.
This commit is contained in:
+9
-3
@@ -1,3 +1,4 @@
|
||||
from __future__ import annotations
|
||||
import json
|
||||
from django.contrib.contenttypes.fields import GenericRelation
|
||||
from django.db import models
|
||||
@@ -256,7 +257,7 @@ class AnatomyQuestion(models.Model):
|
||||
]
|
||||
)
|
||||
|
||||
def get_question_json(self, based=True, feedback=False):
|
||||
def get_question_json(self, based=True, feedback=False, answers=True):
|
||||
"""Returns a json representation of the question"""
|
||||
|
||||
# Loop through rapidimage associations
|
||||
@@ -281,7 +282,8 @@ class AnatomyQuestion(models.Model):
|
||||
"question": str(self.question_type),
|
||||
}
|
||||
|
||||
json["answers"] = list(self.get_correct_unstripped_answers())
|
||||
if answers:
|
||||
json["answers"] = list(self.get_correct_unstripped_answers())
|
||||
|
||||
return json
|
||||
|
||||
@@ -420,11 +422,15 @@ class Exam(ExamBase):
|
||||
else:
|
||||
image = q.image.url
|
||||
|
||||
annotations = []
|
||||
if str(q.image_annotations):
|
||||
annotations = [str(q.image_annotations)]
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"title": q.get_title(),
|
||||
"question": str(q.question_type),
|
||||
"images": [image],
|
||||
"annotations": [str(q.image_annotations)],
|
||||
"annotations": annotations,
|
||||
"type": "anatomy",
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import json
|
||||
import os
|
||||
from re import A
|
||||
from django.conf import settings
|
||||
import pytest
|
||||
|
||||
import tempfile
|
||||
|
||||
# from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
|
||||
@@ -11,7 +15,7 @@ from bs4 import BeautifulSoup
|
||||
|
||||
from anatomy.views import GenericExamViews as AnatomyExamViews
|
||||
|
||||
from anatomy.models import Exam
|
||||
from anatomy.models import Exam, AnatomyQuestion as Question, QuestionType, Structure
|
||||
|
||||
from generic.models import CidUser, CidUserGroup
|
||||
|
||||
@@ -44,9 +48,45 @@ def create_exam(db):
|
||||
|
||||
assert exam
|
||||
|
||||
return exam
|
||||
|
||||
def create_structures(db):
|
||||
structure = Structure.objects.create(structure="test structure")
|
||||
structure.save()
|
||||
structure = Structure.objects.create(structure="test structure 2")
|
||||
structure.save()
|
||||
|
||||
def create_question_types(db):
|
||||
question_type = QuestionType.objects.create(text="test question type")
|
||||
question_type.save()
|
||||
question_type = QuestionType.objects.create(text="test question type 2")
|
||||
question_type.save()
|
||||
|
||||
|
||||
def create_question(exam):
|
||||
# Just assign random stuff
|
||||
|
||||
image = tempfile.NamedTemporaryFile(dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False)
|
||||
|
||||
print(image.name)
|
||||
print(image.file)
|
||||
|
||||
print(os.listdir(settings.MEDIA_ROOT))
|
||||
|
||||
question: Question = Question.objects.create(question_type=QuestionType.objects.first(), structure=Structure.objects.first(), image=image.name)
|
||||
question.exams.set([exam])
|
||||
return question
|
||||
|
||||
def test_exams(db, client):
|
||||
create_cid_user_and_groups(db)
|
||||
create_exam(db)
|
||||
exam = create_exam(db)
|
||||
|
||||
create_structures(db)
|
||||
create_question_types(db)
|
||||
|
||||
question1 = create_question(exam)
|
||||
create_question(exam)
|
||||
create_question(exam)
|
||||
|
||||
active_exams = client.get(reverse(f"{APP_NAME}:active_exams"))
|
||||
assert active_exams.status_code == 200
|
||||
@@ -81,8 +121,15 @@ def test_exams(db, client):
|
||||
assert exam_metadata["exam_active"] == True
|
||||
assert exam_metadata["exam_mode"] == True
|
||||
|
||||
#exam_json = client.get(exam_metadata["url"])
|
||||
#print(exam_json.status_code)
|
||||
#print(exam_json.content)
|
||||
res = client.get(exam_metadata["url"])
|
||||
assert res.status_code == 200
|
||||
exam_json = json.loads(res.content)
|
||||
print("---", exam_json["questions"].values())
|
||||
|
||||
|
||||
assert question1.get_question_json(answers=False) in exam_json["questions"].values()
|
||||
|
||||
|
||||
assert len(exam_json["questions"]) == 3
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user