def test_url_request_descriptors_hosts(self): req = Request.from_values( '/bar?foo=baz', 'http://example.com/test' ) req.trusted_hosts = ['example.com'] self.assertEqual(req.path, u'/bar') self.assertEqual(req.full_path, u'/bar?foo=baz') self.assertEqual(req.script_root, u'/test') self.assertEqual(req.url, u'http://example.com/test/bar?foo=baz') self.assertEqual(req.base_url, u'http://example.com/test/bar') self.assertEqual(req.url_root, u'http://example.com/test/') self.assertEqual(req.host_url, u'http://example.com/') self.assertEqual(req.host, 'example.com') self.assertEqual(req.scheme, 'http') req = Request.from_values( '/bar?foo=baz', 'https://example.com/test' ) self.assertEqual(req.scheme, 'https') req = Request.from_values( '/bar?foo=baz', 'http://example.com/test' ) req.trusted_hosts = ['example.org'] self.assertRaises(SecurityError, lambda: req.url) self.assertRaises(SecurityError, lambda: req.base_url) self.assertRaises(SecurityError, lambda: req.url_root) self.assertRaises(SecurityError, lambda: req.host_url) self.assertRaises(SecurityError, lambda: req.host)
def test_user_agent_mixin(self): user_agents = [ ('Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) ' 'Gecko/20071127 Firefox/2.0.0.11', 'firefox', 'macos', '2.0.0.11', 'en-US'), ('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; de-DE) ' 'Opera 8.54', 'opera', 'windows', '8.54', 'de-DE'), # ('Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420' # ' (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3', # 'safari', 'iphone', '3.0', 'en'), ('Bot Googlebot/2.1 (http://www.googlebot.com/bot.html)', 'google', None, '2.1', None), ('Mozilla/5.0 (X11; CrOS armv7l 3701.81.0) AppleWebKit/537.31 ' '(KHTML, like Gecko) Chrome/26.0.1410.57 Safari/537.31', 'chrome', 'chromeos', '26.0.1410.57', None), ('Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; rv:11.0) ' 'like Gecko', 'msie', 'windows', '11.0', None), ('Mozilla/5.0 (SymbianOS/9.3; Series60/3.2 NokiaE5-00/101.003; ' 'Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 ' '(KHTML, like Gecko) NokiaBrowser/7.3.1.35 ' 'Mobile Safari/533.4 3gpp-gba', 'safari', 'symbian', '533.4', None) ] for ua, browser, platform, version, lang in user_agents: request = Request({'HTTP_USER_AGENT': ua}) self.assertEqual(request.user_agent.browser, browser) self.assertEqual(request.user_agent.platform, platform) self.assertEqual(request.user_agent.version, version) self.assertEqual(request.user_agent.language, lang) self.assertTrue(bool(request.user_agent)) self.assertEqual(request.user_agent.to_header(), ua) self.assertEqual(str(request.user_agent), ua) request = Request({'HTTP_USER_AGENT': 'foo'}) self.assertFalse(request.user_agent)
def test_access_route(self): req = Request.from_values( headers={'X-Forwarded-For': '192.168.1.2, 192.168.1.1'}) req.environ['REMOTE_ADDR'] = '192.168.1.3' self.assertEqual(req.access_route, ['192.168.1.2', '192.168.1.1']) self.assertEqual(req.remote_addr, '192.168.1.3') req = Request.from_values() req.environ['REMOTE_ADDR'] = '192.168.1.3' self.assertEqual(list(req.access_route), ['192.168.1.3'])
def test_access_route(self): req = Request.from_values(headers={ 'X-Forwarded-For': '192.168.1.2, 192.168.1.1' }) req.environ['REMOTE_ADDR'] = '192.168.1.3' self.assertEqual(req.access_route, ['192.168.1.2', '192.168.1.1']) self.assertEqual(req.remote_addr, '192.168.1.3') req = Request.from_values() req.environ['REMOTE_ADDR'] = '192.168.1.3' self.assertEqual(list(req.access_route), ['192.168.1.3'])
def test_request_repr(self): req = Request.from_values('/foobar') self.assertEqual("<Request 'http://localhost/foobar' [GET]>", repr(req)) # test with non-ascii characters req = Request.from_values('/привет') self.assertEqual("<Request 'http://localhost/привет' [GET]>", repr(req)) # test with unicode type for python 2 req = Request.from_values(u'/привет') self.assertEqual("<Request 'http://localhost/привет' [GET]>", repr(req))
def test_url_request_descriptors(self): req = Request.from_values('/bar?foo=baz', 'http://example.com/test') self.assertEqual(req.path, u'/bar') self.assertEqual(req.full_path, u'/bar?foo=baz') self.assertEqual(req.script_root, u'/test') self.assertEqual(req.url, u'http://example.com/test/bar?foo=baz') self.assertEqual(req.base_url, u'http://example.com/test/bar') self.assertEqual(req.url_root, u'http://example.com/test/') self.assertEqual(req.host_url, u'http://example.com/') self.assertEqual(req.host, 'example.com') self.assertEqual(req.scheme, 'http') req = Request.from_values('/bar?foo=baz', 'https://example.com/test') self.assertEqual(req.scheme, 'https')
def test_request_repr(self): req = Request.from_values('/foobar') self.assertEqual( "<Request 'http://localhost/foobar' [GET]>", repr(req) ) # test with non-ascii characters req = Request.from_values('/привет') self.assertEqual( "<Request 'http://localhost/привет' [GET]>", repr(req) ) # test with unicode type for python 2 req = Request.from_values(u'/привет') self.assertEqual( "<Request 'http://localhost/привет' [GET]>", repr(req) )
def test_common_request_descriptors_mixin(self): request = Request.from_values( content_type='text/html; charset=utf-8', content_length='23', headers={ 'Referer': 'http://www.example.com/', 'Date': 'Sat, 28 Feb 2009 19:04:35 GMT', 'Max-Forwards': '10', 'Pragma': 'no-cache', 'Content-Encoding': 'gzip', 'Content-MD5': '9a3bc6dbc47a70db25b84c6e5867a072' } ) self.assertEqual(request.content_type, 'text/html; charset=utf-8') self.assertEqual(request.mimetype, 'text/html') self.assertEqual(request.mimetype_params, {'charset': 'utf-8'}) self.assertEqual(request.content_length, 23) self.assertEqual(request.referrer, 'http://www.example.com/') self.assertEqual(request.date, datetime(2009, 2, 28, 19, 4, 35)) self.assertEqual(request.max_forwards, 10) self.assertTrue('no-cache' in request.pragma) self.assertEqual(request.content_encoding, 'gzip') self.assertEqual( request.content_md5, '9a3bc6dbc47a70db25b84c6e5867a072' )
def test_etag_request_mixin(self): request = Request({ 'HTTP_CACHE_CONTROL': 'no-store, no-cache', 'HTTP_IF_MATCH': 'w/"foo", bar, "baz"', 'HTTP_IF_NONE_MATCH': 'w/"foo", bar, "baz"', 'HTTP_IF_MODIFIED_SINCE': 'Tue, 22 Jan 2008 11:18:44 GMT', 'HTTP_IF_UNMODIFIED_SINCE': 'Tue, 22 Jan 2008 11:18:44 GMT' }) self.assertTrue(request.cache_control.no_store) self.assertTrue(request.cache_control.no_cache) for etags in request.if_match, request.if_none_match: self.assertTrue(etags('bar')) self.assertTrue(etags.contains_raw('w/"foo"')) self.assertTrue(etags.contains_weak('foo')) self.assertFalse(etags.contains('foo')) self.assertEqual(request.if_modified_since, datetime(2008, 1, 22, 11, 18, 44)) self.assertEqual(request.if_unmodified_since, datetime(2008, 1, 22, 11, 18, 44))
def test_common_request_descriptors_mixin(self): request = Request.from_values(content_type='text/html; charset=utf-8', content_length='23', headers={ 'Referer': 'http://www.example.com/', 'Date': 'Sat, 28 Feb 2009 19:04:35 GMT', 'Max-Forwards': '10', 'Pragma': 'no-cache', 'Content-Encoding': 'gzip', 'Content-MD5': '9a3bc6dbc47a70db25b84c6e5867a072' }) self.assertEqual(request.content_type, 'text/html; charset=utf-8') self.assertEqual(request.mimetype, 'text/html') self.assertEqual(request.mimetype_params, {'charset': 'utf-8'}) self.assertEqual(request.content_length, 23) self.assertEqual(request.referrer, 'http://www.example.com/') self.assertEqual(request.date, datetime(2009, 2, 28, 19, 4, 35)) self.assertEqual(request.max_forwards, 10) self.assertTrue('no-cache' in request.pragma) self.assertEqual(request.content_encoding, 'gzip') self.assertEqual(request.content_md5, '9a3bc6dbc47a70db25b84c6e5867a072')
def test_authorization_mixin(self): request = Request.from_values( headers={'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}) a = request.authorization self.assertEqual(a.type, 'basic') self.assertEqual(a.username, 'Aladdin') self.assertEqual(a.password, 'open sesame')
def test_other_method_payload(self): data = b'Hello World' req = Request.from_values( input_stream=BytesIO(data), method='WHAT_THE_FUCK', content_length=len(data), content_type='text/plain' ) self.assertEqual(req.get_data(), data) self.assertTrue(isinstance(req.stream, LimitedStream))
def test_url_request_descriptors_query_quoting(self): next = 'http%3A%2F%2Fwww.example.com%2F%3Fnext%3D%2F' req = Request.from_values( '/bar?next=' + next, 'http://example.com/' ) self.assertEqual(req.path, u'/bar') self.assertEqual(req.full_path, u'/bar?next=' + next) self.assertEqual(req.url, u'http://example.com/bar?next=' + next)
def test_authorization_mixin(self): request = Request.from_values(headers={ 'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' }) a = request.authorization self.assertEqual(a.type, 'basic') self.assertEqual(a.username, 'Aladdin') self.assertEqual(a.password, 'open sesame')
def test_other_method_payload(self): data = b'Hello World' req = Request.from_values(input_stream=BytesIO(data), method='WHAT_THE_FUCK', content_length=len(data), content_type='text/plain') self.assertEqual(req.get_data(), data) self.assertTrue(isinstance(req.stream, LimitedStream))
def test_url_request_descriptors(self): req = Request.from_values( '/bar?foo=baz', 'http://example.com/test' ) self.assertEqual(req.path, u'/bar') self.assertEqual(req.full_path, u'/bar?foo=baz') self.assertEqual(req.script_root, u'/test') self.assertEqual(req.url, u'http://example.com/test/bar?foo=baz') self.assertEqual(req.base_url, u'http://example.com/test/bar') self.assertEqual(req.url_root, u'http://example.com/test/') self.assertEqual(req.host_url, u'http://example.com/') self.assertEqual(req.host, 'example.com') self.assertEqual(req.scheme, 'http') req = Request.from_values( '/bar?foo=baz', 'https://example.com/test' ) self.assertEqual(req.scheme, 'https')
def test_form_parsing_failed(self): data = (b'--blah\r\n') data = Request.from_values( input_stream=BytesIO(data), content_length=len(data), content_type='multipart/form-data; boundary=foo', method='POST') self.assertFalse(data.files) self.assertFalse(data.form)
def test_new_response_iterator_behavior(self): req = Request.from_values() resp = Response(u'Hello Wörld!') def get_content_length(resp): headers = resp.get_wsgi_headers(req.environ) return headers.get('content-length', type=int) def generate_items(): yield "Hello " yield u"Wörld!" # verktyg encodes when set to `data` now, which happens # if a string is passed to the response object. self.assertEqual(resp.response, [u'Hello Wörld!'.encode('utf-8')]) self.assertEqual(resp.get_data(), u'Hello Wörld!'.encode('utf-8')) self.assertEqual(get_content_length(resp), 13) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # try the same for manual assignment resp.set_data(u'Wörd') self.assertEqual(resp.response, [u'Wörd'.encode('utf-8')]) self.assertEqual(resp.get_data(), u'Wörd'.encode('utf-8')) self.assertEqual(get_content_length(resp), 5) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # automatic generator sequence conversion resp.response = generate_items() self.assertTrue(resp.is_streamed) self.assertFalse(resp.is_sequence) self.assertEqual(resp.get_data(), u'Hello Wörld!'.encode('utf-8')) self.assertEqual(resp.response, [b'Hello ', u'Wörld!'.encode('utf-8')]) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # automatic generator sequence conversion resp.response = generate_items() resp.implicit_sequence_conversion = False self.assertTrue(resp.is_streamed) self.assertFalse(resp.is_sequence) self.assertRaises(RuntimeError, lambda: resp.get_data()) resp.make_sequence() self.assertEqual(resp.get_data(), u'Hello Wörld!'.encode('utf-8')) self.assertEqual(resp.response, [b'Hello ', u'Wörld!'.encode('utf-8')]) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # stream makes it a list no matter how the conversion is set for val in True, False: resp.implicit_sequence_conversion = val resp.response = ("foo", "bar") self.assertTrue(resp.is_sequence) resp.stream.write('baz') self.assertEqual(resp.response, ['foo', 'bar', 'baz'])
def test_new_response_iterator_behavior(self): req = Request.from_values() resp = Response(u'Hello Wörld!') def get_content_length(resp): headers = resp.get_wsgi_headers(req.environ) return headers.get('content-length', type=int) def generate_items(): yield "Hello " yield u"Wörld!" # verktyg encodes when set to `data` now, which happens # if a string is passed to the response object. self.assertEqual(resp.response, [u'Hello Wörld!'.encode('utf-8')]) self.assertEqual(resp.get_data(), u'Hello Wörld!'.encode('utf-8')) self.assertEqual(get_content_length(resp), 13) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # try the same for manual assignment resp.set_data(u'Wörd') self.assertEqual(resp.response, [u'Wörd'.encode('utf-8')]) self.assertEqual(resp.get_data(), u'Wörd'.encode('utf-8')) self.assertEqual(get_content_length(resp), 5) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # automatic generator sequence conversion resp.response = generate_items() self.assertTrue(resp.is_streamed) self.assertFalse(resp.is_sequence) self.assertEqual(resp.get_data(), u'Hello Wörld!'.encode('utf-8')) self.assertEqual(resp.response, [b'Hello ', u'Wörld!'.encode('utf-8')]) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # automatic generator sequence conversion resp.response = generate_items() resp.implicit_sequence_conversion = False self.assertTrue(resp.is_streamed) self.assertFalse(resp.is_sequence) self.assertRaises(RuntimeError, lambda: resp.get_data()) resp.make_sequence() self.assertEqual(resp.get_data(), u'Hello Wörld!'.encode('utf-8')) self.assertEqual(resp.response, [b'Hello ', u'Wörld!'.encode('utf-8')]) self.assertFalse(resp.is_streamed) self.assertTrue(resp.is_sequence) # stream makes it a list no matter how the conversion is set for val in True, False: resp.implicit_sequence_conversion = val resp.response = ("foo", "bar") self.assertTrue(resp.is_sequence) resp.stream.write('baz') self.assertEqual(resp.response, ['foo', 'bar', 'baz'])
def test_data_descriptor_triggers_parsing(self): data = b'foo=Hello+World' req = Request.from_values( '/', method='POST', data=data, content_type='application/x-www-form-urlencoded') self.assertEqual(req.get_data(parse_form_data=True), b'') self.assertEqual(req.form['foo'], u'Hello World')
def test_get_data_method_parsing_caching_behavior(self): data = b'foo=Hello+World' req = Request.from_values( '/', method='POST', data=data, content_type='application/x-www-form-urlencoded') # get_data() caches, so form stays available self.assertEqual(req.get_data(), data) self.assertEqual(req.form['foo'], u'Hello World') self.assertEqual(req.get_data(), data) # here we access the form data first, caching is bypassed req = Request.from_values( '/', method='POST', data=data, content_type='application/x-www-form-urlencoded') self.assertEqual(req.form['foo'], u'Hello World') self.assertEqual(req.get_data(), b'') # Another case is uncached get data which trashes everything req = Request.from_values( '/', method='POST', data=data, content_type='application/x-www-form-urlencoded') self.assertEqual(req.get_data(cache=False), data) self.assertEqual(req.get_data(cache=False), b'') self.assertEqual(req.form, {}) # Or we can implicitly start the form parser which is similar to # the old .data behavior req = Request.from_values( '/', method='POST', data=data, content_type='application/x-www-form-urlencoded') self.assertEqual(req.get_data(parse_form_data=True), b'') self.assertEqual(req.form['foo'], u'Hello World')
def test_ranges(self): # basic range stuff req = Request.from_values() self.assertIsNone(req.range) req = Request.from_values(headers={'Range': 'bytes=0-499'}) self.assertEqual(req.range.ranges, [(0, 500)]) resp = Response() resp.content_range = req.range.make_content_range(1000) self.assertEqual(resp.content_range.units, 'bytes') self.assertEqual(resp.content_range.start, 0) self.assertEqual(resp.content_range.stop, 500) self.assertEqual(resp.content_range.length, 1000) self.assertEqual(resp.headers['Content-Range'], 'bytes 0-499/1000') resp.content_range.unset() self.assertNotIn('Content-Range', resp.headers) resp.headers['Content-Range'] = 'bytes 0-499/1000' self.assertEqual(resp.content_range.units, 'bytes') self.assertEqual(resp.content_range.start, 0) self.assertEqual(resp.content_range.stop, 500) self.assertEqual(resp.content_range.length, 1000)
def test_ranges(self): # basic range stuff req = Request.from_values() self.assertIsNone(req.range) req = Request.from_values(headers={'Range': 'bytes=0-499'}) self.assertEqual(req.range.ranges, [(0, 500)]) resp = Response() resp.content_range = req.range.make_content_range(1000) self.assertEqual(resp.content_range.units, 'bytes') self.assertEqual(resp.content_range.start, 0) self.assertEqual(resp.content_range.stop, 500) self.assertEqual(resp.content_range.length, 1000) self.assertEqual(resp.headers['Content-Range'], 'bytes 0-499/1000') resp.content_range.unset() self.assertNotIn('Content-Range', resp.headers) resp.headers['Content-Range'] = 'bytes 0-499/1000' self.assertEqual(resp.content_range.units, 'bytes') self.assertEqual(resp.content_range.start, 0) self.assertEqual(resp.content_range.stop, 500) self.assertEqual(resp.content_range.length, 1000)
def test_url_request_descriptors_hosts(self): req = Request.from_values('/bar?foo=baz', 'http://example.com/test') req.trusted_hosts = ['example.com'] self.assertEqual(req.path, u'/bar') self.assertEqual(req.full_path, u'/bar?foo=baz') self.assertEqual(req.script_root, u'/test') self.assertEqual(req.url, u'http://example.com/test/bar?foo=baz') self.assertEqual(req.base_url, u'http://example.com/test/bar') self.assertEqual(req.url_root, u'http://example.com/test/') self.assertEqual(req.host_url, u'http://example.com/') self.assertEqual(req.host, 'example.com') self.assertEqual(req.scheme, 'http') req = Request.from_values('/bar?foo=baz', 'https://example.com/test') self.assertEqual(req.scheme, 'https') req = Request.from_values('/bar?foo=baz', 'http://example.com/test') req.trusted_hosts = ['example.org'] self.assertRaises(SecurityError, lambda: req.url) self.assertRaises(SecurityError, lambda: req.base_url) self.assertRaises(SecurityError, lambda: req.url_root) self.assertRaises(SecurityError, lambda: req.host_url) self.assertRaises(SecurityError, lambda: req.host)
def test_response_iter_wrapping(self): def uppercasing(iterator): for item in iterator: yield item.upper() def generator(): yield 'foo' yield 'bar' req = Request.from_values() resp = Response(generator()) del resp.headers['Content-Length'] resp.response = uppercasing(resp.iter_encoded()) actual_resp = Response.from_app( resp, req.environ, buffered=True ) self.assertEqual(actual_resp.get_data(), b'FOOBAR')
def test_response_iter_wrapping(self): def uppercasing(iterator): for item in iterator: yield item.upper() def generator(): yield 'foo' yield 'bar' req = Request.from_values() resp = Response(generator()) del resp.headers['Content-Length'] resp.response = uppercasing(resp.iter_encoded()) actual_resp = Response.from_app( resp, req.environ, buffered=True ) self.assertEqual(actual_resp.get_data(), b'FOOBAR')
def test_file_closing_with(self): data = (b'--foo\r\n' b'Content-Disposition: form-data; name="foo"; ' b'filename="foo.txt"\r\n' b'Content-Type: text/plain; charset=utf-8\r\n\r\n' b'file contents, just the contents\r\n' b'--foo--') req = Request.from_values( input_stream=BytesIO(data), content_length=len(data), content_type='multipart/form-data; boundary=foo', method='POST') with req: foo = req.files['foo'] self.assertEqual(foo.mimetype, 'text/plain') self.assertEqual(foo.filename, 'foo.txt') self.assertTrue(foo.closed)
def test_stream_wrapping(self): class LowercasingStream(object): def __init__(self, stream): self._stream = stream def read(self, size=-1): return self._stream.read(size).lower() def readline(self, size=-1): return self._stream.readline(size).lower() data = b'foo=Hello+World' req = Request.from_values( '/', method='POST', data=data, content_type='application/x-www-form-urlencoded') req.stream = LowercasingStream(req.stream) self.assertEqual(req.form['foo'], 'hello world')
def test_storage_classes(self): class MyRequest(Request): dict_storage_class = dict list_storage_class = list parameter_storage_class = dict req = MyRequest.from_values('/?foo=baz', headers={'Cookie': 'foo=bar'}) self.assertIs(type(req.cookies), dict) self.assertEqual(req.cookies, {'foo': 'bar'}) self.assertIs(type(req.access_route), list) self.assertIs(type(req.args), dict) self.assertIs(type(req.values), CombinedMultiDict) self.assertEqual(req.values['foo'], u'baz') req = Request.from_values(headers={'Cookie': 'foo=bar'}) self.assertIs(type(req.cookies), ImmutableTypeConversionDict) self.assertEqual(req.cookies, {'foo': 'bar'}) self.assertIs(type(req.access_route), ImmutableList) MyRequest.list_storage_class = tuple req = MyRequest.from_values() self.assertIs(type(req.access_route), tuple)
def test_storage_classes(self): class MyRequest(Request): dict_storage_class = dict list_storage_class = list parameter_storage_class = dict req = MyRequest.from_values('/?foo=baz', headers={ 'Cookie': 'foo=bar' }) self.assertIs(type(req.cookies), dict) self.assertEqual(req.cookies, {'foo': 'bar'}) self.assertIs(type(req.access_route), list) self.assertIs(type(req.args), dict) req = Request.from_values(headers={ 'Cookie': 'foo=bar' }) self.assertIs(type(req.cookies), ImmutableTypeConversionDict) self.assertEqual(req.cookies, {'foo': 'bar'}) self.assertIs(type(req.access_route), ImmutableList) MyRequest.list_storage_class = tuple req = MyRequest.from_values() self.assertIs(type(req.access_route), tuple)
def test_url_request_descriptors_query_quoting(self): next = 'http%3A%2F%2Fwww.example.com%2F%3Fnext%3D%2F' req = Request.from_values('/bar?next=' + next, 'http://example.com/') self.assertEqual(req.path, u'/bar') self.assertEqual(req.full_path, u'/bar?next=' + next) self.assertEqual(req.url, u'http://example.com/bar?next=' + next)
def test_url_charset_reflection(self): req = Request.from_values() req.charset = 'utf-7' self.assertEqual(req.url_charset, 'utf-7')
def test_shallow_mode(self): request = Request({'QUERY_STRING': 'foo=bar'}, shallow=True) self.assertEqual(request.args['foo'], 'bar') self.assertRaises(RuntimeError, lambda: request.form['foo'])
def test_request_mimetype_always_lowercase(self): request = Request.from_values(content_type='APPLICATION/JSON') self.assertEqual(request.mimetype, 'application/json')
def test_query_string_is_bytes(self): req = Request.from_values(u'/?foo=%2f') self.assertEqual(req.query_string, 'foo=%2f')
def test_query_string_is_bytes(self): req = Request.from_values(u'/?foo=%2f') self.assertEqual(req.query_string, b'foo=%2f')
def test_request_method_case_sensitivity(self): req = Request({'REQUEST_METHOD': 'get'}) self.assertEqual(req.method, 'GET')
def test_request_mimetype_always_lowercase(self): request = Request.from_values(content_type='APPLICATION/JSON') self.assertEqual(request.mimetype, 'application/json')