예제 #1
0
 def test_invalid_multipart_no_boundary(self):
     parser = parsers.MultiPartParser()
     stream = io.BytesIO(b'invalid')
     with self.assertRaises(exceptions.ParseError) as context:
         parser.parse(stream, mediatypes.MediaType('multipart/form-data'))
     detail = str(context.exception)
     expected = 'Multipart message missing boundary in Content-Type header'
     self.assertEqual(detail, expected)
예제 #2
0
 def test_invalid_json(self):
     parser = parsers.JSONParser()
     stream = io.BytesIO(b'{key: 1, "other": "two"}')
     with self.assertRaises(exceptions.ParseError) as context:
         parser.parse(stream, mediatypes.MediaType('application/json'))
     detail = str(context.exception)
     expected_py2 = 'JSON parse error - Expecting property name: line 1 column 1 (char 1)'
     expected_py3 = 'JSON parse error - Expecting property name enclosed in double quotes: line 1 column 2 (char 1)'
     self.assertIn(detail, (expected_py2, expected_py3))
예제 #3
0
 def test_invalid_multipart(self):
     parser = parsers.MultiPartParser()
     stream = io.BytesIO(b'invalid')
     media_type = mediatypes.MediaType('multipart/form-data; boundary="foo"')
     with self.assertRaises(exceptions.ParseError) as context:
         parser.parse(stream, media_type, content_length=len('invalid'))
     detail = str(context.exception)
     expected = 'Multipart parse error - Expected boundary at start of multipart data'
     self.assertEqual(detail, expected)