def test_request_json_gzip(self): """Test well-formed request: gzip""" with mock.patch('flask.request', test_request(self.valid_gzip, 'gzip')): self.assertEqual(self.valid_dict, api.request_json()) with mock.patch('flask.request', test_request(self.valid_gzip, 'GZip')): self.assertEqual(self.valid_dict, api.request_json())
def test_request_json_bad_request_mismatch_encoding(self): """Test mismatched data vs encoding.""" with mock.patch('flask.request', test_request(self.valid_bytes, 'gzip')): with self.assertRaises(werkzeug_exc.BadRequest): api.request_json() with mock.patch('flask.request', test_request(self.valid_gzip, None)): with self.assertRaises(werkzeug_exc.BadRequest): api.request_json()
def test_request_json_identity(self): """Test well-formed request: 'identity' encoding.""" with mock.patch('flask.request', test_request(self.valid_bytes, None)): self.assertEqual(self.valid_dict, api.request_json()) with mock.patch('flask.request', test_request(self.valid_bytes, 'identity')): self.assertEqual(self.valid_dict, api.request_json()) with mock.patch('flask.request', test_request(self.valid_bytes, 'Identity')): self.assertEqual(self.valid_dict, api.request_json())
def test_request_json_unsupported_legal(self): """Test illegal encoding.""" with mock.patch('flask.request', test_request(self.valid_bytes, 'fake_encoding')): with self.assertRaises(werkzeug_exc.UnsupportedMediaType): api.request_json()
def test_request_json_bad_request_invalid_json(self): """Test bad data.""" with mock.patch('flask.request', test_request(b'{"invalid_json": true', None)): with self.assertRaises(werkzeug_exc.BadRequest): api.request_json()