mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-04-28 12:52:40 +00:00
Compare commits
5 Commits
bf32c34d4c
...
aed9f457c3
Author | SHA1 | Date | |
---|---|---|---|
|
aed9f457c3 | ||
|
6afa1ea40b | ||
|
e98540a2a8 | ||
|
7353ecfd5f | ||
|
0a3fffe21e |
@ -1,6 +1,7 @@
|
|||||||
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.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from registration.models import StudentRegistration
|
from registration.models import StudentRegistration
|
||||||
@ -376,6 +377,45 @@ class TestStudentParticipation(TestCase):
|
|||||||
self.assertRedirects(response, reverse("participation:team_detail", args=(self.team.pk,)), 302, 200)
|
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", participation__problem=3).exists())
|
||||||
|
|
||||||
|
def test_leave_team(self):
|
||||||
|
"""
|
||||||
|
A user is in a team, and leaves it.
|
||||||
|
"""
|
||||||
|
# User is not in a team
|
||||||
|
response = self.client.post(reverse("participation:team_leave"))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
self.user.registration.team = self.team
|
||||||
|
self.user.registration.save()
|
||||||
|
|
||||||
|
# Team is pending validation
|
||||||
|
self.team.participation.valid = False
|
||||||
|
self.team.participation.save()
|
||||||
|
response = self.client.post(reverse("participation:team_leave"))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Team is valid
|
||||||
|
self.team.participation.valid = True
|
||||||
|
self.team.participation.save()
|
||||||
|
response = self.client.post(reverse("participation:team_leave"))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Unauthenticated users are redirected to login page
|
||||||
|
self.client.logout()
|
||||||
|
response = self.client.get(reverse("participation:team_leave"))
|
||||||
|
self.assertRedirects(response, reverse("login") + "?next=" + reverse("participation:team_leave"), 302, 200)
|
||||||
|
|
||||||
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
self.team.participation.valid = None
|
||||||
|
self.team.participation.save()
|
||||||
|
|
||||||
|
response = self.client.post(reverse("participation:team_leave"))
|
||||||
|
self.assertRedirects(response, reverse("index"), 302, 200)
|
||||||
|
self.user.registration.refresh_from_db()
|
||||||
|
self.assertIsNone(self.user.registration.team)
|
||||||
|
self.assertFalse(Team.objects.filter(pk=self.team.pk).exists())
|
||||||
|
|
||||||
def test_no_myparticipation_redirect_nomyparticipation(self):
|
def test_no_myparticipation_redirect_nomyparticipation(self):
|
||||||
"""
|
"""
|
||||||
Ensure a permission denied when we search my team participation when we are in no team.
|
Ensure a permission denied when we search my team participation when we are in no team.
|
||||||
@ -469,7 +509,7 @@ class TestStudentParticipation(TestCase):
|
|||||||
self.assertEqual(resp.status_code, 403)
|
self.assertEqual(resp.status_code, 403)
|
||||||
|
|
||||||
|
|
||||||
class TestAdminForbidden(TestCase):
|
class TestAdmin(TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.user = User.objects.create_superuser(
|
self.user = User.objects.create_superuser(
|
||||||
username="admin@example.com",
|
username="admin@example.com",
|
||||||
@ -478,6 +518,25 @@ class TestAdminForbidden(TestCase):
|
|||||||
)
|
)
|
||||||
self.client.force_login(self.user)
|
self.client.force_login(self.user)
|
||||||
|
|
||||||
|
def test_research(self):
|
||||||
|
"""
|
||||||
|
Try to search some things.
|
||||||
|
"""
|
||||||
|
team = Team.objects.create(
|
||||||
|
name="Best team ever",
|
||||||
|
trigram="BTE",
|
||||||
|
)
|
||||||
|
|
||||||
|
call_command("rebuild_index", "--noinput", "--verbosity", 0)
|
||||||
|
|
||||||
|
response = self.client.get(reverse("haystack_search") + "?q=" + team.name)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["object_list"])
|
||||||
|
|
||||||
|
response = self.client.get(reverse("haystack_search") + "?q=" + team.trigram)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertTrue(response.context["object_list"])
|
||||||
|
|
||||||
def test_create_team_forbidden(self):
|
def test_create_team_forbidden(self):
|
||||||
"""
|
"""
|
||||||
Ensure that an admin can't create a team.
|
Ensure that an admin can't create a team.
|
||||||
@ -500,9 +559,23 @@ class TestAdminForbidden(TestCase):
|
|||||||
))
|
))
|
||||||
self.assertTrue(response.status_code, 403)
|
self.assertTrue(response.status_code, 403)
|
||||||
|
|
||||||
|
def test_leave_team_forbidden(self):
|
||||||
|
"""
|
||||||
|
Ensure that an admin can't leave a team.
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("participation:team_leave"))
|
||||||
|
self.assertTrue(response.status_code, 403)
|
||||||
|
|
||||||
def test_my_team_forbidden(self):
|
def test_my_team_forbidden(self):
|
||||||
"""
|
"""
|
||||||
Ensure that an admin can't access to "My team".
|
Ensure that an admin can't access to "My team".
|
||||||
"""
|
"""
|
||||||
response = self.client.get(reverse("participation:my_team_detail"))
|
response = self.client.get(reverse("participation:my_team_detail"))
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
def test_my_participation_forbidden(self):
|
||||||
|
"""
|
||||||
|
Ensure that an admin can't access to "My participation".
|
||||||
|
"""
|
||||||
|
response = self.client.get(reverse("participation:my_participation_detail"))
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
@ -316,7 +316,7 @@ class TeamLeaveView(LoginRequiredMixin, TemplateView):
|
|||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
if not request.user.is_authenticated:
|
if not request.user.is_authenticated:
|
||||||
return self.handle_no_permission()
|
return self.handle_no_permission()
|
||||||
if not request.user.registration.team:
|
if not request.user.registration.participates or not request.user.registration.team:
|
||||||
raise PermissionDenied(_("You are not in a team."))
|
raise PermissionDenied(_("You are not in a team."))
|
||||||
if request.user.registration.team.participation.valid is not None:
|
if request.user.registration.team.participation.valid is not None:
|
||||||
raise PermissionDenied(_("The team is already validated or the validation is pending."))
|
raise PermissionDenied(_("The team is already validated or the validation is pending."))
|
||||||
|
@ -9,6 +9,7 @@ from ..tables import RegistrationTable
|
|||||||
|
|
||||||
def search_table(results):
|
def search_table(results):
|
||||||
model_class = results[0].object.__class__
|
model_class = results[0].object.__class__
|
||||||
|
table_class = Table
|
||||||
if issubclass(model_class, Registration):
|
if issubclass(model_class, Registration):
|
||||||
table_class = RegistrationTable
|
table_class = RegistrationTable
|
||||||
elif issubclass(model_class, Team):
|
elif issubclass(model_class, Team):
|
||||||
@ -17,8 +18,6 @@ def search_table(results):
|
|||||||
table_class = ParticipationTable
|
table_class = ParticipationTable
|
||||||
elif issubclass(model_class, Video):
|
elif issubclass(model_class, Video):
|
||||||
table_class = VideoTable
|
table_class = VideoTable
|
||||||
else:
|
|
||||||
table_class = Table
|
|
||||||
return table_class([result.object for result in results], prefix=model_class._meta.model_name)
|
return table_class([result.object for result in results], prefix=model_class._meta.model_name)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from corres2math.tokens import email_validation_token
|
from corres2math.tokens import email_validation_token
|
||||||
|
from django.conf import settings
|
||||||
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
|
||||||
@ -10,6 +11,7 @@ from django.urls import reverse
|
|||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
|
|
||||||
|
from .auth import CustomAuthUser
|
||||||
from .models import AdminRegistration, CoachRegistration, Registration, StudentRegistration
|
from .models import AdminRegistration, CoachRegistration, Registration, StudentRegistration
|
||||||
|
|
||||||
|
|
||||||
@ -179,6 +181,14 @@ class TestRegistration(TestCase):
|
|||||||
"""
|
"""
|
||||||
Update the user information, for each type of user.
|
Update the user information, for each type of user.
|
||||||
"""
|
"""
|
||||||
|
# To test the modification of mailing lists
|
||||||
|
from participation.models import Team
|
||||||
|
self.student.registration.team = Team.objects.create(
|
||||||
|
name="toto",
|
||||||
|
trigram="TOT",
|
||||||
|
)
|
||||||
|
self.student.registration.save()
|
||||||
|
|
||||||
for user, data in [(self.user, dict(role="Bot")),
|
for user, data in [(self.user, dict(role="Bot")),
|
||||||
(self.student, dict(student_class=11, school="Sky")),
|
(self.student, dict(student_class=11, school="Sky")),
|
||||||
(self.coach, dict(professional_activity="God"))]:
|
(self.coach, dict(professional_activity="God"))]:
|
||||||
@ -317,6 +327,15 @@ class TestRegistration(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertTrue(response.context["object_list"])
|
self.assertTrue(response.context["object_list"])
|
||||||
|
|
||||||
|
def test_init_cas(self):
|
||||||
|
"""
|
||||||
|
Load custom CAS authentication
|
||||||
|
"""
|
||||||
|
self.assertEqual(settings.CAS_AUTH_CLASS, "registration.auth.CustomAuthUser")
|
||||||
|
attr = CustomAuthUser(self.user.username).attributs()
|
||||||
|
self.assertEqual(attr["matrix_username"], self.user.registration.matrix_username)
|
||||||
|
self.assertEqual(attr["display_name"], str(self.user.registration))
|
||||||
|
|
||||||
def test_not_implemented_error(self):
|
def test_not_implemented_error(self):
|
||||||
# Only for coverage
|
# Only for coverage
|
||||||
self.assertRaises(NotImplementedError, lambda: Registration().type)
|
self.assertRaises(NotImplementedError, lambda: Registration().type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user