当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.path方法代码示例

本文整理汇总了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)
开发者ID:DavMerca007,项目名称:c2cgeoportal,代码行数:34,代码来源:test_entry.py

示例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": {
#.........这里部分代码省略.........
开发者ID:camptocamp,项目名称:c2cgeoportal,代码行数:103,代码来源:test_entry.py


注:本文中的pyramid.testing.DummyRequest.path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。