forked from laike9m/Python-Type-Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
25 lines (16 loc) · 893 Bytes
/
test_api.py
File metadata and controls
25 lines (16 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pathlib import Path
from flask.testing import FlaskClient
def test_get_challenge(test_client: FlaskClient, question_file: Path):
level, challenge_name = question_file.parent.name.split("-", maxsplit=1)
response = test_client.get(f"/{level}/{challenge_name}")
# Verify the returned HTML contains a challenge's source code
assert "TODO" in response.text
def test_run_challenge(test_client: FlaskClient, question_file: Path):
level, challenge_name = question_file.parent.name.split("-", maxsplit=1)
response = test_client.post(f"run/{level}/{challenge_name}", data="")
# Verify backend can run type check and return results
assert response.json is not None
def test_invalid_challenge_redirect_to_homepage(test_client: FlaskClient):
response = test_client.get("/foo/bar")
assert response.status_code == 302
assert response.location == "/"