本文整理汇总了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)
示例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)
示例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)