def test_single_resource_with_bad_included(self): resource_object1 = { 'id': 1, 'type': "model_name", 'attributes': {}, 'relationships': {}, } document = {'data': resource_object1, 'included': {'nope': []}} valid = jsalve_utils.is_valid_top_level(document) self.assertFalse(valid)
def test_single_resource(self): resource_object1 = { 'id': 1, 'type': "model_name", 'attributes': {}, 'relationships': {}, } document = {'data': resource_object1} valid = jsalve_utils.is_valid_top_level(document) self.assertTrue(valid)
def test_collection_with_included(self): resource_object1 = { 'id': 1, 'type': "model_name", 'attributes': {}, 'relationships': {}, } resource_object2 = { 'id': 2, 'type': "model_name", 'attributes': {}, 'relationships': {}, } collection = [resource_object1, resource_object2] document = {'data': collection, 'included': []} valid = jsalve_utils.is_valid_top_level(document, collection=True) self.assertTrue(valid)
def test_bad_meta(self): document = {'meta': 'content'} valid = jsalve_utils.is_valid_top_level(document) self.assertFalse(valid)
def test_meta(self): document = {'meta': {}} valid = jsalve_utils.is_valid_top_level(document) self.assertTrue(valid)
def test_bad_errors(self): document = {'errors': {}} valid = jsalve_utils.is_valid_top_level(document) self.assertFalse(valid)
def test_errors(self): document = {'errors': []} valid = jsalve_utils.is_valid_top_level(document) self.assertTrue(valid)
def test_included_without_data(self): bad_document = {'included': [], 'errors': []} valid = jsalve_utils.is_valid_top_level(bad_document) self.assertFalse(valid)
def test_data_and_errors_collision(self): bad_document = {'data': {}, 'errors': []} valid = jsalve_utils.is_valid_top_level(bad_document) self.assertFalse(valid)
def test_none_document(self): bad_document = None valid = jsalve_utils.is_valid_top_level(bad_document) self.assertFalse(valid)
def test_bad_document(self): bad_document = {'bad_member': []} valid = jsalve_utils.is_valid_top_level(bad_document) self.assertFalse(valid)