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


Python DummyRequest.matched_route方法代码示例

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


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

示例1: test_subscriber_predicate

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
def test_subscriber_predicate(settings):
    """Test that the ``asset_request`` subscriber predicate.

    It should correctly match asset requests when its value is ``True``,
    and other requests when ``False``.
    """
    mock1 = Mock()
    mock2 = Mock()

    with testConfig(settings=settings) as config:
        config.include(assets)
        config.add_subscriber(mock1, DummyEvent, asset_request=False)
        config.add_subscriber(mock2, DummyEvent, asset_request=True)

        request1 = DummyRequest('/')
        request1.matched_route = None

        pattern = config.get_webassets_env().url + '*subpath'
        request2 = DummyRequest(config.get_webassets_env().url + '/t.png')
        request2.matched_route = Route('__' + pattern, pattern)

        event1 = DummyEvent(request1)
        event2 = DummyEvent(request2)

        config.registry.notify(event1)
        config.registry.notify(event2)

        mock1.assert_called_onceventwith(event1)
        mock2.assert_called_onceventwith(event2)
开发者ID:Forethinker,项目名称:h,代码行数:31,代码来源:assets_test.py

示例2: test_is_pagination_route

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
    def test_is_pagination_route(self):
        request = DummyRequest()
        request.registry.pagination = {
            'some_route': {}
        }
        request.matched_route = RouteMock('some_route')
        self.assertTrue(is_pagination_route(request))

        request.matched_route = RouteMock('some_other_route')
        self.assertFalse(is_pagination_route(request))
开发者ID:C3S,项目名称:c3sMembership,代码行数:12,代码来源:test_init.py

示例3: test_call

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
    def test_call(self):
        config = testing.setUp()
        config.add_route('some_route', '/')

        pagination_request_writer = PaginationRequestWriterMock()
        param_property_naming = PropertyNamingMock(
            'page-number',
            'page-size',
            'sort-property',
            'sort-direction')
        url_creator_factory = UrlCreatorFactoryMock('http://example.com')
        request = DummyRequest()
        request.registry.pagination = {
            'some_route': {
                'pagination_request_writer': pagination_request_writer,
                'param_property_naming': param_property_naming,
                'url_creator_factory': url_creator_factory,
            }
        }
        request.pagination = Pagination(
            Paging(
                100,
                PagingRequest(3, 12)),
            Sorting('some_property', 'desc'))
        request.matched_route = RouteMock('some_route')
        event = BeforeRenderEventMock()
        event['request'] = request
        subscriber = PaginationBeforeRenderSubscriber()
        subscriber(event)
        self.assertEqual(pagination_request_writer.call_count, 1)

        pagination = event.rendering_val['pagination']
        self.assertEqual('http://example.com', str(pagination.url))
开发者ID:C3S,项目名称:c3sMembership,代码行数:35,代码来源:test_init.py

示例4: test_mapped_values_request

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
def test_mapped_values_request() -> None:
    """Test that values are correctly mapped from pyramid's Request."""

    pyramid_request = DummyRequest(path="/foo")
    pyramid_request.matched_route = DummyRoute(name="foo", pattern="/foo")
    pyramid_request.matchdict["foo"] = "bar"
    pyramid_request.headers["X-Foo"] = "Bar"
    pyramid_request.cookies["tasty-foo"] = "tasty-bar"
    pyramid_request.content_type = "text/html"

    assert pyramid_request.host_url == "http://example.com"
    assert pyramid_request.path == "/foo"
    assert pyramid_request.method == "GET"

    openapi_request = PyramidOpenAPIRequest(pyramid_request)

    assert openapi_request.request == pyramid_request
    assert openapi_request.host_url == "http://example.com"
    assert openapi_request.path == "/foo"
    assert openapi_request.method == "get"
    assert openapi_request.path_pattern == "/foo"
    assert openapi_request.body == ""
    assert openapi_request.mimetype == "text/html"
    assert openapi_request.parameters == {
        "cookies": {"tasty-foo": "tasty-bar"},
        "headers": {"X-Foo": "Bar"},
        "path": {"foo": "bar"},
        "query": {},
    }
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:31,代码来源:test_wrappers.py

示例5: test_call_exception

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
    def test_call_exception(self):

        class ExceptionPaginationReader(object):
            # pylint: disable=too-few-public-methods

            def __init__(self, exception):
                self._exception = exception

            def __call__(self, request, content_size_provider):
                raise self._exception


        content_size_provider_mock = ContentSizeProviderMock(100)

        request = DummyRequest()
        request.registry.pagination = {
            'some_route': {
                'content_size_provider': content_size_provider_mock,
                'pagination_reader': ExceptionPaginationReader(
                    PageNotFoundException()),
            }
        }
        request.matched_route = RouteMock('some_route')

        event = ContextFoundEventMock(request)
        subscriber = PaginationContextFoundSubscriber()
        with self.assertRaises(ParameterValidationException):
            subscriber(event)
开发者ID:C3S,项目名称:c3sMembership,代码行数:30,代码来源:test_init.py

示例6: test_no_matched_route

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
def test_no_matched_route() -> None:
    """Test path_pattern when no route is matched."""
    pyramid_request = DummyRequest(path="/foo")
    pyramid_request.matched_route = None

    openapi_request = PyramidOpenAPIRequest(pyramid_request)
    assert openapi_request.path_pattern == "/foo"
开发者ID:Pylons,项目名称:pyramid_openapi3,代码行数:9,代码来源:test_wrappers.py

示例7: test_get_breadcrumbs_1

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
 def test_get_breadcrumbs_1(self):
     """No layout, no breadcrumbs"""
     request = DummyRequest()
     request.matched_route = MatchedRoute()
     request.matched_route.name = 'p1_homepage'
     p = page.Page(request)
     self.failUnless(p.get_breadcrumbs(request) == None)
开发者ID:rna-seq,项目名称:raisin.restyler,代码行数:9,代码来源:test_page.py

示例8: test_page

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
    def test_page(self):
        request = DummyRequest()

        class DummyRoute(object):
            name = 'p1_homepage'
        route = DummyRoute()
        request.matched_route = route
        page.Page(request)
开发者ID:rna-seq,项目名称:raisin.restyler,代码行数:10,代码来源:test_page.py

示例9: _makeDummyRequest

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
    def _makeDummyRequest(self, request_data=None):
        from pyramid.testing import DummyRequest
        request = DummyRequest()
        request.matched_route = DummyRoute('JSON-RPC')
        if request_data is not None:
            request.body = json.dumps(request_data)
            request.content_length = len(request.body)

        return request
开发者ID:kabhinav,项目名称:pyramid_rpc,代码行数:11,代码来源:test_jsonrpc.py

示例10: test_get_breadcrumbs_2

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
 def test_get_breadcrumbs_2(self):
     request = DummyRequest()
     request.matched_route = MatchedRoute()
     request.matched_route.name = 'p1_project'
     request.matchdict = {'project_name': 'ENCODE'}
     p = page.Page(request)
     breadcrumbs = [{'url': 'http://example.com/',
                     'title': 'Projects'}]
     self.failUnless(p.get_breadcrumbs(request) == breadcrumbs)
开发者ID:rna-seq,项目名称:raisin.restyler,代码行数:11,代码来源:test_page.py

示例11: test_get_breadcrumbs_3

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
 def test_get_breadcrumbs_3(self):
     request = DummyRequest()
     request.matched_route = MatchedRoute()
     request.matched_route.name = 'p1_replicate'
     request.matchdict = {'project_name': 'ENCODE',
                          'replicate_name': 'Ging001N',
                          'parameter_list': None,
                          'parameter_values': None,
                          'tab_name': None}
     p = page.Page(request)
     bcr = [{'url': 'http://example.com/',
             'title': 'Projects'},
            {'url': 'http://example.com/project/ENCODE',
             'title': 'Project: ENCODE'},
            {'url': 'http://example.com/project/ENCODE/None/None',
             'title': 'Experiment: None'}]
     print p.get_breadcrumbs(request)
     self.failUnless(p.get_breadcrumbs(request) == bcr, p.get_breadcrumbs(request))
开发者ID:rna-seq,项目名称:raisin.restyler,代码行数:20,代码来源:test_page.py

示例12: test_call

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import matched_route [as 别名]
    def test_call(self):
        pagination_reader = PaginationReaderMock('some pagination')
        content_size_provider_mock = ContentSizeProviderMock(100)

        request = DummyRequest()
        request.registry.pagination = {
            'some_route': {
                'content_size_provider': content_size_provider_mock,
                'pagination_reader': pagination_reader,
            }
        }
        request.matched_route = RouteMock('some_route')

        event = ContextFoundEventMock(request)
        subscriber = PaginationContextFoundSubscriber()
        subscriber(event)
        self.assertEqual(request.pagination, 'some pagination')
        self.assertEqual(pagination_reader.call_count, 1)
        self.assertEqual(content_size_provider_mock.call_count, 1)
开发者ID:,项目名称:,代码行数:21,代码来源:


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