mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-02-06 10:52:59 +00:00
Test calendar
This commit is contained in:
parent
52763cb75a
commit
f422212aea
@ -1,12 +1,16 @@
|
|||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
|
from django.db.models import F
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
from django.utils import timezone
|
||||||
from registration.models import CoachRegistration, StudentRegistration
|
from registration.models import CoachRegistration, StudentRegistration
|
||||||
|
|
||||||
from .models import Participation, Question, Team
|
from .models import Participation, Phase, Question, Team
|
||||||
|
|
||||||
|
|
||||||
class TestStudentParticipation(TestCase):
|
class TestStudentParticipation(TestCase):
|
||||||
@ -489,6 +493,91 @@ class TestStudentParticipation(TestCase):
|
|||||||
response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
|
response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
def test_current_phase(self):
|
||||||
|
"""
|
||||||
|
Ensure that the current phase is the good one.
|
||||||
|
"""
|
||||||
|
# We are before the beginning
|
||||||
|
for i in range(1, 5):
|
||||||
|
Phase.objects.filter(phase_number=i).update(start=timezone.now() + timedelta(days=2 * i),
|
||||||
|
end=timezone.now() + timedelta(days=2 * i + 1))
|
||||||
|
self.assertEqual(Phase.current_phase().phase_number, 1)
|
||||||
|
|
||||||
|
# We are after the end
|
||||||
|
for i in range(1, 5):
|
||||||
|
Phase.objects.filter(phase_number=i).update(start=timezone.now() - timedelta(days=2 * i),
|
||||||
|
end=timezone.now() - timedelta(days=2 * i + 1))
|
||||||
|
self.assertEqual(Phase.current_phase().phase_number, Phase.objects.count())
|
||||||
|
|
||||||
|
# First phase
|
||||||
|
for i in range(1, 5):
|
||||||
|
Phase.objects.filter(phase_number=i).update(start=timezone.now() + timedelta(days=i - 1),
|
||||||
|
end=timezone.now() + timedelta(days=i))
|
||||||
|
self.assertEqual(Phase.current_phase().phase_number, 1)
|
||||||
|
|
||||||
|
# Second phase
|
||||||
|
for i in range(1, 5):
|
||||||
|
Phase.objects.filter(phase_number=i).update(start=timezone.now() + timedelta(days=i - 2),
|
||||||
|
end=timezone.now() + timedelta(days=i - 1))
|
||||||
|
self.assertEqual(Phase.current_phase().phase_number, 2)
|
||||||
|
|
||||||
|
# Third phase
|
||||||
|
for i in range(1, 5):
|
||||||
|
Phase.objects.filter(phase_number=i).update(start=timezone.now() + timedelta(days=i - 3),
|
||||||
|
end=timezone.now() + timedelta(days=i - 2))
|
||||||
|
self.assertEqual(Phase.current_phase().phase_number, 3)
|
||||||
|
|
||||||
|
# Fourth phase
|
||||||
|
for i in range(1, 5):
|
||||||
|
Phase.objects.filter(phase_number=i).update(start=timezone.now() + timedelta(days=i - 4),
|
||||||
|
end=timezone.now() + timedelta(days=i - 3))
|
||||||
|
self.assertEqual(Phase.current_phase().phase_number, 4)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("participation:calendar"))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("participation:update_phase", args=(4,)))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("participation:update_phase", args=(4,)), data=dict(
|
||||||
|
start=timezone.now(),
|
||||||
|
end=timezone.now() + timedelta(days=3),
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
self.client.force_login(self.superuser)
|
||||||
|
response = self.client.get(reverse("participation:update_phase", args=(4,)))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
response = self.client.post(reverse("participation:update_phase", args=(4,)), data=dict(
|
||||||
|
start=timezone.now(),
|
||||||
|
end=timezone.now() + timedelta(days=3),
|
||||||
|
))
|
||||||
|
self.assertRedirects(response, reverse("participation:calendar"), 302, 200)
|
||||||
|
fourth_phase = Phase.objects.get(phase_number=4)
|
||||||
|
self.assertEqual((fourth_phase.end - fourth_phase.start).days, 3)
|
||||||
|
|
||||||
|
# First phase must be before the other phases
|
||||||
|
response = self.client.post(reverse("participation:update_phase", args=(1,)), data=dict(
|
||||||
|
start=timezone.now() + timedelta(days=8),
|
||||||
|
end=timezone.now() + timedelta(days=9),
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# Fourth phase must be after the other phases
|
||||||
|
response = self.client.post(reverse("participation:update_phase", args=(4,)), data=dict(
|
||||||
|
start=timezone.now() - timedelta(days=9),
|
||||||
|
end=timezone.now() - timedelta(days=8),
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
# End must be after start
|
||||||
|
response = self.client.post(reverse("participation:update_phase", args=(4,)), data=dict(
|
||||||
|
start=timezone.now() + timedelta(days=3),
|
||||||
|
end=timezone.now(),
|
||||||
|
))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_forbidden_access(self):
|
def test_forbidden_access(self):
|
||||||
"""
|
"""
|
||||||
Load personnal pages and ensure that these are protected.
|
Load personnal pages and ensure that these are protected.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user