Files
Ross ee9b942893 .
2022-05-21 12:21:52 +01:00

50 lines
1.7 KiB
Python

from django.urls import reverse
import pytest
from rapids.models import Abnormality, Exam
from rapids.views import GenericExamViews
#@pytest.mark.django_db
def test_create_abnormality(db):
abnormality = Abnormality.objects.create(name="Abnorm")
assert abnormality.name == "Abnorm"
@pytest.fixture
def create_basic_user(db, django_user_model):
return django_user_model.objects.create_superuser("basicuser", "ross@xkjq.uk", "password")
@pytest.fixture
def create_exam(db):
return Exam.objects.create(name="test exam", exam_mode=True)
def test_exam_creation(create_exam):
exams = Exam.objects.filter(name="test exam")
assert exams.exists()
exam = exams.first()
assert exam.time_limit == 35 * 60
def test_exam_list(rf, admin_user, create_exam):
request = rf.get('/rapids/exam/')
# Remember that when using RequestFactory, the request does not pass
# through middleware. If your view expects fields such as request.user
# to be set, you need to set them explicitly.
# The following line sets request.user to an admin user.
request.user = admin_user
response = GenericExamViews.exam_list(request)
#print(response)
assert response.status_code == 200
def test_exam_active_admin(rf, admin_user, create_exam, client):
request = rf.get(reverse('rapids:active_exams'))
request.user = admin_user
response = GenericExamViews.active_exams(request)
print(response.content)
assert response.status_code == 200
def test_exam_active_basic_user(create_basic_user, create_exam, client):
client.login(username="basicuser", password="password")
response = client.get(reverse('rapids:active_exams'))
print(response.content)
assert response.status_code == 200