Skip to content

Commit

Permalink
Merge pull request ColtonProvias#59 from kaitj91/check_json_data_test
Browse files Browse the repository at this point in the history
Add test to verify that an invalid json payload results in a BadRequestError.
  • Loading branch information
Anderycks authored Apr 3, 2017
2 parents d49d8e9 + 9df7005 commit e7b8e23
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 @@ -504,6 +504,21 @@ def test_add_resource_with_missing_one_to_many_relationship_type(self):
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)

@testcases.fragile
def test_add_resource_with_a_null_relationship(self):
"""Create resource with a null relationship returns 201."""
Expand Down

0 comments on commit e7b8e23

Please sign in to comment.