Exemplo n.º 1
0
 def test_get_cookie_with_secret(self):
     request = Request({
         'HTTP_COOKIE':
         'foo="!VzhGFLGcW+5OMs1s4beLXaqFxAUwgHdWkH5fgapghoI='
         '?gASVDwAAAAAAAACMA2Zvb5SMA2JhcpSGlC4="'
     })
     actual = request.get_cookie("foo", secret='secretkey')
     expected = 'bar'
     self.assertEqual(actual, expected)
Exemplo n.º 2
0
 def test_GET_a_parameter(self):
     request = Request({
         'REQUEST_METHOD': 'GET',
         'QUERY_STRING': 'key1=value1',
         'CONTENT_TYPE': 'text/plain',
         'CONTENT_LENGTH': '',
     })
     self.assertEqual(request.query['key1'], 'value1')
Exemplo n.º 3
0
 def test_url(self):
     request = Request({
         'HTTP_X_FORWARDED_PROTO': 'http',
         'QUERY_STRING': 'key1=value1&key2=value2',
         'HTTP_X_FORWARDED_HOST': 'localhost',
         'PATH_INFO': '/hoge',
     })
     actual = request.url
     self.assertEqual(actual,
                      "http://localhost/hoge?key1=value1&key2=value2")
Exemplo n.º 4
0
 def test_raw_body(self):
     wsgi_input_mock = MagicMock()
     wsgi_input_mock.read.return_value = b'{"key1": "value1"}'
     request = Request({
         'REQUEST_METHOD': 'POST',
         'QUERY_STRING': '',
         'wsgi.input': wsgi_input_mock,
         'CONTENT_TYPE': 'application/json',
         'CONTENT_LENGTH': len(b'{"key1": "value1"}'),
     })
     self.assertEqual(request.raw_body, b'{"key1": "value1"}')
Exemplo n.º 5
0
 def test_raw_body_with_empty_string_content_length(self):
     wsgi_input_mock = MagicMock()
     wsgi_input_mock.read.return_value = b''
     request = Request({
         'REQUEST_METHOD': 'POST',
         'QUERY_STRING': '',
         'wsgi.input': wsgi_input_mock,
         'CONTENT_TYPE': 'text/plain',
         'CONTENT_LENGTH': '',
     })
     self.assertEqual(request.raw_body, b'')
Exemplo n.º 6
0
    def test_POST_a_parameter(self):
        wsgi_input_mock = MagicMock()
        wsgi_input_mock.read.return_value = b'key1=value1'

        request = Request({
            'REQUEST_METHOD': 'POST',
            'QUERY_STRING': '',
            'wsgi.input': wsgi_input_mock,
            'CONTENT_TYPE': 'application/x-www-form-urlencoded',
            'CONTENT_LENGTH': len(b'key1=value1'),
        })

        self.assertEqual(request.forms['key1'], 'value1')
Exemplo n.º 7
0
 def test_get_cookie(self):
     request = Request({'HTTP_COOKIE': 'foo="bar"'})
     actual = request.get_cookie("foo")
     expected = 'bar'
     self.assertEqual(actual, expected)
Exemplo n.º 8
0
 def test_initialized(self):
     env = {'hoge': 'HOGE'}
     request = Request(env)
     self.assertEqual(request['hoge'], 'HOGE')
Exemplo n.º 9
0
 def test_path_property_stripped_last_slash(self):
     request = Request({'PATH_INFO': 'hoge'})
     self.assertEqual(request.path, '/hoge')
Exemplo n.º 10
0
 def test_method_name_to_uppercase(self):
     self.assertEqual(Request({'REQUEST_METHOD': 'get'}).method, 'GET')
     self.assertEqual(Request({'REQUEST_METHOD': 'Post'}).method, 'POST')
Exemplo n.º 11
0
 def test_get_default_value(self):
     request = Request({})
     self.assertEqual(request.get('hoge', 'HOGE'), 'HOGE')
Exemplo n.º 12
0
 def test_path_property(self):
     request = Request({'PATH_INFO': '/hoge'})
     self.assertEqual(request.path, '/hoge')
Exemplo n.º 13
0
 def test_headers(self):
     request = Request({'HTTP_FOO': 'Bar', 'QUERY_STRING': 'key1=value1'})
     self.assertEqual(request.headers['FOO'], 'Bar')
Exemplo n.º 14
0
 def test_get(self):
     request = Request({'hoge': 'HOGE'})
     self.assertEqual(request.get('hoge'), 'HOGE')
Exemplo n.º 15
0
 def test_cookies_property_has_an_item(self):
     request = Request({'HTTP_COOKIE': 'foo="bar"'})
     self.assertEqual(len(request.cookies), 1)
Exemplo n.º 16
0
 def test_getitem(self):
     request = Request({'hoge': 'HOGE'})
     self.assertEqual(request['hoge'], 'HOGE')
Exemplo n.º 17
0
 def test_cookies_property_has_nothing(self):
     request = Request({})
     self.assertEqual(len(request.cookies), 0)