start longs testing
This commit is contained in:
@@ -15,7 +15,15 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
from longs.views import GenericExamViews as LongExamViews
|
from longs.views import GenericExamViews as LongExamViews
|
||||||
|
|
||||||
from longs.models import AnswerMarks, CidUserAnswer, Exam, Examination, Long as Question, LongSeries, LongSeriesImage
|
from longs.models import (
|
||||||
|
AnswerMarks,
|
||||||
|
CidUserAnswer,
|
||||||
|
Exam,
|
||||||
|
Examination,
|
||||||
|
Long as Question,
|
||||||
|
LongSeries,
|
||||||
|
LongSeriesImage,
|
||||||
|
)
|
||||||
|
|
||||||
from generic.models import CidUser, CidUserGroup, UserUserGroup
|
from generic.models import CidUser, CidUserGroup, UserUserGroup
|
||||||
|
|
||||||
@@ -39,7 +47,7 @@ def create_exam(db):
|
|||||||
exam.valid_cid_users.add(*group1.ciduser_set.all())
|
exam.valid_cid_users.add(*group1.ciduser_set.all())
|
||||||
exam.valid_user_users.add(*usergroup1.users.all())
|
exam.valid_user_users.add(*usergroup1.users.all())
|
||||||
|
|
||||||
assert exam in group1.long_cid_user_groups.all()
|
assert exam in group1.longs_cid_user_groups.all()
|
||||||
|
|
||||||
assert exam
|
assert exam
|
||||||
|
|
||||||
@@ -53,44 +61,50 @@ def create_examination(db):
|
|||||||
examination.save()
|
examination.save()
|
||||||
|
|
||||||
|
|
||||||
def create_long_image(question):
|
def create_long_series(question, image_number=5):
|
||||||
|
series = LongSeries(
|
||||||
|
description="Test series",
|
||||||
|
examination=Examination.objects.get(pk=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
series.save()
|
||||||
|
|
||||||
|
for n in range(image_number):
|
||||||
|
create_long_series_image(series)
|
||||||
|
|
||||||
|
return series
|
||||||
|
|
||||||
|
|
||||||
|
def create_long_series_image(series):
|
||||||
image = tempfile.NamedTemporaryFile(
|
image = tempfile.NamedTemporaryFile(
|
||||||
dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False
|
dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False
|
||||||
)
|
)
|
||||||
|
|
||||||
long_image = LongImage(image=image, long=question)
|
long_series_image = LongSeriesImage.objects.create(image=image.name, series=series)
|
||||||
|
|
||||||
long_image.save()
|
# long_series_image.save()
|
||||||
|
|
||||||
|
|
||||||
def create_question(exam, answer=None, normal=False):
|
def create_question(exam, answer=None, normal=False):
|
||||||
# Just assign random stuff
|
# Just assign random stuff
|
||||||
|
|
||||||
question: Question = Question.objects.create(
|
question: Question = Question.objects.create(
|
||||||
laterality=Question.NONE,
|
description="Test question",
|
||||||
# examination=Examination.objects.get(pk=1),
|
history="Test history",
|
||||||
# image=imagohe.name,
|
feedback="Test feedback",
|
||||||
history="TEST history",
|
model_observations="Model obs",
|
||||||
normal=normal,
|
model_interpretation="Model interp",
|
||||||
|
model_principle_diagnosis="Model pd",
|
||||||
|
model_differential_diagnosis="Model dd",
|
||||||
|
model_management="Model management",
|
||||||
)
|
)
|
||||||
|
|
||||||
create_long_image(question=question)
|
series = create_long_series(question=question)
|
||||||
|
|
||||||
|
question.series.add(series)
|
||||||
|
|
||||||
question.exams.set([exam])
|
question.exams.set([exam])
|
||||||
|
|
||||||
# Create an answer for the question
|
|
||||||
if answer is None:
|
|
||||||
answer_text = "testanswer"
|
|
||||||
else:
|
|
||||||
answer_text = answer
|
|
||||||
answer = Answer(
|
|
||||||
question=question,
|
|
||||||
answer=answer_text,
|
|
||||||
answer_compare=answer_text,
|
|
||||||
status=Answer.MarkOptions.CORRECT,
|
|
||||||
)
|
|
||||||
answer.save()
|
|
||||||
|
|
||||||
return question
|
return question
|
||||||
|
|
||||||
|
|
||||||
@@ -184,14 +198,48 @@ def test_exams(db, client):
|
|||||||
assert exam_metadata["name"] == "Cid Exam"
|
assert exam_metadata["name"] == "Cid Exam"
|
||||||
assert exam_metadata["exam_active"] == True
|
assert exam_metadata["exam_active"] == True
|
||||||
assert exam_metadata["exam_mode"] == True
|
assert exam_metadata["exam_mode"] == True
|
||||||
|
print(f"{exam_metadata=}")
|
||||||
|
|
||||||
res = client.get(exam_metadata["url"])
|
res = client.get(exam_metadata["url"])
|
||||||
assert res.status_code == 200
|
assert res.status_code == 200
|
||||||
exam_json = json.loads(res.content)
|
exam_json = json.loads(res.content)
|
||||||
print(exam_json)
|
print(exam_json)
|
||||||
|
|
||||||
|
for q in exam_json["question_requests"]:
|
||||||
|
print("check question:", q)
|
||||||
|
# check redirects to the json file work
|
||||||
|
# TODO: sort out testing of the saved JSON files
|
||||||
|
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
|
||||||
|
)
|
||||||
|
#assert question_json_res.status_code == 200
|
||||||
|
print(question_json_res.redirect_chain)
|
||||||
|
print(question_json_res.content)
|
||||||
|
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
|
||||||
|
)
|
||||||
|
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)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
question1.get_question_json(answers=False)
|
question_json
|
||||||
in exam_json["questions"].values()
|
in exam_json["questions"].values()
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -249,7 +297,6 @@ def test_exams(db, client):
|
|||||||
assert json_res["success"] == False
|
assert json_res["success"] == False
|
||||||
assert json_res["error"] == "Invalid data"
|
assert json_res["error"] == "Invalid data"
|
||||||
|
|
||||||
|
|
||||||
# Long answers currently send a seperate object for each component
|
# Long answers currently send a seperate object for each component
|
||||||
valid_answers = []
|
valid_answers = []
|
||||||
valid_answers_extra = []
|
valid_answers_extra = []
|
||||||
|
|||||||
Reference in New Issue
Block a user