Format all the things (#991)

* Format Javascript and CSS files with `prettier`: `prettier --write 'CTFd/themes/**/*'`
* Format Python with `black`: `black CTFd` & `black tests`
* Travis now uses xenial instead of trusty.
This commit is contained in:
Kevin Chung
2019-05-11 21:09:37 -04:00
committed by GitHub
parent 3d23ece370
commit 6833378c36
201 changed files with 9561 additions and 9107 deletions

View File

@@ -6,7 +6,7 @@ from tests.helpers import (
register_user,
login_as_user,
gen_challenge,
gen_flag
gen_flag,
)
@@ -23,15 +23,15 @@ def test_create_new_challenge():
"description": "description",
"value": 100,
"state": "hidden",
"type": "standard"
"type": "standard",
}
r = client.post('/api/v1/challenges', json=challenge_data)
assert r.get_json().get('data')['id'] == 1
r = client.get('/admin/challenges/1')
r = client.post("/api/v1/challenges", json=challenge_data)
assert r.get_json().get("data")["id"] == 1
r = client.get("/admin/challenges/1")
assert r.status_code == 200
r = client.get('/api/v1/challenges/1')
assert r.get_json().get('data')['id'] == 1
r = client.get("/api/v1/challenges/1")
assert r.get_json().get("data")["id"] == 1
destroy_ctfd(app)
@@ -42,60 +42,54 @@ def test_hidden_challenge_is_reachable():
with app.app_context():
register_user(app)
client = login_as_user(app, name="admin", password="password")
chal = gen_challenge(app.db, state='hidden')
gen_flag(app.db, challenge_id=chal.id, content='flag')
chal = gen_challenge(app.db, state="hidden")
gen_flag(app.db, challenge_id=chal.id, content="flag")
chal_id = chal.id
assert Challenges.query.count() == 1
r = client.get('/api/v1/challenges', json='')
data = r.get_json().get('data')
r = client.get("/api/v1/challenges", json="")
data = r.get_json().get("data")
assert data == []
r = client.get('/api/v1/challenges/1', json='')
r = client.get("/api/v1/challenges/1", json="")
assert r.status_code == 200
data = r.get_json().get('data')
assert data['name'] == 'chal_name'
data = r.get_json().get("data")
assert data["name"] == "chal_name"
data = {
"submission": 'flag',
"challenge_id": chal_id
}
data = {"submission": "flag", "challenge_id": chal_id}
r = client.post('/api/v1/challenges/attempt', json=data)
r = client.post("/api/v1/challenges/attempt", json=data)
assert r.status_code == 404
r = client.post('/api/v1/challenges/attempt?preview=true', json=data)
r = client.post("/api/v1/challenges/attempt?preview=true", json=data)
assert r.status_code == 200
resp = r.get_json()['data']
assert resp.get('status') == "correct"
resp = r.get_json()["data"]
assert resp.get("status") == "correct"
destroy_ctfd(app)
def test_challenges_admin_only_as_user():
app = create_ctfd()
with app.app_context():
set_config('challenge_visibility', 'admins')
set_config("challenge_visibility", "admins")
register_user(app)
client = login_as_user(app)
gen_challenge(app.db)
gen_flag(app.db, challenge_id=1, content='flag')
gen_flag(app.db, challenge_id=1, content="flag")
r = client.get('/challenges')
r = client.get("/challenges")
assert r.status_code == 403
r = client.get('/api/v1/challenges', json='')
r = client.get("/api/v1/challenges", json="")
assert r.status_code == 403
r = client.get('/api/v1/challenges/1', json='')
r = client.get("/api/v1/challenges/1", json="")
assert r.status_code == 403
data = {
"submission": 'flag',
"challenge_id": 1
}
r = client.post('/api/v1/challenges/attempt', json=data)
data = {"submission": "flag", "challenge_id": 1}
r = client.post("/api/v1/challenges/attempt", json=data)
assert r.status_code == 403
destroy_ctfd(app)