mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-02-11 11:41:19 +00:00
Test leave team
This commit is contained in:
parent
bf32c34d4c
commit
0a3fffe21e
@ -376,6 +376,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.
|
||||||
@ -500,6 +539,13 @@ 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".
|
||||||
|
@ -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."))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user