Refactor exam image creation and enhance supervisor management tests
This commit is contained in:
@@ -4,13 +4,12 @@ from re import A
|
||||
import time
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.http import Http404
|
||||
from django.utils import timezone
|
||||
|
||||
import pytest
|
||||
|
||||
import tempfile
|
||||
|
||||
# from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
|
||||
@@ -59,11 +58,11 @@ def create_examination(db):
|
||||
|
||||
|
||||
def create_rapid_image(question):
|
||||
image = tempfile.NamedTemporaryFile(
|
||||
dir=settings.MEDIA_ROOT, suffix=".jpg", delete=False
|
||||
image = SimpleUploadedFile(
|
||||
"test_rapid_image.jpg",
|
||||
b"test-rapid-image",
|
||||
content_type="image/jpeg",
|
||||
)
|
||||
image.flush()
|
||||
image._committed = True
|
||||
|
||||
rapid_image = RapidImage(image=image, rapid=question)
|
||||
|
||||
@@ -334,14 +333,39 @@ def test_exams(db, client):
|
||||
|
||||
cid_scores_soup = BeautifulSoup(cid_scores_res.content, "html.parser")
|
||||
|
||||
search_exam = (
|
||||
cid_scores_soup.find("div", {"id": "exam-assigned"})
|
||||
.find("ul", {"class": exam.app_name})
|
||||
.find("li", attrs={"data-exam-id": exam.pk})
|
||||
)
|
||||
assert search_exam
|
||||
assert str(exam) in str(search_exam)
|
||||
assert len(search_exam.find("button", {"class": "start-button"})) > 0
|
||||
if testing_cid_user:
|
||||
search_exam = (
|
||||
cid_scores_soup.find("div", {"id": "exam-assigned"})
|
||||
.find("li", attrs={"data-exam-id": exam.pk})
|
||||
)
|
||||
assert search_exam
|
||||
assert str(exam) in str(search_exam)
|
||||
assert search_exam.find("a", string="Start")
|
||||
|
||||
results_exam = (
|
||||
cid_scores_soup.find("div", {"id": "exam-results"})
|
||||
.find_all("li", attrs={"data-exam-id": exam.pk})
|
||||
)
|
||||
assert results_exam
|
||||
assert str(exam) in str(results_exam)
|
||||
assert str(exam) + " test" not in str(results_exam)
|
||||
assert "Results Published" not in str(
|
||||
results_exam
|
||||
) # It should not be published yet
|
||||
else:
|
||||
search_exam = cid_scores_soup.find("a", href=exam.get_take_url())
|
||||
assert search_exam
|
||||
assert search_exam.string == "Start"
|
||||
|
||||
results_exam = cid_scores_soup.find(
|
||||
"a",
|
||||
href=reverse(
|
||||
f"{exam.app_name}:exam_scores_user",
|
||||
kwargs={"pk": exam.pk},
|
||||
),
|
||||
)
|
||||
assert results_exam
|
||||
assert str(exam) in str(results_exam)
|
||||
# assert "Active" in assigned_exams # check it is active
|
||||
|
||||
invalid_exam = cid_scores_soup.find_all(
|
||||
@@ -349,19 +373,6 @@ def test_exams(db, client):
|
||||
)
|
||||
assert not invalid_exam # Check we can't find an invalid exam
|
||||
|
||||
# Check that we have a results link
|
||||
results_exam = (
|
||||
cid_scores_soup.find("div", {"id": "exam-results"})
|
||||
.find("ul", {"class": exam.app_name})
|
||||
.find_all("li", attrs={"data-exam-id": exam.pk})
|
||||
)
|
||||
assert results_exam
|
||||
assert str(exam) in str(results_exam)
|
||||
assert str(exam) + " test" not in str(results_exam)
|
||||
assert "Results Published" not in str(
|
||||
results_exam
|
||||
) # It should not be published yet
|
||||
|
||||
if testing_cid_user:
|
||||
AssertNotFound(
|
||||
client,
|
||||
@@ -530,10 +541,10 @@ def test_exams_with_dates(db, client):
|
||||
exam.active = False
|
||||
exam.save()
|
||||
|
||||
with pytest.raises(Http404):
|
||||
with pytest.raises(Exam.InactiveException):
|
||||
exam.check_user_can_take(None, None, user1)
|
||||
|
||||
with pytest.raises(Http404):
|
||||
with pytest.raises(Exam.InactiveException):
|
||||
exam.check_user_can_take(cid_user_1000.cid, cid_user_1000.passcode)
|
||||
|
||||
with pytest.raises(ValidationError):
|
||||
|
||||
Reference in New Issue
Block a user