本文整理汇总了Python中pyramid.testing.DummyRequest.path方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.path方法的具体用法?Python DummyRequest.path怎么用?Python DummyRequest.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_login
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import path [as 别名]
def test_login(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.entry import Entry
request = DummyRequest()
request.user = None
entry = Entry(request)
request.path = "/for_test"
expected = {
"lang": "fr",
"came_from": "/for_test",
}
self.assertEqual(entry.loginform403(), expected)
request.params = {
"came_from": "/for_a_second_test",
}
entry = Entry(request)
expected = {
"lang": "fr",
"came_from": "/for_a_second_test",
}
self.assertEqual(entry.loginform(), expected)
entry = Entry(request)
request.params = {}
expected = {
"lang": "fr",
"came_from": "/",
}
self.assertEqual(entry.loginform(), expected)
示例2: test_login
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import path [as 别名]
def test_login(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.entry import Entry
request = DummyRequest()
request.user = None
entry = Entry(request)
request.path = "/for_test"
expected = {
"lang": "fr",
"came_from": "/for_test",
}
self.assertEqual(entry.loginform403(), expected)
request.params = {
"came_from": "/for_a_second_test",
}
entry = Entry(request)
expected = {
"lang": "fr",
"came_from": "/for_a_second_test",
}
self.assertEqual(entry.loginform(), expected)
entry = Entry(request)
request.params = {}
expected = {
"lang": "fr",
"came_from": "/",
}
self.assertEqual(entry.loginform(), expected)
request.registry.settings = {
"functionalities": {
"anonymous": {
"func": ["anon"],
"toto": "titi"
},
"registered": {
"func": ["reg"]
},
"available_in_templates": ["func"]
},
"admin_interface": {
"available_functionalities": ["func"]
}
}
entry = Entry(request)
expected = {
"functionalities": {
"func": ["anon"]
}
}
self.assertEqual(entry.loginuser(), expected)
class G:
id = 123
def __init__(self, name, functionalities):
self.name = name
self.functionalities = functionalities
class U:
username = "__test_user"
is_password_changed = True
def __init__(self, role="__test_role", functionalities=None):
if functionalities is None:
functionalities = []
self.role_name = role
self.role = G(role, functionalities)
request.user = U()
entry = Entry(request)
expected = {
"success": True,
"username": "__test_user",
"is_password_changed": True,
"role_name": "__test_role",
"role_id": 123,
"functionalities": {
"func": ["reg"]
}
}
self.assertEqual(entry.loginuser(), expected)
class F:
name = "func"
value = "user"
request.user = U("__test_role2", [F()])
entry = Entry(request)
expected = {
"success": True,
"username": "__test_user",
"is_password_changed": True,
"role_name": "__test_role2",
"role_id": 123,
"functionalities": {
#.........这里部分代码省略.........