本文整理汇总了Python中django_browserid.auth.BrowserIDBackend.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python BrowserIDBackend.authenticate方法的具体用法?Python BrowserIDBackend.authenticate怎么用?Python BrowserIDBackend.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_browserid.auth.BrowserIDBackend
的用法示例。
在下文中一共展示了BrowserIDBackend.authenticate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify_called_with_extra_kwargs
# 需要导入模块: from django_browserid.auth import BrowserIDBackend [as 别名]
# 或者: from django_browserid.auth.BrowserIDBackend import authenticate [as 别名]
def test_verify_called_with_extra_kwargs(self):
backend = BrowserIDBackend()
verifier = MockVerifier('[email protected]')
verifier.verify = Mock(wraps=verifier.verify)
backend.get_verifier = lambda: verifier
backend.authenticate(assertion='asdf', audience='http://testserver', foo='bar')
verifier.verify.assert_called_with('asdf', 'http://testserver', foo='bar')
示例2: auth
# 需要导入模块: from django_browserid.auth import BrowserIDBackend [as 别名]
# 或者: from django_browserid.auth.BrowserIDBackend import authenticate [as 别名]
def auth(self, verified_email=None, **kwargs):
"""
Attempt to authenticate a user with BrowserIDBackend.
If verified_email is None, verification will fail, otherwise it will
pass and return the specified email.
"""
with mock_browserid(verified_email):
backend = BrowserIDBackend()
return backend.authenticate(assertion='asdf', audience='asdf', **kwargs)
示例3: test_authenticate_verify_exception
# 需要导入模块: from django_browserid.auth import BrowserIDBackend [as 别名]
# 或者: from django_browserid.auth.BrowserIDBackend import authenticate [as 别名]
def test_authenticate_verify_exception(self):
"""
If the verifier raises an exception, log it as a warning and
return None.
"""
backend = BrowserIDBackend()
verifier = Mock()
exception = Exception()
backend.get_verifier = lambda: verifier
verifier.verify.side_effect = exception
with patch('django_browserid.auth.logger') as logger:
self.assertEqual(backend.authenticate('asdf', 'asdf'), None)
logger.warn.assert_called_with(exception)
示例4: _auth
# 需要导入模块: from django_browserid.auth import BrowserIDBackend [as 别名]
# 或者: from django_browserid.auth.BrowserIDBackend import authenticate [as 别名]
def _auth(self, backend=None, verified_email=None):
if backend is None:
backend = BrowserIDBackend()
with mock_browserid(verified_email):
return backend.authenticate(assertion='asdf', audience='asdf')
示例5: BrowserIDBackendTests
# 需要导入模块: from django_browserid.auth import BrowserIDBackend [as 别名]
# 或者: from django_browserid.auth.BrowserIDBackend import authenticate [as 别名]
class BrowserIDBackendTests(TestCase):
def setUp(self):
self.backend = BrowserIDBackend()
self.verifier = Mock()
self.backend.get_verifier = lambda: self.verifier
def test_verify_failure(self):
"""If verification fails, return None."""
self.verifier.verify.return_value = False
self.assertEqual(self.backend.verify('asdf', 'qwer'), None)
self.verifier.verify.assert_called_with('asdf', 'qwer')
def test_verify_success(self):
"""
If verification succeeds, return the email address from the
verification result.
"""
self.verifier.verify.return_value = Mock(email='[email protected]')
self.assertEqual(self.backend.verify('asdf', 'qwer'), '[email protected]')
self.verifier.verify.assert_called_with('asdf', 'qwer')
def test_verify_no_audience_request(self):
"""
If no audience is provided but a request is, retrieve the
audience from the request using get_audience.
"""
request = Mock()
with patch('django_browserid.auth.get_audience') as get_audience:
self.backend.verify('asdf', request=request)
get_audience.assert_called_with(request)
self.verifier.verify.assert_called_with('asdf', get_audience.return_value)
def test_verify_no_audience_no_assertion_no_service(self):
"""
If the assertion isn't provided, or the audience and request
aren't provided, return None.
"""
self.assertEqual(self.backend.verify(audience='asdf'), None)
self.assertEqual(self.backend.verify(assertion='asdf'), None)
with patch('django_browserid.auth.get_audience') as get_audience:
get_audience.return_value = None
self.assertEqual(self.backend.verify('asdf', request=Mock()), None)
def test_verify_kwargs(self):
"""Any extra kwargs should be passed to the verifier."""
self.backend.verify('asdf', 'asdf', request='blah', foo='bar', baz=1)
self.verifier.verify.assert_called_with('asdf', 'asdf', foo='bar', baz=1)
def auth(self, verified_email=None, **kwargs):
"""
Attempt to authenticate a user with BrowserIDBackend.
If verified_email is None, verification will fail, otherwise it will
pass and return the specified email.
"""
self.backend.verify = Mock(return_value=verified_email)
return self.backend.authenticate(assertion='asdf', audience='asdf', **kwargs)
def test_duplicate_emails(self):
"""
If there are two users with the same email address, return None.
"""
new_user('[email protected]', 'test1')
new_user('[email protected]', 'test2')
self.assertTrue(self.auth('[email protected]') is None)
def test_auth_success(self):
"""
If a single user is found with the verified email, return an
instance of their user object.
"""
user = new_user('[email protected]')
self.assertEqual(self.auth('[email protected]'), user)
@patch.object(settings, 'BROWSERID_CREATE_USER', False)
def test_no_create_user(self):
"""
If user creation is disabled and no user is found, return None.
"""
self.assertTrue(self.auth('[email protected]') is None)
@patch.object(settings, 'BROWSERID_CREATE_USER', True)
def test_create_user(self):
"""
If user creation is enabled and no user is found, return a new
User.
"""
user = self.auth('[email protected]')
self.assertTrue(user is not None)
self.assertTrue(isinstance(user, User))
self.assertEqual(user.email, '[email protected]')
@patch.object(settings, 'BROWSERID_CREATE_USER',
'django_browserid.tests.test_auth.new_user')
@patch('django_browserid.tests.test_auth.new_user')
def test_custom_create_user(self, create_user):
"""
If user creation is enabled with a custom create function and no
user is found, return the new user created with the custom
function.
#.........这里部分代码省略.........