本文整理汇总了Python中flask.Request.authorization方法的典型用法代码示例。如果您正苦于以下问题:Python Request.authorization方法的具体用法?Python Request.authorization怎么用?Python Request.authorization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Request
的用法示例。
在下文中一共展示了Request.authorization方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_authorization_raises_exception_if_authorization_is_not_set
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import authorization [as 别名]
def test_authorization_raises_exception_if_authorization_is_not_set(self):
"Should raise an exception and the is_valid_user function should never be invoked"
is_valid_mock = mock.MagicMock(return_value=False)
builder = EnvironBuilder()
request = Request(builder.get_environ())
request.authorization = None
with self.assertRaises(Unauthorized):
BasicAuth(is_valid_user=is_valid_mock).authenticate(request)
self.assertEqual(is_valid_mock.call_count, 0)
示例2: test_authorization_raises_exception_if_user_is_not_valid
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import authorization [as 别名]
def test_authorization_raises_exception_if_user_is_not_valid(self):
"Should raise an Unauthorized exception if is_valid_user function returns False"
is_valid_mock = mock.MagicMock(return_value=False)
builder = EnvironBuilder()
request = Request(builder.get_environ())
request.authorization = {'username': 'john', 'password': 'xxx'}
with self.assertRaises(Unauthorized):
BasicAuth(is_valid_user=is_valid_mock).authenticate(request)
is_valid_mock.assert_called_once_with('john', 'xxx')
示例3: test_authorization_passes_if_is_valid_user_returns_True
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import authorization [as 别名]
def test_authorization_passes_if_is_valid_user_returns_True(self):
"Should return None if the user is valid"
is_valid_mock = mock.MagicMock(return_value=True)
builder = EnvironBuilder()
request = Request(builder.get_environ())
request.authorization = {'username': 'john', 'password': 'xxx'}
result = BasicAuth(is_valid_user=is_valid_mock).authenticate(request)
self.assertEqual(result, None)
is_valid_mock.assert_called_once_with('john', 'xxx')
示例4: test_valid_authentication
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import authorization [as 别名]
def test_valid_authentication(self):
is_valid_mock = mock.MagicMock(return_value=True)
builder = EnvironBuilder()
request = Request(builder.get_environ())
request.authorization = {'username': 'john', 'password': 'xxx'}
dummy = DummyAuthentication(valid_auth=True)
dummy_auth_mock = mock.MagicMock(return_value=True)
dummy.authenticate = dummy_auth_mock
auth = And(
BasicAuth(is_valid_user=is_valid_mock),
dummy
)
result = auth.authenticate(request)
self.assertEqual(result, None)
is_valid_mock.assert_called_once_with('john', 'xxx')
dummy_auth_mock.assert_called_once_with(request)
示例5: test_not_valid_authentication_second_auth_not_invoked
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import authorization [as 别名]
def test_not_valid_authentication_second_auth_not_invoked(self):
"Should raise an Unthorized exception and avoid invoking other auth strategies"
is_valid_mock = mock.MagicMock(return_value=False)
builder = EnvironBuilder()
request = Request(builder.get_environ())
request.authorization = {'username': 'john', 'password': 'xxx'}
dummy = DummyAuthentication(valid_auth=True)
dummy_auth_mock = mock.MagicMock(return_value=True)
dummy.authenticate = dummy_auth_mock
auth = And(
BasicAuth(is_valid_user=is_valid_mock),
dummy
)
with self.assertRaises(Unauthorized):
auth.authenticate(request)
is_valid_mock.assert_called_once_with('john', 'xxx')
self.assertEqual(dummy_auth_mock.call_count, 0)