本文整理匯總了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)