This commit is contained in:
Ross
2022-08-10 22:30:06 +01:00
parent 7032f890f9
commit 4c3b7d2e12
13 changed files with 534 additions and 45 deletions
+56 -5
View File
@@ -73,7 +73,6 @@ def create_question(exam):
dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False
)
question: Question = Question.objects.create(
question_type=QuestionType.objects.first(),
structure=Structure.objects.first(),
@@ -162,14 +161,13 @@ def test_exams(db, client):
"eid": f"anatomy/{exam.pk}",
"cid": cid_user_1001.cid,
"start_time": "1659618141.731",
"answers": [[]]
"answers": [[]],
}
# Test submission
# Start with 0 answers
res = client.post(reverse("global_exam_answers_submit"), data=post_json)
print(res.status_code)
json_res = json.loads(res.content)
assert json_res["success"] == True
@@ -179,10 +177,63 @@ def test_exams(db, client):
"eid": f"anatomy/{exam.pk+10}",
"cid": cid_user_1001.cid,
"start_time": "1659618141.731",
"answers": [[]]
"answers": [[]],
}
res = client.post(reverse("global_exam_answers_submit"), data=post_json)
json_res = json.loads(res.content)
assert json_res["success"] == False
# Test that we ca
# Test invalid cid
post_json = {
"eid": f"anatomy/{exam.pk+10}",
"cid": 1,
"start_time": "1659618141.731",
"answers": [[]],
}
res = client.post(reverse("global_exam_answers_submit"), data=post_json)
json_res = json.loads(res.content)
assert json_res["success"] == False
assert json_res["error"] == "Invalid data"
valid_answers = []
for questions in exam_json["questions"]:
for qid in questions:
valid_answers.append(
{
"eid": exam_json["eid"],
"cid": cid_user_1001.cid,
"passcode": cid_user_1001.passcode,
"qid": qid,
"qidn": "1",
"ans": f"answer {qid}",
}
)
post_json = {
"eid": exam_json["eid"],
"cid": cid_user_1001.cid,
"start_time": "1659618141.731",
"answers": json.dumps(valid_answers),
}
# Test submission
# give three answers
print("post_json", post_json)
res = client.post(reverse("global_exam_answers_submit"), data=post_json)
json_res = json.loads(res.content)
print(json_res)
assert json_res["success"] == True
assert json_res["question_count"] == 3
# We can then check the answers have been submitted (and can be viewed by the user)
cid_scores_res = client.get(
reverse(f"cid_scores", kwargs={"cid": 1001, "passcode": "EFGH"})
)
cid_scores_soup = BeautifulSoup(cid_scores_res.content, "html.parser")
assigned_exams = cid_scores_soup.find(id="exam-assigned").find_all("li")
print(assigned_exams)