Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pytition/petition/tests/tests_PetitionViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def test_petition_detail(self):
self.assertContains(response, text='<meta property="og:url" content="http://testserver/petition/{}/" />'
.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()
Expand Down Expand Up @@ -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)
self.assertEqual(petition.published, True)
9 changes: 8 additions & 1 deletion pytition/petition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!
Could you add one unit test for this new feature?
Just check that if a user is logged in, its personal information are displayed in the HTML form and that

form.is_bound == True

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep !


reasons = ModerationReason.objects.all()
ctx = {"user": pytitionuser, "petition": petition, "form": sign_form,
Expand Down