本文整理汇总了Python中pyramid.testing.DummyRequest._get_authentication_policy方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest._get_authentication_policy方法的具体用法?Python DummyRequest._get_authentication_policy怎么用?Python DummyRequest._get_authentication_policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest._get_authentication_policy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_request_wrong_auth
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _get_authentication_policy [as 别名]
def test_request_wrong_auth(self):
from pyramid.testing import DummyRequest
from c2cgeoportal import get_user_from_request
from c2cgeoportal import default_user_validator
from c2cgeoportal.lib.authentication import create_authentication
request = DummyRequest(
headers={"Authorization": "Basic " + base64.b64encode("__test_user:__wrong_pass").replace("\n", "")}
)
request.registry.validate_user = default_user_validator
request._get_authentication_policy = lambda: create_authentication(
{"authtkt_cookie_name": "__test", "authtkt_secret": "123"}
)
request.set_property(get_user_from_request, name="user", reify=True)
self.assertEqual(request.user, None)
示例2: test_request_right_auth
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _get_authentication_policy [as 别名]
def test_request_right_auth(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.pyramid_ import default_user_validator
from c2cgeoportal.lib.authentication import create_authentication
request = DummyRequest(
headers={"Authorization": "Basic " + base64.b64encode("__test_user:__test_user").replace("\n", "")}
)
request.path_info_peek = lambda: "main"
request.registry.validate_user = default_user_validator
request._get_authentication_policy = lambda: create_authentication(
{"authtkt_cookie_name": "__test", "authtkt_secret": "123"}
)
add_user_property(request)
self.assertEqual(request.user.username, u"__test_user")
示例3: test_request_right_auth
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _get_authentication_policy [as 别名]
def test_request_right_auth(self):
from pyramid.testing import DummyRequest
from c2cgeoportal import get_user_from_request
from c2cgeoportal import default_user_validator
from c2cgeoportal.lib.authentication import create_authentication
request = DummyRequest(headers={
'Authorization': 'Basic ' + base64.b64encode('__test_user:__test_user').replace('\n', '')
})
request.registry.validate_user = default_user_validator
request._get_authentication_policy = lambda: create_authentication({
"authtkt_cookie_name": "__test",
"authtkt_secret": "123",
})
request.set_property(
get_user_from_request, name='user', reify=True
)
self.assertEqual(request.user.username, u'__test_user')