From be6059eba6f856f0c876021450690e93200fa299 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 9 Sep 2021 09:47:04 +0200 Subject: [PATCH] [WEI] Fix tests Signed-off-by: Yohann D'ANELLO --- apps/wei/tests/test_wei_registration.py | 27 +++++++++++++++++++------ apps/wei/views.py | 12 ++++++----- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/apps/wei/tests/test_wei_registration.py b/apps/wei/tests/test_wei_registration.py index 0bc84013..65edd902 100644 --- a/apps/wei/tests/test_wei_registration.py +++ b/apps/wei/tests/test_wei_registration.py @@ -65,8 +65,6 @@ class TestWEIRegistration(TestCase): sess["permission_mask"] = 42 sess.save() - NoteUser.objects.create(user=self.user) - self.year = timezone.now().year self.wei = WEIClub.objects.create( name="Test WEI", @@ -304,6 +302,7 @@ class TestWEIRegistration(TestCase): self.assertEqual(response.status_code, 200) user = User.objects.create(username="toto", email="toto@example.com") + NoteUser.objects.create(user=user) # Try with an invalid form response = self.client.post(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk)), dict( @@ -370,7 +369,7 @@ class TestWEIRegistration(TestCase): last_name="toto", bank="Société générale", )) - response = self.client.get(reverse("wei:wei_register_2A_myself", kwargs=dict(wei_pk=self.wei.pk))) + response = self.client.get(reverse("wei:wei_register_2A", kwargs=dict(wei_pk=self.wei.pk))) self.assertEqual(response.status_code, 200) # Check that if the WEI is started, we can't register anyone @@ -386,10 +385,8 @@ class TestWEIRegistration(TestCase): response = self.client.get(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk))) self.assertEqual(response.status_code, 200) - response = self.client.get(reverse("wei:wei_register_1A_myself", kwargs=dict(wei_pk=self.wei.pk))) - self.assertEqual(response.status_code, 200) - user = User.objects.create(username="toto", email="toto@example.com") + NoteUser.objects.create(user=user) response = self.client.post(reverse("wei:wei_register_1A", kwargs=dict(wei_pk=self.wei.pk)), dict( user=user.id, soge_credit=True, @@ -469,6 +466,24 @@ class TestWEIRegistration(TestCase): response = self.client.get(reverse("wei:wei_survey", kwargs=dict(pk=registration.pk))) self.assertRedirects(response, reverse("wei:wei_closed", kwargs=dict(pk=self.wei.pk)), 302, 200) + def test_register_myself(self): + """ + Try to register myself to the WEI, and check redirections. + """ + response = self.client.get(reverse('wei:wei_register_1A_myself', args=(self.wei.pk,))) + self.assertRedirects(response, reverse('wei:wei_update_registration', args=(self.registration.pk,))) + + response = self.client.get(reverse('wei:wei_register_2A_myself', args=(self.wei.pk,))) + self.assertRedirects(response, reverse('wei:wei_update_registration', args=(self.registration.pk,))) + + self.registration.delete() + + response = self.client.get(reverse('wei:wei_register_1A_myself', args=(self.wei.pk,))) + self.assertEqual(response.status_code, 200) + + response = self.client.get(reverse('wei:wei_register_2A_myself', args=(self.wei.pk,))) + self.assertEqual(response.status_code, 200) + def test_wei_survey_ended(self): """ Test display the end page of a survey. diff --git a/apps/wei/views.py b/apps/wei/views.py index c24b6c45..20243c40 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -691,12 +691,14 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update context["membership_form"] = membership_form elif not self.object.first_year and PermissionBackend.check_perm( self.request, "wei.change_weiregistration_information_json", self.object): + information = self.object.information + d = dict( + bus=Bus.objects.filter(pk__in=information["preferred_bus_pk"]).all(), + team=BusTeam.objects.filter(pk__in=information["preferred_team_pk"]).all(), + roles=WEIRole.objects.filter(pk__in=information["preferred_roles_pk"]).all(), + ) if 'preferred_bus_pk' in information else dict() choose_bus_form = WEIChooseBusForm( - self.request.POST if self.request.POST else dict( - bus=Bus.objects.filter(pk__in=self.object.information["preferred_bus_pk"]).all(), - team=BusTeam.objects.filter(pk__in=self.object.information["preferred_team_pk"]).all(), - roles=WEIRole.objects.filter(pk__in=self.object.information["preferred_roles_pk"]).all(), - ) + self.request.POST if self.request.POST else d ) choose_bus_form.fields["bus"].queryset = Bus.objects.filter(wei=context["club"]) choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])