Skip to content

Commit

Permalink
Add test to verify that an invalid json payload results in a BadReque…
Browse files Browse the repository at this point in the history
…stError.
  • Loading branch information
kjohnson3 committed Mar 28, 2017
1 parent 894402a commit 613cac5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sqlalchemy_jsonapi/unittests/test_serializer_post_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,3 +503,18 @@ def test_add_resource_with_missing_one_to_many_relationship_type(self):
self.assertEqual(
error.exception.detail, 'posts must have type and id keys')
self.assertEqual(error.exception.status_code, 400)

def test_add_resource_with_invalid_json_payload(self):
"""Create resource with invalid json payload returns 400.
A BadRequestError is raised.
"""
payload = {'foo'}

with self.assertRaises(errors.BadRequestError) as error:
models.serializer.post_collection(
self.session, payload, 'users')

self.assertEqual(
error.exception.detail, 'Request body should be a JSON hash')
self.assertEqual(error.exception.status_code, 400)

0 comments on commit 613cac5

Please sign in to comment.