diff --git a/pytition/petition/tests/tests_PetitionViews.py b/pytition/petition/tests/tests_PetitionViews.py index 2a0eb522..0a18b10b 100644 --- a/pytition/petition/tests/tests_PetitionViews.py +++ b/pytition/petition/tests/tests_PetitionViews.py @@ -36,6 +36,19 @@ def test_petition_detail(self): self.assertContains(response, text='' .format(petition.id)) + def test_fill_petition_when_logged(self): + """ if logged in, the petition form should be pre filled with user account info """ + petition = Petition.objects.filter(user__user__username="julia").first() + self.login('john') + response = self.client.get(reverse("detail", args=[petition.id])) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['petition'], petition) + self.assertTemplateUsed(response, "petition/petition_detail.html") + + form = response.context['form'] + self.assertEqual(form.is_bound, True) + self.assertContains(response, text='value="John"') + def test_petition_success_msg(self): """ Test that the success modal is there when signing and confirming """ petition = Petition.objects.filter(published=True).first() @@ -228,4 +241,4 @@ def test_petition_unpublish_org(self): response = self.client.get(reverse("petition_unpublish", args=[petition.id])) petition.refresh_from_db() self.assertEqual(response.status_code, 403) - self.assertEqual(petition.published, True) \ No newline at end of file + self.assertEqual(petition.published, True) diff --git a/pytition/petition/views.py b/pytition/petition/views.py index 4cbfa742..fd6a990c 100644 --- a/pytition/petition/views.py +++ b/pytition/petition/views.py @@ -1594,8 +1594,15 @@ def slug_show_petition(request, orgslugname=None, username=None, petitionname=No except SlugModel.DoesNotExist: raise Http404(_("Sorry, we are not able to find this petition")) petition = slug.petition + + initial = None if not pytitionuser else { + 'first_name': pytitionuser.user.first_name, + 'last_name': pytitionuser.user.last_name, + 'email': pytitionuser.user.email + } + check_petition_is_accessible(request, petition) - sign_form = SignatureForm(petition=petition) + sign_form = SignatureForm(petition=petition, initial=initial) reasons = ModerationReason.objects.all() ctx = {"user": pytitionuser, "petition": petition, "form": sign_form,