Пример #1
0
 def test_parse_body_empty(self):
     """Should parse an empty body to an empty string."""
     request = MockRequest()
     request.body = b''
     request.headers = {}
     result = parse_body(request)
     self.assertEqual(result, '', 'Did not properly handle body = empty string.')
Пример #2
0
 def test_parse_body_defaults_to_text_plain(self):
     """Should parse a body to a string by default."""
     request = MockRequest()
     request.body = b'{"foo" : "bar"}'
     request.headers = {}
     result = parse_body(request)
     self.assertEqual(result, '{"foo" : "bar"}', 'Did not properly handle body = empty string.')
Пример #3
0
 def test_parse_body_bad_json(self):
     """Should parse the body from an invalid JSON byte stream to a string."""
     request = MockRequest()
     request.body = b'{ "foo" "bar" }'
     request.headers = {
         'Content-Type' : 'application/json'
     }
     result = parse_body(request)
     self.assertEqual(result, '{ "foo" "bar" }', 'Did not properly parse json body.')
Пример #4
0
 def test_parse_body_json(self):
     """Should parse the body from a JSON byte stream to a dict."""
     request = MockRequest()
     request.body = b'{ "foo" : "bar" }'
     request.headers = {
         'Content-Type' : 'application/json'
     }
     result = parse_body(request)
     self.assertEqual(result, { 'foo' : 'bar' }, 'Did not properly parse json body.')
Пример #5
0
 def test_parse_body_text(self):
     """Should parse the body text from a byte stream to a string."""
     request = MockRequest()
     request.body = b'test value'
     request.headers = {
         'Content-Type' : 'text/plain'
     }
     result = parse_body(request)
     self.assertEqual(result, "test value", 'Did not properly parse text body.')
Пример #6
0
 def test_parse_body_url_encoded_form(self):
     """Should parse body arguments from urlencoded form data to a dict."""
     request = MockRequest()
     request.body = None
     request.body_arguments = { 'foo' : [b'bar']}
     request.headers = {
         'Content-Type' : 'application/x-www-form-urlencoded'
     }
     result = parse_body(request)
     self.assertEqual(result, { 'foo' : ['bar']}, 'Did not properly parse json body.')
Пример #7
0
 def test_parse_body_multipart_form(self):
     """Should parse body arguments from multipart form data to a dict."""
     request = MockRequest()
     request.body = None
     request.body_arguments = { 'foo' : [b'bar']}
     request.headers = {
         'Content-Type' : 'multipart/form-data'
     }
     result = parse_body(request)
     self.assertEqual(result, { 'foo' : ['bar']}, 'Did not properly parse json body.')