本文整理汇总了Python中kitsune.users.tests.UserFactory.check_password方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.check_password方法的具体用法?Python UserFactory.check_password怎么用?Python UserFactory.check_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kitsune.users.tests.UserFactory
的用法示例。
在下文中一共展示了UserFactory.check_password方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PasswordChangeTests
# 需要导入模块: from kitsune.users.tests import UserFactory [as 别名]
# 或者: from kitsune.users.tests.UserFactory import check_password [as 别名]
class PasswordChangeTests(TestCaseBase):
def setUp(self):
super(PasswordChangeTests, self).setUp()
self.u = UserFactory()
self.url = reverse('users.pw_change')
self.new_pw = 'fjdka387fvstrongpassword!'
self.client.login(username=self.u.username, password='testpass')
def test_change_password(self):
assert self.u.check_password(self.new_pw) is False
r = self.client.post(self.url, {'old_password': 'testpass',
'new_password1': self.new_pw,
'new_password2': self.new_pw})
eq_(302, r.status_code)
eq_('http://testserver/en-US/users/pwchangecomplete', r['location'])
self.u = User.objects.get(username=self.u.username)
assert self.u.check_password(self.new_pw)
def test_bad_old_password(self):
r = self.client.post(self.url, {'old_password': 'testpqss',
'new_password1': self.new_pw,
'new_password2': self.new_pw})
eq_(200, r.status_code)
doc = pq(r.content)
eq_('Your old password was entered incorrectly. Please enter it '
'again.', doc('ul.errorlist').text())
def test_new_pw_doesnt_match(self):
r = self.client.post(self.url, {'old_password': 'testpqss',
'new_password1': self.new_pw,
'new_password2': self.new_pw + '1'})
eq_(200, r.status_code)
doc = pq(r.content)
eq_("The two password fields didn't match. Your old password was "
"entered incorrectly. Please enter it again.",
doc('ul.errorlist').text())
示例2: PasswordResetTests
# 需要导入模块: from kitsune.users.tests import UserFactory [as 别名]
# 或者: from kitsune.users.tests.UserFactory import check_password [as 别名]
class PasswordResetTests(TestCaseBase):
def setUp(self):
super(PasswordResetTests, self).setUp()
self.u = UserFactory(email="[email protected]")
self.uidb36 = int_to_base36(self.u.id)
self.token = default_token_generator.make_token(self.u)
self.orig_debug = settings.DEBUG
settings.DEBUG = True
def tearDown(self):
super(PasswordResetTests, self).tearDown()
settings.DEBUG = self.orig_debug
def test_bad_email(self):
r = self.client.post(reverse('users.pw_reset'),
{'email': '[email protected]'})
eq_(302, r.status_code)
eq_('http://testserver/en-US/users/pwresetsent', r['location'])
eq_(0, len(mail.outbox))
@mock.patch.object(Site.objects, 'get_current')
def test_success(self, get_current):
get_current.return_value.domain = 'testserver.com'
r = self.client.post(reverse('users.pw_reset'),
{'email': self.u.email})
eq_(302, r.status_code)
eq_('http://testserver/en-US/users/pwresetsent', r['location'])
eq_(1, len(mail.outbox))
assert mail.outbox[0].subject.find('Password reset') == 0
assert mail.outbox[0].body.find('pwreset/%s' % self.uidb36) > 0
@mock.patch.object(PasswordResetForm, 'save')
def test_smtp_error(self, pwform_save):
def raise_smtp(*a, **kw):
raise SMTPRecipientsRefused(recipients=[self.u.email])
pwform_save.side_effect = raise_smtp
r = self.client.post(reverse('users.pw_reset'),
{'email': self.u.email})
self.assertContains(r, unicode(ERROR_SEND_EMAIL))
def _get_reset_url(self):
return reverse('users.pw_reset_confirm',
args=[self.uidb36, self.token])
def test_bad_reset_url(self):
r = self.client.get('/users/pwreset/junk/', follow=True)
eq_(r.status_code, 404)
r = self.client.get(reverse('users.pw_reset_confirm',
args=[self.uidb36, '12-345']))
eq_(200, r.status_code)
doc = pq(r.content)
eq_('Password reset unsuccessful', doc('article h1').text())
def test_reset_fail(self):
url = self._get_reset_url()
r = self.client.post(url, {'new_password1': '', 'new_password2': ''})
eq_(200, r.status_code)
doc = pq(r.content)
eq_(1, len(doc('ul.errorlist')))
r = self.client.post(url, {'new_password1': 'onetwo12',
'new_password2': 'twotwo22'})
eq_(200, r.status_code)
doc = pq(r.content)
eq_("The two password fields didn't match.",
doc('ul.errorlist li').text())
def test_reset_success(self):
url = self._get_reset_url()
new_pw = 'fjdka387fvstrongpassword!'
assert self.u.check_password(new_pw) is False
r = self.client.post(url, {'new_password1': new_pw,
'new_password2': new_pw})
eq_(302, r.status_code)
eq_('http://testserver/en-US/users/pwresetcomplete', r['location'])
self.u = User.objects.get(username=self.u.username)
assert self.u.check_password(new_pw)
def test_reset_user_with_unusable_password(self):
"""Verify that user's with unusable passwords can reset them."""
self.u.set_unusable_password()
self.u.save()
self.test_success()