This commit is contained in:
Ross
2022-08-04 09:58:29 +01:00
parent be70054cf7
commit a2759908c4
4 changed files with 69 additions and 8 deletions
+52 -5
View File
@@ -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