mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-04 13:32:17 +02:00
Drop a lot of Corres2math content
This commit is contained in:
@ -1,18 +1,15 @@
|
||||
# Copyright (C) 2020 by Animath
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.management import call_command
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from registration.models import CoachRegistration, StudentRegistration
|
||||
|
||||
from .models import Participation, Phase, Question, Team
|
||||
from .models import Participation, Team
|
||||
|
||||
|
||||
class TestStudentParticipation(TestCase):
|
||||
@ -40,10 +37,7 @@ class TestStudentParticipation(TestCase):
|
||||
name="Super team",
|
||||
trigram="AAA",
|
||||
access_code="azerty",
|
||||
grant_animath_access_videos=True,
|
||||
)
|
||||
self.question = Question.objects.create(participation=self.team.participation,
|
||||
question="Pourquoi l'existence précède l'essence ?")
|
||||
self.client.force_login(self.user)
|
||||
|
||||
self.second_user = User.objects.create(
|
||||
@ -63,7 +57,6 @@ class TestStudentParticipation(TestCase):
|
||||
name="Poor team",
|
||||
trigram="FFF",
|
||||
access_code="qwerty",
|
||||
grant_animath_access_videos=True,
|
||||
)
|
||||
|
||||
self.coach = User.objects.create(
|
||||
@ -108,29 +101,6 @@ class TestStudentParticipation(TestCase):
|
||||
self.assertRedirects(response, "http://" + Site.objects.get().domain +
|
||||
str(self.team.participation.get_absolute_url()), 302, 200)
|
||||
|
||||
# Test video pages
|
||||
response = self.client.get(reverse("admin:index") + "participation/video/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(reverse("admin:index")
|
||||
+ f"participation/video/{self.team.participation.solution.pk}/change/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Test question pages
|
||||
response = self.client.get(reverse("admin:index") + "participation/question/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(reverse("admin:index")
|
||||
+ f"participation/question/{self.question.pk}/change/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Test phase pages
|
||||
response = self.client.get(reverse("admin:index") + "participation/phase/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(reverse("admin:index") + "participation/phase/1/change/")
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_create_team(self):
|
||||
"""
|
||||
Try to create a team.
|
||||
@ -141,14 +111,12 @@ class TestStudentParticipation(TestCase):
|
||||
response = self.client.post(reverse("participation:create_team"), data=dict(
|
||||
name="Test team",
|
||||
trigram="123",
|
||||
grant_animath_access_videos=False,
|
||||
))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.post(reverse("participation:create_team"), data=dict(
|
||||
name="Test team",
|
||||
trigram="TES",
|
||||
grant_animath_access_videos=False,
|
||||
))
|
||||
self.assertTrue(Team.objects.filter(trigram="TES").exists())
|
||||
team = Team.objects.get(trigram="TES")
|
||||
@ -158,7 +126,6 @@ class TestStudentParticipation(TestCase):
|
||||
response = self.client.post(reverse("participation:create_team"), data=dict(
|
||||
name="Test team 2",
|
||||
trigram="TET",
|
||||
grant_animath_access_videos=False,
|
||||
))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
@ -286,13 +253,6 @@ class TestStudentParticipation(TestCase):
|
||||
self.user.registration.photo_authorization = "authorization/photo/ananas"
|
||||
self.user.registration.save()
|
||||
|
||||
resp = self.client.get(reverse("participation:team_detail", args=(self.team.pk,)))
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertFalse(resp.context["can_validate"])
|
||||
|
||||
self.team.participation.problem = 2
|
||||
self.team.participation.save()
|
||||
|
||||
resp = self.client.get(reverse("participation:team_detail", args=(self.team.pk,)))
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertTrue(resp.context["can_validate"])
|
||||
@ -383,23 +343,12 @@ class TestStudentParticipation(TestCase):
|
||||
response = self.client.get(reverse("participation:update_team", args=(self.team.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Form is invalid
|
||||
response = self.client.post(reverse("participation:update_team", args=(self.team.pk,)), data=dict(
|
||||
name="Updated team name",
|
||||
trigram="BBB",
|
||||
grant_animath_access_videos=True,
|
||||
problem=42,
|
||||
))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.post(reverse("participation:update_team", args=(self.team.pk,)), data=dict(
|
||||
name="Updated team name",
|
||||
trigram="BBB",
|
||||
grant_animath_access_videos=True,
|
||||
problem=3,
|
||||
))
|
||||
self.assertRedirects(response, reverse("participation:team_detail", args=(self.team.pk,)), 302, 200)
|
||||
self.assertTrue(Team.objects.filter(trigram="BBB", participation__problem=3).exists())
|
||||
self.assertTrue(Team.objects.filter(trigram="BBB").exists())
|
||||
|
||||
def test_leave_team(self):
|
||||
"""
|
||||
@ -471,199 +420,6 @@ class TestStudentParticipation(TestCase):
|
||||
response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_upload_video(self):
|
||||
"""
|
||||
Try to send a solution video link.
|
||||
"""
|
||||
self.user.registration.team = self.team
|
||||
self.user.registration.save()
|
||||
|
||||
self.team.participation.valid = True
|
||||
self.team.participation.save()
|
||||
|
||||
response = self.client.get(reverse("participation:upload_video", args=(self.team.participation.solution.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.post(reverse("participation:upload_video", args=(self.team.participation.solution.pk,)),
|
||||
data=dict(link="https://youtube.com/watch?v=73nsrixx7eI"))
|
||||
self.assertRedirects(response,
|
||||
reverse("participation:participation_detail", args=(self.team.participation.id,)),
|
||||
302, 200)
|
||||
self.team.participation.refresh_from_db()
|
||||
self.assertEqual(self.team.participation.solution.platform, "youtube")
|
||||
self.assertEqual(self.team.participation.solution.youtube_code, "73nsrixx7eI")
|
||||
|
||||
response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Set the 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)
|
||||
|
||||
# Can't update the link during the second phase
|
||||
response = self.client.post(reverse("participation:upload_video", args=(self.team.participation.solution.pk,)),
|
||||
data=dict(link="https://youtube.com/watch?v=73nsrixx7eI"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_questions(self):
|
||||
"""
|
||||
Ensure that creating/updating/deleting a question is working.
|
||||
"""
|
||||
self.user.registration.team = self.team
|
||||
self.user.registration.save()
|
||||
|
||||
self.team.participation.valid = True
|
||||
self.team.participation.save()
|
||||
|
||||
response = self.client.get(reverse("participation:add_question", args=(self.team.participation.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# We are not in second phase
|
||||
response = self.client.post(reverse("participation:add_question", args=(self.team.participation.pk,)),
|
||||
data=dict(question="I got censored!"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# Set the 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)
|
||||
|
||||
# Create a question
|
||||
response = self.client.post(reverse("participation:add_question", args=(self.team.participation.pk,)),
|
||||
data=dict(question="I asked a question!"))
|
||||
self.assertRedirects(response, reverse("participation:participation_detail",
|
||||
args=(self.team.participation.pk,)), 302, 200)
|
||||
qs = Question.objects.filter(participation=self.team.participation, question="I asked a question!")
|
||||
self.assertTrue(qs.exists())
|
||||
question = qs.get()
|
||||
|
||||
# Update a question
|
||||
response = self.client.get(reverse("participation:update_question", args=(question.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.post(reverse("participation:update_question", args=(question.pk,)), data=dict(
|
||||
question="The question changed!",
|
||||
))
|
||||
self.assertRedirects(response, reverse("participation:participation_detail",
|
||||
args=(self.team.participation.pk,)), 302, 200)
|
||||
question.refresh_from_db()
|
||||
self.assertEqual(question.question, "The question changed!")
|
||||
|
||||
# Delete the question
|
||||
response = self.client.get(reverse("participation:delete_question", args=(question.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.post(reverse("participation:delete_question", args=(question.pk,)))
|
||||
self.assertRedirects(response, reverse("participation:participation_detail",
|
||||
args=(self.team.participation.pk,)), 302, 200)
|
||||
self.assertFalse(Question.objects.filter(pk=question.pk).exists())
|
||||
|
||||
# Non-authenticated users are redirected to login page
|
||||
self.client.logout()
|
||||
response = self.client.get(reverse("participation:add_question", args=(self.team.participation.pk,)))
|
||||
self.assertRedirects(response, reverse("login") + "?next=" +
|
||||
reverse("participation:add_question", args=(self.team.participation.pk,)), 302, 200)
|
||||
response = self.client.get(reverse("participation:update_question", args=(self.question.pk,)))
|
||||
self.assertRedirects(response, reverse("login") + "?next=" +
|
||||
reverse("participation:update_question", args=(self.question.pk,)), 302, 200)
|
||||
response = self.client.get(reverse("participation:delete_question", args=(self.question.pk,)))
|
||||
self.assertRedirects(response, reverse("login") + "?next=" +
|
||||
reverse("participation:delete_question", args=(self.question.pk,)), 302, 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(), None)
|
||||
|
||||
# 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)
|
||||
|
||||
# Unauthenticated user can't update the calendar
|
||||
self.client.logout()
|
||||
response = self.client.get(reverse("participation:calendar"))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.get(reverse("participation:update_phase", args=(2,)))
|
||||
self.assertRedirects(response, reverse("login") + "?next=" +
|
||||
reverse("participation:update_phase", args=(2,)), 302, 200)
|
||||
|
||||
def test_forbidden_access(self):
|
||||
"""
|
||||
Load personal pages and ensure that these are protected.
|
||||
@ -679,20 +435,6 @@ class TestStudentParticipation(TestCase):
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
resp = self.client.get(reverse("participation:participation_detail", args=(self.second_team.pk,)))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
resp = self.client.get(reverse("participation:upload_video",
|
||||
args=(self.second_team.participation.solution.pk,)))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
resp = self.client.get(reverse("participation:upload_video",
|
||||
args=(self.second_team.participation.synthesis.pk,)))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
resp = self.client.get(reverse("participation:add_question", args=(self.second_team.pk,)))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
question = Question.objects.create(participation=self.second_team.participation,
|
||||
question=self.question.question)
|
||||
resp = self.client.get(reverse("participation:update_question", args=(question.pk,)))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
resp = self.client.get(reverse("participation:delete_question", args=(question.pk,)))
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
|
||||
def test_cover_matrix(self):
|
||||
"""
|
||||
@ -707,7 +449,6 @@ class TestStudentParticipation(TestCase):
|
||||
self.team.participation.save()
|
||||
|
||||
call_command('fix_matrix_channels')
|
||||
call_command('setup_third_phase')
|
||||
|
||||
|
||||
class TestAdmin(TestCase):
|
||||
@ -765,50 +506,6 @@ class TestAdmin(TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTrue(response.context["object_list"])
|
||||
|
||||
def test_set_received_video(self):
|
||||
"""
|
||||
Try to define the received video of a participation.
|
||||
"""
|
||||
response = self.client.get(reverse("participation:participation_receive_participation",
|
||||
args=(self.team1.participation.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.post(reverse("participation:participation_receive_participation",
|
||||
args=(self.team1.participation.pk,)),
|
||||
data=dict(received_participation=self.team2.participation.pk))
|
||||
self.assertRedirects(response, reverse("participation:participation_detail",
|
||||
args=(self.team1.participation.pk,)), 302, 200)
|
||||
|
||||
response = self.client.get(reverse("participation:participation_receive_participation",
|
||||
args=(self.team1.participation.pk,)))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.post(reverse("participation:participation_send_participation",
|
||||
args=(self.team1.participation.pk,)),
|
||||
data=dict(sent_participation=self.team3.participation.pk))
|
||||
self.assertRedirects(response, reverse("participation:participation_detail",
|
||||
args=(self.team1.participation.pk,)), 302, 200)
|
||||
|
||||
self.team1.participation.refresh_from_db()
|
||||
self.team2.participation.refresh_from_db()
|
||||
self.team3.participation.refresh_from_db()
|
||||
|
||||
self.assertEqual(self.team1.participation.received_participation.pk, self.team2.participation.pk)
|
||||
self.assertEqual(self.team1.participation.sent_participation.pk, self.team3.participation.pk)
|
||||
self.assertEqual(self.team2.participation.sent_participation.pk, self.team1.participation.pk)
|
||||
self.assertEqual(self.team3.participation.received_participation.pk, self.team1.participation.pk)
|
||||
|
||||
# The other team didn't work on the same problem
|
||||
response = self.client.post(reverse("participation:participation_receive_participation",
|
||||
args=(self.team1.participation.pk,)),
|
||||
data=dict(received_participation=self.other_team.participation.pk))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.post(reverse("participation:participation_send_participation",
|
||||
args=(self.team1.participation.pk,)),
|
||||
data=dict(sent_participation=self.other_team.participation.pk))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_create_team_forbidden(self):
|
||||
"""
|
||||
Ensure that an admin can't create a team.
|
||||
@ -816,7 +513,6 @@ class TestAdmin(TestCase):
|
||||
response = self.client.post(reverse("participation:create_team"), data=dict(
|
||||
name="Test team",
|
||||
trigram="TES",
|
||||
grant_animath_access_videos=False,
|
||||
))
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
|
Reference in New Issue
Block a user