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


Python DummyRequest.host方法代码示例

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

示例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")
开发者ID:camptocamp,项目名称:c2cgeoportal,代码行数:37,代码来源:test_shortener.py

示例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"
        )
开发者ID:camptocamp,项目名称:c2cgeoportal,代码行数:28,代码来源:test_shortener.py

示例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)
开发者ID:CDTRH,项目名称:c2cgeoportal,代码行数:56,代码来源:test_shortener.py

示例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)
开发者ID:DavMerca007,项目名称:c2cgeoportal,代码行数:56,代码来源:test_shortener.py

示例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'
        )
开发者ID:kailIII,项目名称:c2cgeoportal,代码行数:24,代码来源:test_shortener.py

示例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")
开发者ID:yjacolin,项目名称:c2cgeoportal,代码行数:24,代码来源:test_shortener.py


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