forked from johnny603/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_smoke.py
More file actions
63 lines (41 loc) · 1.66 KB
/
Copy pathtest_smoke.py
File metadata and controls
63 lines (41 loc) · 1.66 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import server
def test_import_server():
assert server.app is not None
def test_health_endpoint():
client = server.app.test_client()
response = client.get("/health")
assert response.status_code == 200
response = client.get("/ready")
assert response.status_code == 200
def test_levels_endpoint():
client = server.app.test_client()
response = client.get("/levels")
assert response.status_code == 200
data = response.get_json()
assert isinstance(data, list)
assert len(data) > 0
def test_level_detail_and_submission_endpoints(monkeypatch):
client = server.app.test_client()
response = client.get("/level/1")
assert response.status_code == 200
payload = response.get_json()
assert payload["id"] == "1"
assert payload["difficulty"] == "easy"
response = client.post("/submit", json={"level_id": "1", "attempt": "-a"})
assert response.status_code == 200
assert response.get_json()["correct"] is True
response = client.post("/api/v1/submit", json={"level_id": "1", "attempt": "-a"})
assert response.status_code == 200
assert response.get_json()["correct"] is True
monkeypatch.setattr(
server, "run_docker", lambda files, script: {"passed": True, "exit_code": 0}
)
response = client.post(
"/submit", json={"level_id": "5", "files": {"answer.c": "int main(void){return 0;}"}}
)
assert response.status_code == 200
assert response.get_json()["correct"] is True
def test_invalid_submission_rejected():
client = server.app.test_client()
response = client.post("/submit", json={"level_id": "999", "attempt": "x"})
assert response.status_code == 404