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

Python messages.Request类代码示例

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

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



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

示例1: 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


示例2: test_create_put_from_environ

 def test_create_put_from_environ(self):
     data = 'HTTP_REQUEST_METHOD=PUT'
     environ = sample_environ(REQUEST_METHOD='POST', CONTENT_LENGTH=len(data))
     environ['wsgi.input'] = BufferedReader(BytesIO(data.encode('utf-8')))
     request = Request.from_environ(environ)
     assert request.post['HTTP_REQUEST_METHOD'] == 'PUT'
     assert not request.files
     assert request.is_method('PUT')
开发者ID:watsonpy,项目名称:watson-http,代码行数:8,代码来源:test_messages.py


示例3: setup

 def setup(self):
     self.protected_form = has_csrf(UnprotectedForm)
     data = 'test=blah'
     environ = sample_environ(REQUEST_METHOD='POST')
     environ['wsgi.input'] = BufferedReader(BytesIO(data.encode('utf-8')))
     environ['CONTENT_LENGTH'] = len(data)
     self.request = Request.from_environ(
         environ, 'watson.http.sessions.Memory')
开发者ID:B-Rich,项目名称:watson-form,代码行数:8,代码来源:test_decorators.py


示例4: create_event

 def create_event(self, **kwargs):
     router = DictRouter({"home": {"path": "/"}})
     environ = {}
     util.setup_testing_defaults(environ)
     environ.update(**kwargs)
     context = {"request": Request.from_environ(environ)}
     event = Event("TestEvent", params={"router": router, "context": context})
     return event
开发者ID:BroukPytlik,项目名称:watson-framework,代码行数:8,代码来源:test_listeners.py


示例5: 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:BroukPytlik,项目名称:watson-framework,代码行数:9,代码来源:test_controllers.py


示例6: test_invalid_form

 def test_invalid_form(self):
     post_data = 'username=simon'
     environ = sample_environ(REQUEST_METHOD='POST',
                              CONTENT_LENGTH=len(post_data))
     environ['wsgi.input'] = BufferedReader(
         BytesIO(post_data.encode('utf-8')))
     self.controller.request = Request.from_environ(environ, 'watson.http.sessions.Memory')
     self.controller.login_action()
     assert len(self.controller.flash_messages) == 1
开发者ID:B-Rich,项目名称:watson-auth,代码行数:9,代码来源:test_decorators.py


示例7: test_invalid_user

 def test_invalid_user(self):
     post_data = 'username=simon&password=test'
     environ = sample_environ(REQUEST_METHOD='POST',
                              CONTENT_LENGTH=len(post_data))
     environ['wsgi.input'] = BufferedReader(
         BytesIO(post_data.encode('utf-8')))
     self.controller.request = Request.from_environ(environ, 'watson.http.sessions.Memory')
     response = self.controller.login_action()
     assert response.headers['location'] == '/login'
开发者ID:B-Rich,项目名称:watson-auth,代码行数:9,代码来源:test_decorators.py


示例8: test_session_from_https_request

 def test_session_from_https_request(self):
     environ = sample_environ(HTTPS='HTTPS')
     request = Request.from_environ(environ,
                                    session_class='watson.http.sessions.Memory')
     assert request.is_secure()
     request.session['arbitrary'] = 'value'
     sessions.session_to_cookie(request, Response())
     cookie = request.cookies[sessions.COOKIE_KEY]
     assert cookie['httponly']
     assert cookie['secure']
开发者ID:watsonpy,项目名称:watson-http,代码行数:10,代码来源:test_messages.py


示例9: 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


示例10: setup

 def setup(self):
     post_data = 'username=admin&password=test'
     environ = sample_environ(REQUEST_METHOD='POST',
                              CONTENT_LENGTH=len(post_data))
     environ['wsgi.input'] = BufferedReader(
         BytesIO(post_data.encode('utf-8')))
     self.controller = support.app.container.get(
         'tests.watson.auth.test_decorators.SampleController')
     self.controller.request = Request.from_environ(environ, 'watson.http.sessions.Memory')
     self.controller.login_action()
开发者ID:B-Rich,项目名称:watson-auth,代码行数:10,代码来源:test_decorators.py


示例11: setup

 def setup(self):
     data = 'form_csrf_token=123456&test=blah'
     environ = sample_environ(
         HTTP_COOKIE='watson.session=123456;',
         REQUEST_METHOD='POST',
         CONTENT_LENGTH=len(data))
     environ['wsgi.input'] = BufferedReader(
         BytesIO(data.encode('utf-8')))
     self.request = Request.from_environ(
         environ, 'watson.http.sessions.Memory')
开发者ID:B-Rich,项目名称:watson-form,代码行数:10,代码来源:test_forms.py


示例12: test_create

 def test_create(self):
     data = 'test'
     environ = sample_environ(CONTENT_LENGTH=len(data))
     environ['wsgi.input'] = BufferedReader(BytesIO(data.encode('utf-8')))
     request = Request.from_environ(environ)
     assert request.method == 'GET'
     assert not request.is_method('PUT', 'PATCH')
     assert repr(request) == '<watson.http.messages.Request method:GET url:http://127.0.0.1/>'
     assert 'Content-Length: 4' in str(request)
     assert "\r\n\r\ntest" in str(request)
开发者ID:watsonpy,项目名称:watson-http,代码行数:10,代码来源:test_messages.py


示例13: 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


示例14: create_event

 def create_event(self, **kwargs):
     router = DictRouter({'home': {'path': '/'}})
     environ = {}
     util.setup_testing_defaults(environ)
     environ.update(**kwargs)
     context = {'request': Request.from_environ(environ)}
     event = Event(
         'TestEvent',
         params={'router': router,
                 'context': context})
     return event
开发者ID:B-Rich,项目名称:watson-framework,代码行数:11,代码来源:test_listeners.py


示例15: test_json_body

 def test_json_body(self):
     json_str = '{"test": [1, 2, 3]}'
     environ = sample_environ(CONTENT_TYPE='application/json; charset=utf-8',
                              CONTENT_LENGTH=len(json_str),
                              REQUEST_METHOD='put')
     environ['wsgi.input'] = BufferedReader(
         BytesIO(json_str.encode('utf-8')))
     request = Request.from_environ(environ)
     json_output = json.loads(request.body)
     assert 'test' in json_output
     assert 'test' in request.json_body
开发者ID:watsonpy,项目名称:watson-http,代码行数:11,代码来源:test_messages.py


示例16: test_multiple_values

 def test_multiple_values(self):
     form = MultipleForm('test')
     data = 'checkbox[]=1&checkbox[]=2'
     environ = sample_environ(
         REQUEST_METHOD='POST',
         CONTENT_LENGTH=len(data))
     environ['wsgi.input'] = BufferedReader(
         BytesIO(data.encode('utf-8')))
     request = Request.from_environ(
         environ, 'watson.http.sessions.Memory')
     form.data = request
     assert form.test == ['1', '2']
开发者ID:watsonpy,项目名称:watson-form,代码行数:12,代码来源:test_forms.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: run

 def run(self, environ, start_response):
     session = self.config['session']
     request = Request.from_environ(environ,
                                    session_class=session.get(
                                        'class', None),
                                    session_options=session.get(
                                        'options', None))
     try:
         response = self.__run_inner(request)
     except Exception as exc:
         response, view_model = self.exception(
             exception=exc, context={'request': request})
     return response(start_response)
开发者ID:watsonpy,项目名称:watson-framework,代码行数:13,代码来源: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_set_data_on_form

 def test_set_data_on_form(self):
     form = LoginForm('test')
     post_data = {
         'username': 'simon',
         'password': 'test',
         'first_name': None,
         'last_name': None,
         'email': None}
     form.data = post_data
     assert form.data == post_data
     environ = environ_with_file()
     request = Request.from_environ(environ)
     form.data = request
     assert form.data['first_name'] == '1234'
开发者ID:B-Rich,项目名称:watson-form,代码行数:14,代码来源:test_forms.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python models.has_int_pk函数代码示例发布时间:2022-05-26
下一篇:
Python messages.create_request_from_environ函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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