Exemple #1
0
    def test_subscribe_all_primary_to_secondary_email(self):
        # setup
        self.profile.subscribed_newsletter = True
        self.profile.subscribed_gmm_invite = True
        self.profile.newsletter_recipient = "TUE"
        self.profile.save()

        recipient = "*****@*****.**"

        # act
        form = PreferencesUpdateForm(
            instance=self.profile,
            data=get_preferences_form_data(subscribed_newsletter=True,
                                           subscribed_gmm_invite=True,
                                           newsletter_recipient="ALT"),
        )
        form.full_clean()
        form.save()  # runs update_newsletter_preferences

        # test
        self.assertEqual(form["subscribed_newsletter"].initial, True)
        self.assertEqual(form["subscribed_gmm_invite"].initial, True)
        profile = Profile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.subscribed_newsletter, True)
        self.assertEqual(profile.subscribed_gmm_invite, True)
        self.assert_newsletter_subscription(recipient, True)
        self.assert_gmm_invite_subscription(recipient, True)
Exemple #2
0
    def test_fail_gmm_invite_enable_secondary_email_empty(self):
        # setup
        self.profile.user.email = ""
        self.profile.user.save()

        # act
        form = PreferencesUpdateForm(
            instance=self.profile,
            data=get_preferences_form_data(subscribed_gmm_invite=True,
                                           newsletter_recipient="ALT"),
        )
        form.full_clean()

        # test
        self.assertTrue(
            form.has_error("__all__",
                           error_codes.INVALID_SUBSCRIBE_TO_EMPTY_EMAIL))
Exemple #3
0
    def test_success_newsletter_unchanged(self):
        # setup
        recipient = "*****@*****.**"

        # act
        form = PreferencesUpdateForm(instance=self.profile,
                                     data=get_preferences_form_data())
        form.full_clean()
        form.save()  # runs update_newsletter_preferences

        # test
        self.assertEqual(form.instance.subscribed_newsletter, False)
        self.assertEqual(form.instance.subscribed_gmm_invite, False)
        profile = Profile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.subscribed_newsletter, False)
        self.assertEqual(profile.subscribed_gmm_invite, False)
        self.assert_newsletter_subscription(recipient, False)
        self.assert_gmm_invite_subscription(recipient, False)
Exemple #4
0
    def test_success_newsletter_enable_gmm_invite_sub_on_institution_email(
            self):
        # setup
        recipient = "*****@*****.**"

        # act
        form = PreferencesUpdateForm(
            instance=self.profile,
            data=get_preferences_form_data(subscribed_gmm_invite=True))
        form.full_clean()
        form.save()  # runs update_newsletter_preferences

        # test
        self.assertTrue(form.is_valid())
        profile = Profile.objects.get(pk=self.profile.pk)
        self.assertEqual(profile.subscribed_newsletter, False)
        self.assertEqual(profile.subscribed_gmm_invite, True)
        self.assert_newsletter_subscription(recipient, False)
        self.assert_gmm_invite_subscription(recipient, True)