本文整理汇总了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")
示例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")
示例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())
示例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))
示例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")
示例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)
示例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))
示例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"))