pytition / Pytition

Django app for self-hosted privacy-friendly online petitions
https://pytition.org
BSD 3-Clause "New" or "Revised" License
100 stars 28 forks source link

Issue 311 #312

Closed rsk2 closed 8 months ago

rsk2 commented 11 months ago

For #311

fallen commented 11 months ago

For the unit test you can either add a new test in pytition/petition/tests/tests_EditPetitionView.py or just modify test_edit_petition_POST_social_network_form(). I would see it like this:

rsk2 commented 11 months ago

For the unit test you can either add a new test in pytition/petition/tests/tests_EditPetitionView.py or just modify test_edit_petition_POST_social_network_form(). I would see it like this:

OK. I am planning to add new test in the file pytition/petition/tests/tests_EditPetitionView.py

* Testing that submitting the form with one of the `has_xxx_share_button` set and that the Petition object then has the correct property value

@fallen can you please give me an example test for one of the has_xxx_share_button?

fallen commented 11 months ago

@fallen can you please give me an example test for one of the has_xxx_share_button?

Sure, here you go:

    def test_edit_petition_email_share_button(self):
        julia = self.login('julia')
        org = Organization.objects.get(name='RAP')
        share_button_form_data = {
            'social_network_form_submitted': 'yes',
            'has_email_share_button': True,
        }

        # For an org owned petition
        p = Petition.objects.create(title="My petition", org=org)

        # By default, a new petition has no share button
        self.assertFalse(p.has_email_share_button)

        # Now let's enable the email share button
        response = self.client.post(reverse("edit_petition", args=[p.id]),
                                    share_button_form_data)
        self.assertEqual(response.status_code, 200)
        p.refresh_from_db()
        self.assertTemplateUsed(response, "petition/edit_petition.html")
        self.assertEquals(response.context['social_network_form'].is_valid(), True)
        self.assertEquals(response.context['social_network_form'].is_bound, True)
        self.assertEquals(response.context['content_form_submitted'], False)
        self.assertEquals(response.context['email_form_submitted'], False)
        self.assertEquals(response.context['social_network_form_submitted'], True)
        self.assertEquals(response.context['newsletter_form_submitted'], False)
        self.assertTrue(p.has_email_share_button)

        # Let's now turn it back off
        share_button_form_data['has_email_share_button'] = False
        response = self.client.post(reverse("edit_petition", args=[p.id]),
                                    share_button_form_data)
        self.assertEqual(response.status_code, 200)
        p.refresh_from_db()
        self.assertFalse(p.has_email_share_button)

        # For a user owned petition
        p = Petition.objects.create(title="My petition 2", user=julia)

        # By default, a new petition has no share button
        self.assertFalse(p.has_email_share_button)

        # Now let's enable the email share button
        share_button_form_data['has_email_share_button'] = True
        response = self.client.post(reverse("edit_petition", args=[p.id]), share_button_form_data)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "petition/edit_petition.html")
        p.refresh_from_db()
        self.assertEquals(response.context['social_network_form'].is_valid(), True)
        self.assertEquals(response.context['social_network_form'].is_bound, True)
        self.assertEquals(response.context['content_form_submitted'], False)
        self.assertEquals(response.context['email_form_submitted'], False)
        self.assertEquals(response.context['social_network_form_submitted'], True)
        self.assertEquals(response.context['newsletter_form_submitted'], False)
        self.assertTrue(p.has_email_share_button)

        # Let's now turn it back off
        share_button_form_data['has_email_share_button'] = False
        response = self.client.post(reverse("edit_petition", args=[p.id]), share_button_form_data)
        self.assertEqual(response.status_code, 200)
        p.refresh_from_db()
        self.assertFalse(p.has_email_share_button)

This tests that when creating a Petition, the "has_email_share_button" is by default "off" and then tries to enable it and switch it back off using the "edit_petition" view. This is done twice: once for an organization owned Petition and once for a user owned Petition.

I hope you are well and I wish you a very happy festive season :)

rsk2 commented 11 months ago

@fallen Wish you a very happy festive season too!

rsk2 commented 9 months ago

Hi @fallen, hope all is well. The PR is ready for review and please take a look whenever you get the chance.