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


Python Subscription.subscribe_activate_url方法代码示例

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


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

示例1: test_subscribe_request_activate_form_loophole

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import subscribe_activate_url [as 别名]
    def test_subscribe_request_activate_form_loophole(self):
        """
        Prevent updating to unconfirmed email address. (#108)
        """

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

        activate_url = subscription.subscribe_activate_url()

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

        testname2 = 'Test Name2'
        testemail2 = '[email protected]'
        response = self.client.post(activate_url, {
            'name_field': testname2,
            'email_field': testemail2,
            'user_activation_code': subscription.activation_code
        })

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

        subscription = Subscription.objects.get(pk=subscription.pk)

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

示例2: test_subscribe_request_activate

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import subscribe_activate_url [as 别名]
    def test_subscribe_request_activate(self):
        """ Test subscription activation. """

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

        time.sleep(WAIT_TIME)

        self.assertFalse(subscription.subscribed)

        activate_url = subscription.subscribe_activate_url()
        self.assertTrue(activate_url)

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

        response = self.client.post(
            activate_url, {
                'name_field': 'Test Name',
                'email_field': self.testemail,
                '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)

        dt = (subscription.subscribe_date - subscription.create_date).seconds
        self.assertBetween(dt, WAIT_TIME, WAIT_TIME + 1)
开发者ID:dokterbob,项目名称:django-newsletter,代码行数:41,代码来源:test_web.py

示例3: test_subscribe_unsubscribed

# 需要导入模块: from newsletter.models import Subscription [as 别名]
# 或者: from newsletter.models.Subscription import subscribe_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.subscribe_activate_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。