Beispiel #1
0
    def test_unsubscription(self):
        self.backend.unregister('*****@*****.**', self.monthly, 'fr')

        self.backend.register('*****@*****.**', self.monthly, 'fr')
        self.backend.register('*****@*****.**', self.weekly, 'fr')
        self.backend.register('*****@*****.**', self.daily, 'fr')

        # Unsubscribe from monthly
        valid_data = {'email': '*****@*****.**', 'from_all': False}

        form = UnsubscribeForm(data=valid_data, initial={'email': '*****@*****.**'}, **{'newsletter_list': self.monthly})

        self.assertTrue(form.is_valid())

        form.save()

        old_subscriber = NewsletterSubscriber.objects.get(email=valid_data['email'],
                                                          newsletter_list=self.monthly)
        old_subscriber2 = NewsletterSubscriber.objects.get(email=valid_data['email'],
                                                           newsletter_list=self.weekly)

        self.assertEqual(old_subscriber.is_unsubscribed, True)
        self.assertEqual(old_subscriber.unsubscribed_at, datetime.now())
        self.assertEqual(old_subscriber2.is_unsubscribed, False)

        # Unsubscribe from all
        valid_data = {'email': '*****@*****.**', 'from_all': True}

        form = UnsubscribeForm(data=valid_data, newsletter_list=self.weekly)

        self.assertTrue(form.is_valid())

        form.save()

        old_subscriber = NewsletterSubscriber.objects.filter(email=valid_data['email'],
                                                             newsletter_list=self.weekly)
        old_subscriber2 = NewsletterSubscriber.objects.filter(email=valid_data['email'],
                                                              newsletter_list=self.daily)

        self.assertEqual(old_subscriber.get().is_unsubscribed, True)
        self.assertEqual(old_subscriber2.get().is_unsubscribed, True)
        self.assertEqual(old_subscriber2.get().unsubscribed_at, datetime.now())

        form2 = UnsubscribeForm(data=valid_data, newsletter_list=self.weekly)

        is_valid = form2.is_valid()

        self.assertEqual(is_valid, False)
Beispiel #2
0
    def test_unsubscription_logged_in(self):
        user = User.objects.create_user('thoas', '*****@*****.**', 'secret')

        self.backend.register('*****@*****.**', self.monthly, 'fr', user=user)
        new_subscriber = NewsletterSubscriber.objects.filter(email='*****@*****.**', user=user)
        self.assertEqual(new_subscriber.count(), 1)

        valid_data = {'email': '*****@*****.**', 'from_all': False}

        form = UnsubscribeForm(data=valid_data, initial={'email': '*****@*****.**'}, **{'newsletter_list': self.monthly})

        self.assertTrue(form.is_valid())

        form.save(user)  # Equivalent for saving with user logged in

        self.backend.unregister('*****@*****.**')
Beispiel #3
0
    def test_unsubscription(self):
        self.backend.unregister("*****@*****.**", self.monthly, lang="fr")

        self.backend.register("*****@*****.**", self.monthly, lang="fr")
        self.backend.register("*****@*****.**", self.weekly, lang="fr")
        self.backend.register("*****@*****.**", self.daily, lang="fr")

        # Unsubscribe from monthly
        valid_data = {"email": "*****@*****.**", "from_all": False}

        form = UnsubscribeForm(
            data=valid_data,
            initial={"email": "*****@*****.**"},
            **{"newsletter_list": self.monthly}
        )

        self.assertTrue(form.is_valid())

        form.save()

        old_subscriber = NewsletterSubscriber.objects.get(
            email=valid_data["email"], newsletter_list=self.monthly
        )
        old_subscriber2 = NewsletterSubscriber.objects.get(
            email=valid_data["email"], newsletter_list=self.weekly
        )

        self.assertEqual(old_subscriber.is_unsubscribed, True)
        self.assertEqual(old_subscriber.unsubscribed_at, datetime.now())
        self.assertEqual(old_subscriber2.is_unsubscribed, False)

        # Unsubscribe from all
        valid_data = {"email": "*****@*****.**", "from_all": True}

        form = UnsubscribeForm(data=valid_data, newsletter_list=self.weekly)

        self.assertTrue(form.is_valid())

        form.save()

        old_subscriber = NewsletterSubscriber.objects.filter(
            email=valid_data["email"], newsletter_list=self.weekly
        )
        old_subscriber2 = NewsletterSubscriber.objects.filter(
            email=valid_data["email"], newsletter_list=self.daily
        )

        self.assertEqual(old_subscriber.get().is_unsubscribed, True)
        self.assertEqual(old_subscriber2.get().is_unsubscribed, True)
        self.assertEqual(old_subscriber2.get().unsubscribed_at, datetime.now())
Beispiel #4
0
    def test_unsubscription_logged_in(self):
        user = User.objects.create_user('thoas', '*****@*****.**', 'secret')

        self.backend.register('*****@*****.**',
                              self.monthly,
                              'fr',
                              user=user)
        new_subscriber = NewsletterSubscriber.objects.filter(
            email='*****@*****.**', user=user)
        self.assertEqual(new_subscriber.count(), 1)

        valid_data = {'email': '*****@*****.**', 'from_all': False}

        form = UnsubscribeForm(data=valid_data,
                               initial={'email': '*****@*****.**'},
                               **{'newsletter_list': self.monthly})

        self.assertTrue(form.is_valid())

        form.save(user)  # Equivalent for saving with user logged in

        self.backend.unregister('*****@*****.**')
Beispiel #5
0
    def test_unsubscription_logged_in(self):
        user = User.objects.create_user("thoas", "*****@*****.**", "secret")

        self.backend.register("*****@*****.**", self.monthly, "fr", user=user)
        new_subscriber = NewsletterSubscriber.objects.filter(
            email="*****@*****.**", user=user
        )
        self.assertEqual(new_subscriber.count(), 1)

        valid_data = {"email": "*****@*****.**", "from_all": False}

        form = UnsubscribeForm(
            data=valid_data,
            initial={"email": "*****@*****.**"},
            **{"newsletter_list": self.monthly}
        )

        self.assertTrue(form.is_valid())

        form.save(user)  # Equivalent for saving with user logged in

        self.backend.unregister("*****@*****.**")
Beispiel #6
0
    def test_unsubscription(self):
        self.backend.unregister('*****@*****.**', self.monthly, 'fr')

        self.backend.register('*****@*****.**', self.monthly, 'fr')
        self.backend.register('*****@*****.**', self.weekly, 'fr')
        self.backend.register('*****@*****.**', self.daily, 'fr')

        # Unsubscribe from monthly
        valid_data = {'email': '*****@*****.**', 'from_all': False}

        form = UnsubscribeForm(data=valid_data,
                               initial={'email': '*****@*****.**'},
                               **{'newsletter_list': self.monthly})

        self.assertTrue(form.is_valid())

        form.save()

        old_subscriber = NewsletterSubscriber.objects.get(
            email=valid_data['email'], newsletter_list=self.monthly)
        old_subscriber2 = NewsletterSubscriber.objects.get(
            email=valid_data['email'], newsletter_list=self.weekly)

        self.assertEqual(old_subscriber.is_unsubscribed, True)
        self.assertEqual(old_subscriber2.is_unsubscribed, False)

        # Unsubscribe from all
        valid_data = {'email': '*****@*****.**', 'from_all': True}

        form = UnsubscribeForm(data=valid_data, newsletter_list=self.weekly)

        self.assertTrue(form.is_valid())

        form.save()

        old_subscriber = NewsletterSubscriber.objects.filter(
            email=valid_data['email'], newsletter_list=self.weekly)
        old_subscriber2 = NewsletterSubscriber.objects.filter(
            email=valid_data['email'], newsletter_list=self.daily)

        self.assertEqual(old_subscriber.get().is_unsubscribed, True)
        self.assertEqual(old_subscriber2.get().is_unsubscribed, True)

        form2 = UnsubscribeForm(data=valid_data, newsletter_list=self.weekly)

        is_valid = form2.is_valid()

        self.assertEqual(is_valid, False)