当前位置: 首页>>代码示例>>Python>>正文


Python Subscription.unsubscribe_activate_url方法代码示例

本文整理汇总了Python中newsletter.models.Subscription.unsubscribe_activate_url方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.unsubscribe_activate_url方法的具体用法?Python Subscription.unsubscribe_activate_url怎么用?Python Subscription.unsubscribe_activate_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在newsletter.models.Subscription的用法示例。


在下文中一共展示了Subscription.unsubscribe_activate_url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_unsubscribe_request_activate

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import unsubscribe_activate_url [as 别名]
    def test_unsubscribe_request_activate(self):
        """ Update a request. """

        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail)
        subscription.save()

        activate_url = subscription.unsubscribe_activate_url()

        response = self.client.get(activate_url)
        self.assertInContext(response, 'form', UpdateForm)
        self.assertContains(response, subscription.activation_code)

        testname2 = 'Test Name2'
        response = self.client.post(activate_url, {
            'name_field': testname2,
            'user_activation_code': subscription.activation_code
        })

        # Assure we are redirected to "unsubscribe activated" page.
        self.assertRedirects(response, self.unsubscribe_activated_url)

        subscription = self.get_only_subscription(
            email_field__exact=self.testemail
        )

        self.assertTrue(subscription.unsubscribed)
        self.assertEqual(subscription.name, testname2)
        self.assertEqual(subscription.email, self.testemail)

        dt = (timezone.now() - subscription.unsubscribe_date).seconds
        self.assertLessThan(dt, 2)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:35,代码来源:test_web.py

示例2: test_unsubscribe_request_post

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import unsubscribe_activate_url [as 别名]
    def test_unsubscribe_request_post(self):
        """ Post the unsubscribe request form. """

        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail,
                                    subscribed=True)
        subscription.save()

        response = self.client.post(
            self.unsubscribe_url, {'email_field': self.testemail}
        )

        # Assure we are redirected to "unsubscribe activation email sent" page.
        self.assertRedirects(response, self.unsubscribe_email_sent_url)

        """ Check the subscription email. """
        self.assertEqual(len(mail.outbox), 1)

        activate_url = subscription.unsubscribe_activate_url()
        full_activate_url = 'http://%s%s' % (self.site.domain, activate_url)

        self.assertEmailContains(full_activate_url)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:25,代码来源:test_web.py

示例3: test_subscribe_unsubscribed

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import unsubscribe_activate_url [as 别名]
    def test_subscribe_unsubscribed(self):
        """
        After having been unsubscribed, a user should be able to subscribe
        again.

        This relates to #5 on GitHub.
        """

        # Create a subscription
        subscription = Subscription(newsletter=self.n,
                                    name=self.testname,
                                    email=self.testemail,
                                    subscribed=True)
        subscription.save()

        # Unsubscribe
        response = self.client.post(
            subscription.unsubscribe_activate_url(),
            {
                'name_field': subscription.name,
                'email_field': subscription.email,
                'user_activation_code': subscription.activation_code
            }
        )

        # Assure we are redirected to "unsubscribe activated" page.
        self.assertRedirects(response, self.unsubscribe_activated_url)

        subscription = self.get_only_subscription(
            email_field__exact=self.testemail
        )

        self.assertFalse(subscription.subscribed)
        self.assertTrue(subscription.unsubscribed)

        # Resubscribe request
        response = self.client.post(
            self.subscribe_url,
            {
                'name_field': subscription.name,
                'email_field': subscription.email,
            }
        )

        # Assure we are redirected to "email sent page"
        self.assertRedirects(response, self.subscribe_email_sent_url)

        # self.assertFalse(subscription.subscribed)
        self.assertTrue(subscription.unsubscribed)

        # Activate subscription
        response = self.client.post(
            subscription.subscribe_activate_url(),
            {
                'name_field': subscription.name,
                'email_field': subscription.email,
                'user_activation_code': subscription.activation_code
            }
        )

        # Assure we are redirected to "subscribe activated" page.
        self.assertRedirects(response, self.subscribe_activated_url)

        subscription = self.get_only_subscription(
            email_field__exact=self.testemail
        )

        self.assertTrue(subscription.subscribed)
        self.assertFalse(subscription.unsubscribed)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:71,代码来源:test_web.py


注:本文中的newsletter.models.Subscription.unsubscribe_activate_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。