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


Python DummyRequest.environ["HTTP_HOST"]方法代码示例

本文整理汇总了Python中pyramid.testing.DummyRequest.environ["HTTP_HOST"]方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.environ["HTTP_HOST"]方法的具体用法?Python DummyRequest.environ["HTTP_HOST"]怎么用?Python DummyRequest.environ["HTTP_HOST"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.testing.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.environ["HTTP_HOST"]方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_login

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_login(self):
        from ptahcrowd import login
        from ptahcrowd.provider import CrowdUser

        user = CrowdUser(name="name", login="login", email="email", password="{plain}12345")
        CrowdUser.__type__.add(user)

        uri = user.__uri__

        request = DummyRequest()

        form = login.LoginForm(None, request)
        form.update()
        data, errors = form.extract()
        self.assertEqual(len(errors), 2)

        form.login_handler()
        self.assertIn("Please fix indicated errors.", ptah.render_messages(request))

        request = DummyRequest(POST={"login": "login", "password": "12345"})
        request.environ["HTTP_HOST"] = "example.com"

        form = login.LoginForm(None, request)
        form.update()
        res = form.login_handler()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers["location"], "http://example.com/login-success.html")
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:30,代码来源:test_login.py

示例2: test_login_success_anon

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_login_success_anon(self):
        from ptahcrowd import login

        request = DummyRequest()
        request.environ["HTTP_HOST"] = "example.com"

        res = self.render_route_view(None, request, "ptah-login-success")

        self.assertEqual(res.headers["location"], "http://example.com/login.html")
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:11,代码来源:test_login.py

示例3: test_logout

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_logout(self):
        from ptahcrowd import login
        from ptahcrowd.provider import CrowdUser

        user = CrowdUser(name="name", login="login", email="email", password="{plain}12345")
        CrowdUser.__type__.add(user)

        uri = user.__uri__

        request = DummyRequest()
        request.environ["HTTP_HOST"] = "example.com"
        ptah.auth_service.set_userid(uri)

        res = login.logout(request)
        self.assertIsInstance(res, HTTPFound)
        self.assertIsNone(ptah.auth_service.get_userid())
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:18,代码来源:test_login.py

示例4: test_login_wrong_login

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_login_wrong_login(self):
        from ptahcrowd import login
        from ptahcrowd.provider import CrowdUser

        user = CrowdUser(name="name", login="login", email="email", password="{plain}12345")
        CrowdUser.__type__.add(user)

        uri = user.__uri__

        request = DummyRequest(POST={"login": "login1", "password": "123456"})
        request.environ["HTTP_HOST"] = "example.com"

        form = login.LoginForm(None, request)
        form.update()
        form.login_handler()

        self.assertIn("You have entered the wrong login or password.", ptah.render_messages(request))
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:19,代码来源:test_login.py

示例5: test_login_suspended

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_login_suspended(self):
        from ptahcrowd import login
        from ptahcrowd.provider import CrowdUser

        user = CrowdUser(name="name", login="login", email="email", password="{plain}12345")
        CrowdUser.__type__.add(user)

        uri = user.__uri__
        user.suspended = True

        request = DummyRequest(POST={"login": "login", "password": "12345"})
        request.environ["HTTP_HOST"] = "example.com"

        form = login.LoginForm(None, request)
        form.update()
        res = form.login_handler()

        self.assertEqual(res.headers["location"], "http://example.com/login-suspended.html")
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:20,代码来源:test_login.py

示例6: test_resetpassword_form_change_errors

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_resetpassword_form_change_errors(self):
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.resetpassword import ResetPasswordForm

        user = CrowdUser(name="name", login="login", email="email")
        CrowdUser.__type__.add(user)

        passcode = ptah.pwd_tool.generate_passcode(user)

        request = DummyRequest(
            subpath=(passcode,),
            POST={"password": "12345", "confirm_password": "123456", "form.buttons.change": "Change"},
        )
        request.environ["HTTP_HOST"] = "example.com"

        form = ResetPasswordForm(None, request)
        form.update()

        msg = ptah.render_messages(request)
        self.assertIn("Please fix indicated errors.", msg)
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:22,代码来源:test_resetpassword.py

示例7: test_login_unvalidated

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_login_unvalidated(self):
        from ptahcrowd import login
        from ptahcrowd.provider import CrowdUser

        user = CrowdUser(name="name", login="login", email="email", password="{plain}12345")
        CrowdUser.__type__.add(user)

        uri = user.__uri__
        user.validated = False

        cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD)
        cfg["allow-unvalidated"] = False

        request = DummyRequest(POST={"login": "login", "password": "12345"})
        request.environ["HTTP_HOST"] = "example.com"

        form = login.LoginForm(None, request)
        form.update()
        form.login_handler()

        self.assertIn("Account is not validated.", ptah.render_messages(request))
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:23,代码来源:test_login.py

示例8: test_resetpassword_form_change

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import environ["HTTP_HOST"] [as 别名]
    def test_resetpassword_form_change(self):
        from ptahcrowd.provider import CrowdUser
        from ptahcrowd.resetpassword import ResetPasswordForm

        user = CrowdUser(name="name", login="login", email="email")
        CrowdUser.__type__.add(user)

        passcode = ptah.pwd_tool.generate_passcode(user)

        request = DummyRequest(
            subpath=(passcode,),
            POST={"password": "123456", "confirm_password": "123456", "form.buttons.change": "Change"},
        )
        request.environ["HTTP_HOST"] = "example.com"

        form = ResetPasswordForm(None, request)
        res = form.update()

        msg = ptah.render_messages(request)
        self.assertIn("You have successfully changed your password.", msg)
        self.assertEqual(res.headers["location"], "http://example.com")
        self.assertTrue(ptah.pwd_tool.check(user.password, "123456"))
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:24,代码来源:test_resetpassword.py


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