mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-04-28 17:32:38 +00:00
Compare commits
3 Commits
aed9f457c3
...
e73bb2d18b
Author | SHA1 | Date | |
---|---|---|---|
|
e73bb2d18b | ||
|
f422212aea | ||
|
52763cb75a |
@ -171,10 +171,12 @@ class PhaseForm(forms.ModelForm):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
# Ensure that dates are in a right order
|
# Ensure that dates are in a right order
|
||||||
cleaned_data = super().clean()
|
cleaned_data = super().clean()
|
||||||
if cleaned_data["end"] <= cleaned_data["start"]:
|
start = cleaned_data["start"]
|
||||||
|
end = cleaned_data["end"]
|
||||||
|
if end <= start:
|
||||||
self.add_error("end", _("Start date must be before the end date."))
|
self.add_error("end", _("Start date must be before the end date."))
|
||||||
if Phase.objects.filter(phase_number__lt=self.instance.phase_number, end__gt=cleaned_data["start"]).exists():
|
if Phase.objects.filter(phase_number__lt=self.instance.phase_number, end__gt=start).exists():
|
||||||
self.add_error("start", _("This phase must start after the previous phases."))
|
self.add_error("start", _("This phase must start after the previous phases."))
|
||||||
if Phase.objects.filter(phase_number__gt=self.instance.phase_number, start__lt=cleaned_data["end"]).exists():
|
if Phase.objects.filter(phase_number__gt=self.instance.phase_number, start__lt=end).exists():
|
||||||
self.add_error("end", _("This phase must end after the next phases."))
|
self.add_error("end", _("This phase must end after the next phases."))
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
@ -72,19 +72,17 @@ class ParticipationTable(tables.Table):
|
|||||||
|
|
||||||
|
|
||||||
class VideoTable(tables.Table):
|
class VideoTable(tables.Table):
|
||||||
participationname = tables.LinkColumn(
|
participation_name = tables.LinkColumn(
|
||||||
'participation:participation_detail',
|
'participation:participation_detail',
|
||||||
args=[tables.A("participation__pk")],
|
args=[tables.A("participation__pk")],
|
||||||
verbose_name=lambda: _("name").capitalize(),
|
verbose_name=lambda: _("name").capitalize(),
|
||||||
|
accessor=tables.A("participation__team__name"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def render_participationname(self, record):
|
|
||||||
return record.participation.team.name
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
attrs = {
|
attrs = {
|
||||||
'class': 'table table condensed table-striped',
|
'class': 'table table condensed table-striped',
|
||||||
}
|
}
|
||||||
model = Team
|
model = Team
|
||||||
fields = ('participationname', 'link',)
|
fields = ('participation_name', 'link',)
|
||||||
template_name = 'django_tables2/bootstrap4.html'
|
template_name = 'django_tables2/bootstrap4.html'
|
||||||
|
@ -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 registration.models import StudentRegistration
|
from django.utils import timezone
|
||||||
|
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):
|
||||||
@ -60,6 +64,14 @@ class TestStudentParticipation(TestCase):
|
|||||||
grant_animath_access_videos=True,
|
grant_animath_access_videos=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.coach = User.objects.create(
|
||||||
|
first_name="Coach",
|
||||||
|
last_name="Coach",
|
||||||
|
email="coach@example.com",
|
||||||
|
password="coach",
|
||||||
|
)
|
||||||
|
CoachRegistration.objects.create(user=self.coach)
|
||||||
|
|
||||||
def test_admin_pages(self):
|
def test_admin_pages(self):
|
||||||
"""
|
"""
|
||||||
Load Django-admin pages.
|
Load Django-admin pages.
|
||||||
@ -356,6 +368,9 @@ class TestStudentParticipation(TestCase):
|
|||||||
self.user.registration.team = self.team
|
self.user.registration.team = self.team
|
||||||
self.user.registration.save()
|
self.user.registration.save()
|
||||||
|
|
||||||
|
self.coach.registration.team = self.team
|
||||||
|
self.coach.registration.save()
|
||||||
|
|
||||||
response = self.client.get(reverse("participation:update_team", args=(self.team.pk,)))
|
response = self.client.get(reverse("participation:update_team", args=(self.team.pk,)))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
@ -478,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