예제 #1
0
 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()
예제 #2
0
 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')
예제 #3
0
    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'
예제 #4
0
파일: test_wsgi.py 프로젝트: enigma/watson
    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'
예제 #5
0
파일: test_wsgi.py 프로젝트: enigma/watson
 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'
예제 #6
0
 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')
예제 #7
0
 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)
예제 #8
0
 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')
예제 #9
0
 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']
예제 #10
0
 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)
예제 #11
0
 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']
예제 #12
0
 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)
예제 #13
0
 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
예제 #14
0
 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()
예제 #15
0
 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'
예제 #16
0
 def test_url(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert request.url.path == '/'
예제 #17
0
 def test_is_method(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert request.is_method('get')
예제 #18
0
 def test_session_from_request(self):
     environ = sample_environ(HTTP_COOKIE='watson.session=12345')
     request = create_request_from_environ(environ)
     assert isinstance(request.session, sessions.File)
     assert isinstance(request, sessions.SessionMixin)
예제 #19
0
 def test_create_from_environ(self):
     environ = sample_environ()
     request = create_request_from_environ(environ)
     assert request.method == 'GET'
     assert request.is_method('GET')
예제 #20
0
 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'
예제 #21
0
 def test_cookies(self):
     environ = sample_environ(HTTP_COOKIE='test=something;')
     request = create_request_from_environ(environ)
     assert request.cookies['test'].value == 'something'
예제 #22
0
 def test_host(self):
     environ = sample_environ(HTTP_X_FORWARDED_FOR='10.11.12.13')
     request = create_request_from_environ(environ)
     assert request.host() == '10.11.12.13'
예제 #23
0
 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'
예제 #24
0
 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)
예제 #25
0
 def test_body(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     request.body = 'Test'
     assert request.raw_body == b'Test'
     assert request.body == 'Test'
예제 #26
0
 def test_is_secure(self):
     environ = sample_environ(HTTPS='HTTPS')
     request = Request.from_environ(environ)
     assert request.is_secure()
     request = Request.from_environ({'PATH_INFO': '/', 'wsgi.url_scheme': 'https', 'HTTP_HOST': '127.0.0.1'})
     assert request.is_secure()
예제 #27
0
 def test_no_post(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert not request.post
예제 #28
0
 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'
예제 #29
0
파일: test_wsgi.py 프로젝트: enigma/watson
 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'
예제 #30
0
 def test_create_from_environ(self):
     environ = sample_environ()
     request = create_request_from_environ(environ)
     assert request.method == 'GET'
     assert request.is_method('GET')
예제 #31
0
 def test_cookies(self):
     environ = sample_environ(HTTP_COOKIE='test=something;')
     request = Request.from_environ(environ)
     assert request.cookies['test'].value == 'something'
예제 #32
0
 def test_repr(self):
     environ = sample_environ()
     assert repr(create_request_from_environ(environ)
                 ) == '<watson.http.messages.Request method:GET url:http://127.0.0.1/>'
예제 #33
0
 def test_is_xml_http_request(self):
     environ = sample_environ(HTTP_X_REQUESTED_WITH='XmlHttpRequest')
     request = create_request_from_environ(environ)
     assert request.is_xml_http_request()
예제 #34
0
 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'
예제 #35
0
 def test_server(self):
     environ = sample_environ()
     request = create_request_from_environ(environ)
     assert request.server['PATH_INFO'] == '/'
예제 #36
0
 def test_headers(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert len(request.headers) == 1
예제 #37
0
 def test_session(self):
     environ = sample_environ(HTTP_COOKIE='watson.session=123456;')
     request = create_request_from_environ(environ,
                                           'watson.http.sessions.Memory')
     assert request.session.id == '123456'
     assert isinstance(request.session, sessions.Memory)
예제 #38
0
 def test_server(self):
     environ = sample_environ()
     request = Request.from_environ(environ)
     assert request.server['PATH_INFO'] == '/'
예제 #39
0
 def test_repr(self):
     environ = sample_environ()
     assert repr(
         create_request_from_environ(environ)
     ) == '<watson.http.messages.Request method:GET url:http://127.0.0.1/>'
예제 #40
0
 def test_multiple_requests(self):
     request1 = messages.Request.from_environ(support.sample_environ(), 'watson.http.sessions.Memory')
     request1.session['testing'] = 'test'
     request2 = messages.Request.from_environ(support.sample_environ(), 'watson.http.sessions.Memory')
     request2.session['testing'] = 'test'
     assert request1.session.id != request2.session.id