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

@@ -2,13 +2,15 @@
# -*- coding: utf-8 -*-
from CTFd.plugins.dynamic_challenges import DynamicChallenge, DynamicValueChallenge
from tests.helpers import (create_ctfd,
destroy_ctfd,
register_user,
login_as_user,
gen_flag,
gen_user,
FakeRequest)
from tests.helpers import (
create_ctfd,
destroy_ctfd,
register_user,
login_as_user,
gen_flag,
gen_user,
FakeRequest,
)
def test_can_create_dynamic_challenge():
@@ -26,11 +28,11 @@ def test_can_create_dynamic_challenge():
"decay": 20,
"minimum": 1,
"state": "hidden",
"type": "dynamic"
"type": "dynamic",
}
r = client.post('/api/v1/challenges', json=challenge_data)
assert r.get_json().get('data')['id'] == 1
r = client.post("/api/v1/challenges", json=challenge_data)
assert r.get_json().get("data")["id"] == 1
challenges = DynamicChallenge.query.all()
assert len(challenges) == 1
@@ -55,7 +57,7 @@ def test_can_update_dynamic_challenge():
"decay": 20,
"minimum": 1,
"state": "hidden",
"type": "dynamic"
"type": "dynamic",
}
req = FakeRequest(form=challenge_data)
challenge = DynamicValueChallenge.create(req)
@@ -74,13 +76,13 @@ def test_can_update_dynamic_challenge():
"decay": "40",
"minimum": "5",
"max_attempts": "0",
"state": "visible"
"state": "visible",
}
req = FakeRequest(form=challenge_data)
challenge = DynamicValueChallenge.update(challenge, req)
assert challenge.name == 'new_name'
assert challenge.name == "new_name"
assert challenge.description == "new_description"
assert challenge.value == 200
assert challenge.initial == 200
@@ -103,7 +105,7 @@ def test_can_add_requirement_dynamic_challenge():
"decay": 20,
"minimum": 1,
"state": "hidden",
"type": "dynamic"
"type": "dynamic",
}
req = FakeRequest(form=challenge_data)
challenge = DynamicValueChallenge.create(req)
@@ -122,13 +124,13 @@ def test_can_add_requirement_dynamic_challenge():
"decay": "40",
"minimum": "5",
"max_attempts": "0",
"state": "visible"
"state": "visible",
}
req = FakeRequest(form=challenge_data)
challenge = DynamicValueChallenge.create(req)
assert challenge.name == 'second_name'
assert challenge.name == "second_name"
assert challenge.description == "new_description"
assert challenge.value == 200
assert challenge.initial == 200
@@ -136,9 +138,7 @@ def test_can_add_requirement_dynamic_challenge():
assert challenge.minimum == 5
assert challenge.state == "visible"
challenge_data = {
"requirements": [1]
}
challenge_data = {"requirements": [1]}
req = FakeRequest(form=challenge_data)
challenge = DynamicValueChallenge.update(challenge, req)
@@ -162,11 +162,11 @@ def test_can_delete_dynamic_challenge():
"decay": 20,
"minimum": 1,
"state": "hidden",
"type": "dynamic"
"type": "dynamic",
}
r = client.post('/api/v1/challenges', json=challenge_data)
assert r.get_json().get('data')['id'] == 1
r = client.post("/api/v1/challenges", json=challenge_data)
assert r.get_json().get("data")["id"] == 1
challenges = DynamicChallenge.query.all()
assert len(challenges) == 1
@@ -193,13 +193,13 @@ def test_dynamic_challenge_loses_value_properly():
"decay": 20,
"minimum": 1,
"state": "visible",
"type": "dynamic"
"type": "dynamic",
}
r = client.post('/api/v1/challenges', json=challenge_data)
assert r.get_json().get('data')['id'] == 1
r = client.post("/api/v1/challenges", json=challenge_data)
assert r.get_json().get("data")["id"] == 1
gen_flag(app.db, challenge_id=1, content='flag')
gen_flag(app.db, challenge_id=1, content="flag")
for i, team_id in enumerate(range(2, 26)):
name = "user{}".format(team_id)
@@ -210,20 +210,17 @@ def test_dynamic_challenge_loses_value_properly():
with app.test_client() as client:
# We need to bypass rate-limiting so creating a fake user instead of logging in
with client.session_transaction() as sess:
sess['id'] = team_id
sess['name'] = name
sess['type'] = 'user'
sess['email'] = email
sess['nonce'] = 'fake-nonce'
sess["id"] = team_id
sess["name"] = name
sess["type"] = "user"
sess["email"] = email
sess["nonce"] = "fake-nonce"
data = {
"submission": 'flag',
"challenge_id": 1
}
data = {"submission": "flag", "challenge_id": 1}
r = client.post('/api/v1/challenges/attempt', json=data)
resp = r.get_json()['data']
assert resp['status'] == 'correct'
r = client.post("/api/v1/challenges/attempt", json=data)
resp = r.get_json()["data"]
assert resp["status"] == "correct"
chal = DynamicChallenge.query.filter_by(id=1).first()
if i >= 20:
@@ -248,23 +245,20 @@ def test_dynamic_challenge_value_isnt_affected_by_hidden_users():
"decay": 20,
"minimum": 1,
"state": "visible",
"type": "dynamic"
"type": "dynamic",
}
r = client.post('/api/v1/challenges', json=challenge_data)
assert r.get_json().get('data')['id'] == 1
r = client.post("/api/v1/challenges", json=challenge_data)
assert r.get_json().get("data")["id"] == 1
gen_flag(app.db, challenge_id=1, content='flag')
gen_flag(app.db, challenge_id=1, content="flag")
# Make a solve as a regular user. This should not affect the value.
data = {
"submission": 'flag',
"challenge_id": 1
}
data = {"submission": "flag", "challenge_id": 1}
r = client.post('/api/v1/challenges/attempt', json=data)
resp = r.get_json()['data']
assert resp['status'] == 'correct'
r = client.post("/api/v1/challenges/attempt", json=data)
resp = r.get_json()["data"]
assert resp["status"] == "correct"
# Make solves as hidden users. Also should not affect value
for i, team_id in enumerate(range(2, 26)):
@@ -278,20 +272,17 @@ def test_dynamic_challenge_value_isnt_affected_by_hidden_users():
with app.test_client() as client:
# We need to bypass rate-limiting so creating a fake user instead of logging in
with client.session_transaction() as sess:
sess['id'] = team_id
sess['name'] = name
sess['type'] = 'user'
sess['email'] = email
sess['nonce'] = 'fake-nonce'
sess["id"] = team_id
sess["name"] = name
sess["type"] = "user"
sess["email"] = email
sess["nonce"] = "fake-nonce"
data = {
"submission": 'flag',
"challenge_id": 1
}
data = {"submission": "flag", "challenge_id": 1}
r = client.post('/api/v1/challenges/attempt', json=data)
resp = r.get_json()['data']
assert resp['status'] == 'correct'
r = client.post("/api/v1/challenges/attempt", json=data)
resp = r.get_json()["data"]
assert resp["status"] == "correct"
chal = DynamicChallenge.query.filter_by(id=1).first()
assert chal.value == chal.initial