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

Python support.sample_environ函数代码示例

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

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



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

示例1: test_create_put_from_environ

 def test_create_put_from_environ(self):
     environ = sample_environ(REQUEST_METHOD='POST')
     environ['wsgi.input'] = BufferedReader(
         BytesIO(b'HTTP_REQUEST_METHOD=PUT'))
     request = create_request_from_environ(environ)
     assert request.post['HTTP_REQUEST_METHOD'] == 'PUT'
     assert request.is_method('PUT')
开发者ID:enigma,项目名称:watson,代码行数:7,代码来源:test_messages.py


示例2: test_get_form_vars_with_file

    def test_get_form_vars_with_file(self):
        environ = sample_environ(
                    REQUEST_METHOD='POST',
                    CONTENT_TYPE='multipart/form-data; boundary=---------------------------721837373350705526688164684',
                    CONTENT_LENGTH='558'
                )
        postdata = """-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="id"

1234
-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="title"


-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

Testing 123.

-----------------------------721837373350705526688164684
Content-Disposition: form-data; name="submit"

 Add\x20
-----------------------------721837373350705526688164684--
"""
        encoding = 'utf-8'
        fp = BytesIO(postdata.encode(encoding))
        environ['wsgi.input'] = fp
        get, post, files = get_form_vars(environ)
        file = files.get('file')
        assert file.filename == 'test.txt'
        assert post.get('id') == '1234'
开发者ID:erhuabushuo,项目名称:watson,代码行数:33,代码来源:test_wsgi.py


示例3: test_get_form_vars

 def test_get_form_vars(self):
     environ = sample_environ(
         QUERY_STRING='test=test',
         REQUEST_METHOD='PUT')
     get, post, files = get_form_vars(environ)
     assert get['test'] == 'test'
     assert environ['CONTENT_TYPE'] == 'application/x-www-form-urlencoded'
开发者ID:enigma,项目名称:watson,代码行数:7,代码来源:test_wsgi.py


示例4: test_is_secure

 def test_is_secure(self):
     environ = sample_environ(HTTPS='HTTPS')
     environ['wsgi.url_scheme'] = 'https'
     request = create_request_from_environ(environ)
     assert str(
         request) == 'GET https://127.0.0.1:80/ HTTP/1.1\r\nHost: 127.0.0.1\r\nHttps: HTTPS\r\n\r\n'
     assert request.is_secure()
开发者ID:enigma,项目名称:watson,代码行数:7,代码来源:test_messages.py


示例5: test_session_from_https_request

 def test_session_from_https_request(self):
     environ = sample_environ(HTTPS='HTTPS')
     request = create_request_from_environ(environ)
     assert request.is_secure()
     request.session_to_cookie()
     cookie = request.cookies[sessions.COOKIE_KEY]
     assert cookie['httponly']
     assert cookie['secure']
开发者ID:erhuabushuo,项目名称:watson,代码行数:8,代码来源:test_init.py


示例6: test_create_mutable

 def test_create_mutable(self):
     environ = sample_environ()
     environ['REQUEST_METHOD'] = 'POST'
     environ['wsgi.input'] = BufferedReader(BytesIO(b'HTTP_REQUEST_METHOD=PUT'))
     request = create_request_from_environ(environ)
     new_request = copy(request)
     assert isinstance(request.post, ImmutableMultiDict)
     assert isinstance(new_request.post, MultiDict)
开发者ID:erhuabushuo,项目名称:watson,代码行数:8,代码来源:test_messages.py


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


示例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_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


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


示例11: test_is_xml_http_request

 def test_is_xml_http_request(self):
     environ = sample_environ(HTTP_X_REQUESTED_WITH='XmlHttpRequest')
     request = Request.from_environ(environ)
     assert request.is_xml_http_request()
开发者ID:watsonpy,项目名称:watson-http,代码行数:4,代码来源:test_messages.py


示例12: test_host

 def test_host(self):
     environ = sample_environ(HTTP_X_FORWARDED_FOR='10.11.12.13')
     request = Request.from_environ(environ)
     assert request.host() == '10.11.12.13'
开发者ID:watsonpy,项目名称:watson-http,代码行数:4,代码来源:test_messages.py


示例13: test_url

 def test_url(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert request.url.path == '/'
开发者ID:watsonpy,项目名称:watson-http,代码行数:4,代码来源:test_messages.py


示例14: test_is_method

 def test_is_method(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert request.is_method('get')
开发者ID:watsonpy,项目名称:watson-http,代码行数:4,代码来源:test_messages.py


示例15: test_cookies

 def test_cookies(self):
     environ = sample_environ(HTTP_COOKIE='test=something;')
     request = Request.from_environ(environ)
     assert request.cookies['test'].value == 'something'
开发者ID:watsonpy,项目名称:watson-http,代码行数:4,代码来源:test_messages.py


示例16: test_get_vars

 def test_get_vars(self):
     environ = sample_environ(
         QUERY_STRING='blah=something&someget=test&arr[]=a&arr[]=b')
     request = create_request_from_environ(environ)
     assert request.get['blah'] == 'something'
开发者ID:enigma,项目名称:watson,代码行数:5,代码来源:test_messages.py


示例17: test_post

 def test_post(self):
     data = 'test=test'
     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['test'] == 'test'
开发者ID:watsonpy,项目名称:watson-http,代码行数:6,代码来源:test_messages.py


示例18: test_get_vars

 def test_get_vars(self):
     environ = sample_environ(
         QUERY_STRING='blah=something&someget=test&arr[]=a&arr[]=b')
     request = Request.from_environ(environ)
     assert len(request.get['arr[]']) == 2
     assert request.get['blah'] == 'something'
开发者ID:watsonpy,项目名称:watson-http,代码行数:6,代码来源:test_messages.py


示例19: test_create_from_environ

 def test_create_from_environ(self):
     environ = sample_environ()
     request = create_request_from_environ(environ)
     assert request.method == 'GET'
     assert request.is_method('GET')
开发者ID:enigma,项目名称:watson,代码行数:5,代码来源:test_messages.py


示例20: test_session

 def test_session(self):
     environ = sample_environ(HTTP_COOKIE='watson.session=123456;')
     request = Request.from_environ(environ,
                                    session_class='watson.http.sessions.Memory')
     assert request.session.id == '123456'
     assert isinstance(request.session, sessions.Memory)
开发者ID:watsonpy,项目名称:watson-http,代码行数:6,代码来源:test_messages.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python class_accounting.AccountingMethods类代码示例发布时间:2022-05-27
下一篇:
Python support.sample_environ函数代码示例发布时间: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