more Long improvements
This commit is contained in:
@@ -203,7 +203,21 @@ def test_exams(db, client):
|
||||
res = client.get(exam_metadata["url"])
|
||||
assert res.status_code == 200
|
||||
exam_json = json.loads(res.content)
|
||||
print(exam_json)
|
||||
|
||||
# We can also check the unbased questions
|
||||
res = client.get(exam_metadata["url"] + "/unbased")
|
||||
assert res.status_code == 200
|
||||
|
||||
exam_json_unbased = json.loads(res.content)
|
||||
|
||||
# This show we have different types (int vs string)
|
||||
assert (
|
||||
set([str(i) for i in exam_json["exam_order"]])
|
||||
== set(exam_json["questions"].keys())
|
||||
== set(exam_json["question_requests"].keys())
|
||||
== set([str(i) for i in exam_json_unbased["exam_order"]])
|
||||
== set(exam_json_unbased["questions"].keys())
|
||||
)
|
||||
|
||||
for q in exam_json["question_requests"]:
|
||||
print("check question:", q)
|
||||
@@ -212,37 +226,48 @@ def test_exams(db, client):
|
||||
question_json_res = client.get(
|
||||
reverse(
|
||||
f"longs:exam_question_json_cid",
|
||||
kwargs={"pk": exam.pk, "sk": q, "cid": cid_user.cid, "passcode": cid_user.passcode},
|
||||
), follow=True
|
||||
kwargs={
|
||||
"pk": exam.pk,
|
||||
"sk": q,
|
||||
"cid": cid_user.cid,
|
||||
"passcode": cid_user.passcode,
|
||||
},
|
||||
),
|
||||
follow=True,
|
||||
)
|
||||
#assert question_json_res.status_code == 200
|
||||
print(question_json_res.redirect_chain)
|
||||
print(question_json_res.content)
|
||||
# assert question_json_res.status_code == 200
|
||||
assert len(question_json_res.redirect_chain) == 2
|
||||
assert question_json_res.redirect_chain[0][1] == 302
|
||||
assert question_json_res.redirect_chain[1][1] == 302
|
||||
|
||||
assert question_json_res.redirect_chain[1][0].endswith(f"{q}.json")
|
||||
|
||||
|
||||
question_json_unbased_res = client.get(
|
||||
reverse(
|
||||
f"longs:exam_question_json_unbased_cid",
|
||||
kwargs={"pk": exam.pk, "sk": q, "cid": cid_user.cid, "passcode": cid_user.passcode},
|
||||
), follow=True
|
||||
kwargs={
|
||||
"pk": exam.pk,
|
||||
"sk": q,
|
||||
"cid": cid_user.cid,
|
||||
"passcode": cid_user.passcode,
|
||||
},
|
||||
),
|
||||
follow=True,
|
||||
)
|
||||
assert question_json_unbased_res.status_code == 200
|
||||
question_json = json.loads(question_json_unbased_res.content)
|
||||
|
||||
#question_json_res = client.get(question1.get_question_json(answers=False, based=True))
|
||||
|
||||
#print(question_json)
|
||||
# question_json_res = client.get(question1.get_question_json(answers=False, based=True))
|
||||
|
||||
assert (
|
||||
question_json
|
||||
in exam_json["questions"].values()
|
||||
# As we store references to the questions we have to check individually
|
||||
assert q in exam_json["questions"].keys()
|
||||
|
||||
q_json = Question.objects.get(pk=q).get_question_json(
|
||||
based=False
|
||||
)
|
||||
|
||||
assert question_json == q_json
|
||||
|
||||
assert len(exam_json["questions"]) == 3
|
||||
|
||||
exam.active = False
|
||||
@@ -303,26 +328,26 @@ def test_exams(db, client):
|
||||
|
||||
for questions in exam_json["questions"]:
|
||||
for qid in questions:
|
||||
post_data = {
|
||||
"eid": exam_json["eid"],
|
||||
"cid": post_cid,
|
||||
"qid": qid,
|
||||
"qidn": "1",
|
||||
"ans": f"Abnormal",
|
||||
}
|
||||
post_data2 = {
|
||||
"eid": exam_json["eid"],
|
||||
"cid": post_cid,
|
||||
"qid": qid,
|
||||
"qidn": "2",
|
||||
"ans": f"answer {qid}",
|
||||
}
|
||||
if testing_cid_user:
|
||||
post_data["passcode"] = cid_user.passcode
|
||||
post_data2["passcode"] = cid_user.passcode
|
||||
# Long answers submit 5 sections
|
||||
sections = (
|
||||
("1", "answer observations"),
|
||||
("2", "answer interpretation"),
|
||||
("3", "answer principle diagnosis"),
|
||||
("4", "answer differential diagnosis"),
|
||||
("5", "answer management"),
|
||||
)
|
||||
for n, name in sections:
|
||||
post_data = {
|
||||
"eid": exam_json["eid"],
|
||||
"cid": post_cid,
|
||||
"qid": qid,
|
||||
"qidn": n,
|
||||
"ans": f"{name} - {q}",
|
||||
}
|
||||
if testing_cid_user:
|
||||
post_data["passcode"] = cid_user.passcode
|
||||
|
||||
valid_answers_extra.append(post_data)
|
||||
valid_answers.append(post_data2)
|
||||
valid_answers_extra.append(post_data)
|
||||
|
||||
post_json = {
|
||||
"eid": exam_json["eid"],
|
||||
@@ -337,8 +362,8 @@ def test_exams(db, client):
|
||||
|
||||
json_res = json.loads(res.content)
|
||||
|
||||
assert json_res["success"] == True
|
||||
assert json_res["question_count"] == 6
|
||||
assert json_res["success"] is True
|
||||
assert json_res["question_count"] == 5 * 3
|
||||
|
||||
# Check the answers now exist in the database
|
||||
if testing_cid_user:
|
||||
|
||||
Reference in New Issue
Block a user