mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
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:
@@ -2,12 +2,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from CTFd.models import Hints
|
||||
from tests.helpers import (create_ctfd,
|
||||
destroy_ctfd,
|
||||
register_user,
|
||||
login_as_user,
|
||||
gen_challenge,
|
||||
gen_hint)
|
||||
from tests.helpers import (
|
||||
create_ctfd,
|
||||
destroy_ctfd,
|
||||
register_user,
|
||||
login_as_user,
|
||||
gen_challenge,
|
||||
gen_hint,
|
||||
)
|
||||
|
||||
|
||||
def test_api_hint_get_non_admin():
|
||||
@@ -17,13 +19,13 @@ def test_api_hint_get_non_admin():
|
||||
with login_as_user(app) as client:
|
||||
# test_api_hint_get_non_admin
|
||||
"""Can the users get /api/v1/hints if not admin"""
|
||||
r = client.get('/api/v1/hints', json="")
|
||||
r = client.get("/api/v1/hints", json="")
|
||||
assert r.status_code == 403
|
||||
assert Hints.query.count() == 0
|
||||
|
||||
# test_api_hint_post_non_admin
|
||||
"""Can the users post /api/v1/hints if not admin"""
|
||||
r = client.post('/api/v1/hints', json="")
|
||||
r = client.post("/api/v1/hints", json="")
|
||||
assert r.status_code == 403
|
||||
destroy_ctfd(app)
|
||||
|
||||
@@ -33,7 +35,7 @@ def test_api_hint_get_admin():
|
||||
app = create_ctfd()
|
||||
with app.app_context():
|
||||
with login_as_user(app, name="admin") as client:
|
||||
r = client.get('/api/v1/hints', json="")
|
||||
r = client.get("/api/v1/hints", json="")
|
||||
assert r.status_code == 200
|
||||
destroy_ctfd(app)
|
||||
|
||||
@@ -44,10 +46,9 @@ def test_api_hint_post_admin():
|
||||
with app.app_context():
|
||||
gen_challenge(app.db)
|
||||
with login_as_user(app, name="admin") as client:
|
||||
r = client.post('/api/v1/hints', json={
|
||||
"content": "hint",
|
||||
"cost": "1",
|
||||
"challenge": 1})
|
||||
r = client.post(
|
||||
"/api/v1/hints", json={"content": "hint", "cost": "1", "challenge": 1}
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert Hints.query.count() == 1
|
||||
destroy_ctfd(app)
|
||||
@@ -60,15 +61,15 @@ def test_admins_can_preview_hints():
|
||||
gen_challenge(app.db)
|
||||
gen_hint(app.db, challenge_id=1, cost=100)
|
||||
client = login_as_user(app, name="admin", password="password")
|
||||
r = client.get('/api/v1/hints/1')
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.status_code == 200
|
||||
hint = r.get_json()
|
||||
assert hint.get('content') is None
|
||||
assert hint.get("content") is None
|
||||
|
||||
r = client.get('/api/v1/hints/1?preview=true')
|
||||
r = client.get("/api/v1/hints/1?preview=true")
|
||||
assert r.status_code == 200
|
||||
hint = r.get_json()
|
||||
assert hint['data']['content'] == "This is a hint"
|
||||
assert hint["data"]["content"] == "This is a hint"
|
||||
destroy_ctfd(app)
|
||||
|
||||
|
||||
@@ -80,13 +81,13 @@ def test_users_cannot_preview_hints():
|
||||
gen_hint(app.db, challenge_id=1, cost=100)
|
||||
register_user(app)
|
||||
client = login_as_user(app)
|
||||
r = client.get('/api/v1/hints/1')
|
||||
r = client.get("/api/v1/hints/1")
|
||||
assert r.status_code == 200
|
||||
hint = r.get_json()
|
||||
assert hint.get('content') is None
|
||||
assert hint.get("content") is None
|
||||
|
||||
r = client.get('/api/v1/hints/1?preview=true')
|
||||
r = client.get("/api/v1/hints/1?preview=true")
|
||||
assert r.status_code == 200
|
||||
hint = r.get_json()
|
||||
assert hint['data'].get('content') is None
|
||||
assert hint["data"].get("content") is None
|
||||
destroy_ctfd(app)
|
||||
|
||||
Reference in New Issue
Block a user