forked from datacamp/pythonwhat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_debug.py
More file actions
46 lines (37 loc) · 1.22 KB
/
test_debug.py
File metadata and controls
46 lines (37 loc) · 1.22 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
import requests
import tests.helper as helper
def build_data(course_id, chapter_id, ex_number, printout=False):
url = "https://www.datacamp.com/api/courses/{course_id}/chapters/{chapter_id}/exercises.json".format(
course_id=course_id, chapter_id=chapter_id
)
resp = requests.get(url)
assert resp.status_code == 200
ex = resp.json()[ex_number - 1]
pec = ex.get("pre_exercise_code", "")
sol = ex.get("solution", "")
sct = ex.get("sct", "")
if printout:
print("\n\n\n\n")
print("## PEC ######################\n")
print(pec)
print("## SOL ######################\n")
print(sol)
print("## SCT ######################\n")
print(sct)
print("#############################\n")
print("\n\n\n\n")
return {"DC_PEC": pec, "DC_CODE": sol, "DC_SOLUTION": sol, "DC_SCT": sct}
def test_normal_pass():
code = "x = 123"
data = {
"DC_PEC": "",
"DC_CODE": code,
"DC_SOLUTION": code,
"DC_SCT": "success_msg('great')",
}
output = helper.run(data)
assert output["correct"]
def test_dc_exercise():
data = build_data(735, 1842, 2)
output = helper.run(data)
assert output["correct"]