本文整理汇总了Python中accounts.factories.UserFactory.set_unusable_password方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.set_unusable_password方法的具体用法?Python UserFactory.set_unusable_password怎么用?Python UserFactory.set_unusable_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类accounts.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.set_unusable_password方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CustomCustomPasswordResetFormTest
# 需要导入模块: from accounts.factories import UserFactory [as 别名]
# 或者: from accounts.factories.UserFactory import set_unusable_password [as 别名]
class CustomCustomPasswordResetFormTest(TestCase):
"""
Test our cutomised reset password form.
These tests are a modified version of those found at
django.contrib.auth.tests.testforms
"""
def setUp(self):
self.user = UserFactory(email='[email protected]')
def test_invalid_email(self):
form = CustomPasswordResetForm({'email': 'not valid'})
self.assertFalse(form.is_valid())
self.assertEqual(form['email'].errors, [_('Please enter a valid email address.')])
def test_nonexistent_email(self):
"""
Test nonexistent email address. This should not fail because it would
expose information about registered users.
"""
form = CustomPasswordResetForm({'email': '[email protected]'})
self.assertTrue(form.is_valid())
self.assertEqual(len(mail.outbox), 0)
def test_cleaned_data(self):
form = CustomPasswordResetForm({'email': self.user.email})
self.assertTrue(form.is_valid())
form.save(domain_override='example.com')
self.assertEqual(form.cleaned_data['email'], self.user.email)
self.assertEqual(len(mail.outbox), 1)
def test_custom_email_subject(self):
data = {'email': '[email protected]'}
form = CustomPasswordResetForm(data)
self.assertTrue(form.is_valid())
# Since we're not providing a request object, we must provide a
# domain_override to prevent the save operation from failing in the
# potential case where contrib.sites is not installed. Refs #16412.
form.save(domain_override='example.com')
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, 'Reset your example.com password')
def test_inactive_user(self):
"""
Test that inactive user cannot receive password reset email.
"""
self.user.is_active = False
self.user.save()
form = CustomPasswordResetForm({'email': self.user.email})
self.assertTrue(form.is_valid())
form.save()
self.assertEqual(len(mail.outbox), 0)
def test_unusable_password(self):
data = {"email": "[email protected]"}
form = CustomPasswordResetForm(data)
self.assertTrue(form.is_valid())
self.user.set_unusable_password()
self.user.save()
form = CustomPasswordResetForm(data)
# The form itself is valid, but no email is sent
self.assertTrue(form.is_valid())
form.save()
self.assertEqual(len(mail.outbox), 0)