• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python support.sample_environ函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.watson.framework.support.sample_environ函数的典型用法代码示例。如果您正苦于以下问题:Python sample_environ函数的具体用法?Python sample_environ怎么用?Python sample_environ使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_child_route_creation

    def test_child_route_creation(self):
        router = Router({
            'home': {
                'path': '/'
            },
            'parent': {
                'path': '/parent',
                'children': {
                    'child_one': {
                        'path': '/child_one',
                        'children': {
                            'sub_child': {
                                'path': '/test'
                            }
                        }
                    },
                    'child_two': {
                        'path': '/child_two'
                    }
                }
            }
        })
        assert len(router) == 5

        request = create_request_from_environ(sample_environ(PATH_INFO='/child_one'))
        matches = router.matches(request)
        assert len(matches) == 0

        request = create_request_from_environ(sample_environ(PATH_INFO='/parent/child_one'))
        matches = router.matches(request)
        assert len(matches) == 1

        assert router.assemble('parent/child_one/sub_child') == '/parent/child_one/test'
开发者ID:strogo,项目名称:watson-framework,代码行数:33,代码来源:test_routing.py


示例2: test_static_match

 def test_static_match(self):
     route = Route(name='home', path='/')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
开发者ID:strogo,项目名称:watson-framework,代码行数:8,代码来源:test_routing.py


示例3: test_accept_method_match

 def test_accept_method_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', REQUEST_METHOD='POST'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', REQUEST_METHOD='GET'))
     route = Route(name='test', path='/test', accepts=('POST',))
     assert route.match(valid_request)
     assert not route.match(invalid_request)
开发者ID:strogo,项目名称:watson-framework,代码行数:8,代码来源:test_routing.py


示例4: test_optional_segment_match

 def test_optional_segment_match(self):
     route = Route(name="search", path='/search[/:keyword]')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/searching'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
     assert route.match(valid_request_with_param)
开发者ID:strogo,项目名称:watson-framework,代码行数:11,代码来源:test_routing.py


示例5: test_mandatory_segment_match

 def test_mandatory_segment_match(self):
     route = Route("search", path='/search/:keyword')
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/searching'))
     valid_request_no_param = create_request_from_environ(
         sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert not route.match(valid_request_no_param)
     assert route.match(valid_request_with_param)
开发者ID:strogo,项目名称:watson-framework,代码行数:11,代码来源:test_routing.py


示例6: test_optional_segment_with_required

 def test_optional_segment_with_required(self):
     route = Route(
         name="search",
         path='/search[/:keyword]',
         requires={'keyword': 'blah'})
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search/blah'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     assert not route.match(invalid_request)
     assert route.match(valid_request)
开发者ID:strogo,项目名称:watson-framework,代码行数:11,代码来源:test_routing.py


示例7: test_requires_get_variables

    def test_requires_get_variables(self):
        route = Route(name='test', path='/', requires={'test': '.*'})
        request = create_request_from_environ(sample_environ(
            PATH_INFO='/',
            QUERY_STRING='test=blah&something=test'))
        match = route.match(request)
        assert match

        request = create_request_from_environ(sample_environ(
            PATH_INFO='/',
            QUERY_STRING='tesst=blah'))
        match = route.match(request)
        assert not match
开发者ID:strogo,项目名称:watson-framework,代码行数:13,代码来源:test_routing.py


示例8: test_subdomain_match

 def test_subdomain_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test',
                        SERVER_NAME='clients.test.com',
                        HTTP_HOST='clients.test.com'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/test', SERVER_NAME='clients2.test.com',
                        HTTP_HOST='clients2.test.com'))
     route = Route(name='test', path='/test', subdomain='clients')
     assert route.match(valid_request)
     assert not route.match(invalid_request)
     route_multiple_subdomains = Route(name='test', path='/test', subdomain=('clients', 'test'))
     assert route_multiple_subdomains.match(valid_request)
     assert not route_multiple_subdomains.match(invalid_request)
开发者ID:strogo,项目名称:watson-framework,代码行数:14,代码来源:test_routing.py


示例9: test_format_match

 def test_format_match(self):
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/dump',
                        HTTP_ACCEPT='application/json'))
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/dump', HTTP_ACCEPT='application/xml'))
     valid_request_segment = create_request_from_environ(
         sample_environ(PATH_INFO='/dump.json'))
     route = Route(name='json', path='/dump', requires={'format': 'json'})
     route_format = Route(
         name='json',
         path='/dump.:format',
         requires={'format': 'json'})
     assert route.match(valid_request)
     assert not route.match(invalid_request)
     assert route_format.match(valid_request_segment)
开发者ID:strogo,项目名称:watson-framework,代码行数:16,代码来源:test_routing.py


示例10: test_call

 def test_call(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'options': {
                     'controller': 'tests.watson.framework.support.TestController'
                 },
                 'requires': {
                     'format': 'json'
                 }
             }
         },
         'views': {
             'templates': {
                 'watson/mvc/test_applications/testcontroller/post': 'blank'
             }
         },
         'debug': {
             'enabled': True
         }
     })
     environ = sample_environ(PATH_INFO='/',
                              REQUEST_METHOD='POST',
                              HTTP_ACCEPT='application/json')
     response = application(environ, start_response)
     assert response == [b'{"content": "Posted Hello World!"}']
开发者ID:SabatierBoris,项目名称:watson-framework,代码行数:27,代码来源:test_applications.py


示例11: test_optional_segment_with_defaults

 def test_optional_segment_with_defaults(self):
     route = Route(
         name="search",
         path='/search[/:keyword]',
         defaults={'keyword': 'blah'})
     invalid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/searching'))
     valid_request = create_request_from_environ(
         sample_environ(PATH_INFO='/search'))
     valid_request_with_param = create_request_from_environ(
         sample_environ(PATH_INFO='/search/test'))
     valid_request_with_default = route.match(valid_request)
     assert not route.match(invalid_request)
     assert valid_request_with_default
     assert valid_request_with_default.params == {'keyword': 'blah'}
     assert route.match(valid_request_with_param)
开发者ID:strogo,项目名称:watson-framework,代码行数:16,代码来源:test_routing.py


示例12: test_forward_no_method

 def test_forward_no_method(self):
     controller = SampleActionController()
     controller.container = IocContainer()
     request = Request.from_environ(sample_environ())
     context = {'request': request}
     controller.event = types.Event('test', params={'context': context})
     controller.__action__ = 'do_method_forward'
     assert controller.do_method_forward() == 'Another Response'
开发者ID:BroukPytlik,项目名称:watson-framework,代码行数:8,代码来源:test_controllers.py


示例13: test_flash_message

 def test_flash_message(self):
     controller = SampleActionController()
     controller.request = Request.from_environ(sample_environ(), "watson.http.sessions.Memory")
     controller.flash_messages.add("testing")
     controller.flash_messages.add("something")
     assert controller.flash_messages["info"] == ["testing", "something"]
     for namespace, message in controller.flash_messages:
         assert namespace == "info"
     assert not controller.flash_messages.messages
开发者ID:B-Rich,项目名称:watson-framework,代码行数:9,代码来源:test_controllers.py


示例14: test_last_exception

 def test_last_exception(self):
     # occurs when exceptions have been raised from others
     environ = sample_environ()
     context = {
         'request': Request.from_environ(environ)
     }
     app = applications.Http()
     response, view_model = app.exception(
         last_exception=True, exception=Exception('test'), context=context)
     assert '<h1>Internal Server Error</h1>' in response.body
开发者ID:watsonpy,项目名称:watson-framework,代码行数:10,代码来源:test_applications.py


示例15: test_short_circuit

 def test_short_circuit(self):
     environ = sample_environ()
     route = LiteralRoute(
         "test", path="/", options={"controller": "tests.watson.framework.support.ShortCircuitedController"}
     )
     match = RouteMatch(route, {})
     context = {"request": Request.from_environ(environ), "route_match": match}
     event = Event("something", params={"container": IocContainer(), "context": context})
     listener = listeners.DispatchExecute({"404": "page/404"})
     response, view_model = listener(event)
     assert isinstance(response, Response)
开发者ID:BroukPytlik,项目名称:watson-framework,代码行数:11,代码来源:test_listeners.py


示例16: setup

 def setup(self):
     app = applications.Http()
     p = Request(
         {'enabled': True}, app.container.get('jinja2_renderer'), app)
     self.app = app
     self.panel = p
     params = {
         'context': {
             'request': messages.Request.from_environ(support.sample_environ())
         }
     }
     p.event = types.Event('test', params=params)
开发者ID:SabatierBoris,项目名称:watson-framework,代码行数:12,代码来源:test_request.py


示例17: test_overriden_template

 def test_overriden_template(self):
     environ = sample_environ()
     route = LiteralRoute(
         "test", path="/", options={"controller": "tests.watson.framework.support.SampleActionController"}
     )
     match = RouteMatch(route, {"action": "view_model_template"})
     context = {"request": Request.from_environ(environ), "route_match": match}
     event = Event("something", params={"container": IocContainer(), "context": context})
     listener = listeners.DispatchExecute({"404": "page/500"})
     response, view_model = listener(event)
     assert isinstance(view_model, views.Model)
     assert view_model.template == "sampleactioncontroller/404"
开发者ID:BroukPytlik,项目名称:watson-framework,代码行数:12,代码来源:test_listeners.py


示例18: test_raise_exception_event_server_error

 def test_raise_exception_event_server_error(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'options': {
                     'controller': 'tests.watson.framework.support.TestController'
                 }
             }
         }
     })
     response = application(sample_environ(PATH_INFO='/'), start_response)
     assert '<h1>Internal Server Error</h1>' in response[0].decode('utf-8')
开发者ID:SabatierBoris,项目名称:watson-framework,代码行数:13,代码来源:test_applications.py


示例19: test_short_circuit

 def test_short_circuit(self):
     environ = sample_environ()
     route = LiteralRoute(
         'test',
         path='/',
         options={'controller': 'tests.watson.framework.support.ShortCircuitedController'})
     match = RouteMatch(route, {})
     context = {'request': Request.from_environ(environ), 'route_match': match}
     event = Event(
         'something',
         params={'container': IocContainer(), 'context': context})
     listener = listeners.DispatchExecute({'404': 'page/404'})
     response, view_model = listener(event)
     assert isinstance(response, Response)
开发者ID:B-Rich,项目名称:watson-framework,代码行数:14,代码来源:test_listeners.py


示例20: test_post_redirect_get

 def test_post_redirect_get(self):
     base = controllers.HttpMixin()
     router = DictRouter({"test": {"path": "/test"}})
     environ = sample_environ(PATH_INFO="/", REQUEST_METHOD="POST")
     environ["wsgi.input"] = BufferedReader(BytesIO(b"post_var_one=test&post_var_two=blah"))
     base.request = Request.from_environ(environ, "watson.http.sessions.Memory")
     base.container = Mock()
     base.container.get.return_value = router
     response = base.redirect("test")
     assert response.status_code == 303
     assert base.redirect_vars == base.request.session["post_redirect_get"]
     base.clear_redirect_vars()
     assert not base.redirect_vars
     base.redirect("test", clear=True)
     assert not base.redirect_vars
开发者ID:B-Rich,项目名称:watson-framework,代码行数:15,代码来源:test_controllers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python support.sample_environ函数代码示例发布时间:2022-05-27
下一篇:
Python vim._with函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap