本文整理汇总了Python中pyramid.testing.DummyRequest.host方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.host方法的具体用法?Python DummyRequest.host怎么用?Python DummyRequest.host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.host方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_shortener
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener(self):
from pyramid.testing import DummyRequest
from pyramid.httpexceptions import HTTPNotFound, HTTPBadRequest
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "https://example.com/s/"
}
shortener = Shortener(request)
request.params = {}
request.matchdict = {
"ref": "AAAAAA"
}
self.assertRaises(HTTPNotFound, shortener.get)
request.params = {}
request.matchdict = {}
self.assertRaises(HTTPBadRequest, shortener.create)
request.params = {
"url": "https://other-site.com/hi"
}
self.assertRaises(HTTPBadRequest, shortener.create)
示例2: test_shortener_create_1
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener_create_1(self):
from pyramid.testing import DummyRequest
from pyramid.httpexceptions import HTTPFound
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "https://example.com/s/"
}
shortener = Shortener(request)
request.params = {
"url": "https://example.com/hi"
}
result = shortener.create()
index = result["short_url"].rfind("/")
self.assertEqual(
result["short_url"][:index],
"https://example.com/s"
)
request.params = {}
request.matchdict = {
"ref": result["short_url"][index + 1:]
}
result = shortener.get()
self.assertEqual(type(result), HTTPFound)
self.assertEqual(result.location, "https://example.com/hi")
示例3: test_shortener_baseurl
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener_baseurl(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "http://my_host/my_short/"
}
shortener = Shortener(request)
request.params = {
"url": "https://example.com/hi"
}
result = shortener.create()
index = result["short_url"].rfind("/")
self.assertEqual(
result["short_url"][:index],
"http://my_host/my_short"
)
示例4: test_shortener
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener(self):
from pyramid.testing import DummyRequest
from pyramid.httpexceptions import HTTPFound, HTTPNotFound, \
HTTPBadRequest
from c2cgeoportal.views.shortener import shortener
def route_url(name, *elements, **kw):
return 'https://example.com/s/' + kw['ref']
request = DummyRequest()
request.user = None
request.host = 'example.com:443'
request.server_name = 'example.com'
request.route_url = route_url
shortener = shortener(request)
request.params = {
'url': 'https://example.com/hi'
}
result = shortener.create()
index = result['short_url'].rfind('/')
self.assertEqual(
result['short_url'][:index],
'https://example.com/s'
)
request.params = {}
request.matchdict = {
'ref': result['short_url'][index + 1:]
}
result = shortener.get()
self.assertEqual(type(result), HTTPFound)
self.assertEqual(result.location, 'https://example.com/hi')
request.params = {}
request.matchdict = {
'ref': 'AAAAAA'
}
self.assertRaises(HTTPNotFound, shortener.get)
request.params = {
'url': 'https://example.com/short/truite'
}
result = shortener.create()
self.assertEqual(result['short_url'], 'https://example.com/s/truite')
request.params = {}
request.matchdict = {}
self.assertRaises(HTTPBadRequest, shortener.create)
request.params = {
'url': 'https://other-site.com/hi'
}
self.assertRaises(HTTPBadRequest, shortener.create)
示例5: test_shortener
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener(self):
from pyramid.testing import DummyRequest
from pyramid.httpexceptions import HTTPFound, HTTPNotFound, \
HTTPBadRequest
from c2cgeoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/s/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
shortener = Shortener(request)
request.params = {
"url": "https://example.com/hi"
}
result = shortener.create()
index = result["short_url"].rfind("/")
self.assertEqual(
result["short_url"][:index],
"https://example.com/s"
)
request.params = {}
request.matchdict = {
"ref": result["short_url"][index + 1:]
}
result = shortener.get()
self.assertEqual(type(result), HTTPFound)
self.assertEqual(result.location, "https://example.com/hi")
request.params = {}
request.matchdict = {
"ref": "AAAAAA"
}
self.assertRaises(HTTPNotFound, shortener.get)
request.params = {
"url": "https://example.com/short/truite"
}
result = shortener.create()
self.assertEqual(result["short_url"], "https://example.com/s/truite")
request.params = {}
request.matchdict = {}
self.assertRaises(HTTPBadRequest, shortener.create)
request.params = {
"url": "https://other-site.com/hi"
}
self.assertRaises(HTTPBadRequest, shortener.create)
示例6: test_shortener_baseurl
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener_baseurl(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.views.shortener import Shortener
request = DummyRequest()
request.user = None
request.host = 'example.com:443'
request.server_name = 'example.com'
request.registry.settings['shortener'] = {
'base_url': 'http://my_host/my_short/'
}
shortener = Shortener(request)
request.params = {
'url': 'https://example.com/hi'
}
result = shortener.create()
index = result['short_url'].rfind('/')
self.assertEqual(
result['short_url'][:index],
'http://my_host/my_short'
)
示例7: test_shortener_noreplace_2
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import host [as 别名]
def test_shortener_noreplace_2(self):
from pyramid.testing import DummyRequest
from c2cgeoportal_geoportal.views.shortener import Shortener
def route_url(name, *elements, **kw):
return "https://example.com/short/" + kw["ref"]
request = DummyRequest()
request.user = None
request.host = "example.com:443"
request.server_name = "example.com"
request.route_url = route_url
request.registry.settings["shortener"] = {
"base_url": "https://example.com/s/"
}
shortener = Shortener(request)
request.params = {
"url": "https://example.com/s/truite"
}
result = shortener.create()
self.assertEqual(result["short_url"], "https://example.com/s/truite")