diff --git a/apps/participation/tests.py b/apps/participation/tests.py index abd8dd7..df4a7d9 100644 --- a/apps/participation/tests.py +++ b/apps/participation/tests.py @@ -1,9 +1,11 @@ from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType +from django.contrib.sites.models import Site from django.test import TestCase from django.urls import reverse from registration.models import StudentRegistration -from .models import Team +from .models import Participation, Question, Team, Video class TestStudentParticipation(TestCase): @@ -27,11 +29,72 @@ class TestStudentParticipation(TestCase): 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) - # TODO Remove these lines - str(self.team) - str(self.team.participation) + def test_admin_pages(self): + """ + Load Django-admin pages. + """ + superuser = User.objects.create_superuser( + username="admin", + email="admin@example.com", + password="toto1234", + ) + self.client.force_login(superuser) + + # Test team pages + response = self.client.get(reverse("admin:index") + "participation/team/") + self.assertEqual(response.status_code, 200) + + response = self.client.get(reverse("admin:index") + + f"participation/team/{self.team.pk}/change/") + self.assertEqual(response.status_code, 200) + response = self.client.get(reverse("admin:index") + + f"r/{ContentType.objects.get_for_model(Team).id}/" + f"{self.team.pk}/") + self.assertRedirects(response, "http://" + Site.objects.get().domain + + str(self.team.get_absolute_url()), 302, 200) + + # Test participation pages + self.team.participation.valid = True + self.team.participation.save() + response = self.client.get(reverse("admin:index") + "participation/participation/") + self.assertEqual(response.status_code, 200) + + response = self.client.get(reverse("admin:index") + + f"participation/participation/{self.team.participation.pk}/change/") + self.assertEqual(response.status_code, 200) + response = self.client.get(reverse("admin:index") + + f"r/{ContentType.objects.get_for_model(Participation).id}/" + f"{self.team.participation.pk}/") + 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") + + f"participation/phase/1/change/") + self.assertEqual(response.status_code, 200) def test_create_team(self): """ @@ -62,6 +125,7 @@ class TestStudentParticipation(TestCase): trigram="TET", grant_animath_access_videos=False, )) + self.assertEqual(response.status_code, 403) def test_join_team(self): """