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


Python support.sample_environ函数代码示例

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


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


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