start adding exam dates

This commit is contained in:
Ross
2024-05-18 08:39:45 +01:00
parent f37b3312e5
commit 4367b88057
14 changed files with 322 additions and 32 deletions
@@ -0,0 +1,28 @@
# Generated by Django 5.0.2 on 2024-05-13 10:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('rapids', '0008_alter_exam_authors_only'),
]
operations = [
migrations.AddField(
model_name='exam',
name='end_date',
field=models.DateTimeField(help_text='Date (and time) the exam/collection ends', null=True),
),
migrations.AddField(
model_name='exam',
name='restrict_to_dates',
field=models.BooleanField(default=False, help_text='If the exam/collection should only be taken between the start and end date times'),
),
migrations.AddField(
model_name='exam',
name='start_date',
field=models.DateTimeField(help_text='Date (and time) the exam/collection starts', null=True),
),
]
+55
View File
@@ -1,7 +1,12 @@
import json
import os
from re import A
import time
from django.conf import settings
from django.core.exceptions import ValidationError
from django.http import Http404
from django.utils import timezone
import pytest
import tempfile
@@ -508,3 +513,53 @@ def test_exams(db, client):
generated_questions.pop(-1).delete()
users_tested = users_tested + 1
def test_exams_with_dates(db, client):
create_cid_user_and_groups(db)
exam = create_exam(db)
active_exams = client.get(reverse(f"{APP_NAME}:active_exams"))
assert active_exams.status_code == 200
assert len(json.loads(active_exams.content)["exams"]) == 0
cid_user_1000 = CidUser.objects.get(cid=1000)
user1 = User.objects.get(username="user1")
exam.check_user_can_take(None, None, user1)
exam.check_user_can_take(cid_user_1000.cid, cid_user_1000.passcode)
exam.active = False
exam.save()
with pytest.raises(Http404):
exam.check_user_can_take(None, None, user1)
with pytest.raises(Http404):
exam.check_user_can_take(cid_user_1000.cid, cid_user_1000.passcode)
with pytest.raises(ValidationError):
exam.restrict_to_dates = True
exam.save()
with pytest.raises(ValidationError):
exam.restrict_to_dates = True
exam.end_date = timezone.now()
exam.start_date = timezone.now() + timezone.timedelta(days=1)
exam.save()
exam.start_date = timezone.now()
exam.end_date = None # The previously set value seems to remain...
exam.restrict_to_dates = True
exam.save()
exam.check_user_can_take(None, None, user1)
exam.check_user_can_take(cid_user_1000.cid, cid_user_1000.passcode)
exam.end_date = timezone.now()
exam.save()
with pytest.raises(Http404):
exam.check_user_can_take(None, None, user1)
with pytest.raises(Http404):
exam.check_user_can_take(cid_user_1000.cid, cid_user_1000.passcode)