def test_invalid_relationship_object(self): primary_data = { 'relationships': { 'important-info':'not-json-api', } } with pytest.raises(JsonApiException): api_utils.parse_relationships(primary_data)
def test_null_relationship_object(self): primary_data = { 'relationships': { 'important-info': None, } } with pytest.raises(JsonApiException): api_utils.parse_relationships(primary_data)
def test_missing_attributes(self): """ Ensures a ``None`` for missing ``relationships`` member in primary data. """ primary_data = {'no_attributes': {}} relationships = api_utils.parse_relationships(primary_data) self.assertIsNone(relationships)
def test_missing_data_relationship(self): """ Ensures a ``None`` for missing ``relationships`` member in primary data. """ primary_data = { 'relationships': { 'related-object': { 'no_data': {} } } } relationships = api_utils.parse_relationships(primary_data) self.assertIsNone(relationships['related_object'])
def test_to_one_relationships(self): primary_data = { 'relationships': { 'important-info': { 'data': { 'id': 1 } }, 'more-important-info': {'data': None}, 'bad-resource-data': {'pk': 1} } } relationships = api_utils.parse_relationships(primary_data) self.assertEqual(relationships['important_info'], 1) self.assertEqual(relationships['more_important_info'], None) self.assertEqual(relationships['bad_resource_data'], None)
def test_to_many_relationships(self): primary_data = { 'relationships': { 'important-info': { 'data': [ {'id': 1}, {'id': 2}, {'id': 3} ] }, 'more-important-info': { 'data': [ {'id': 1} ] }, 'bad-resource-data': {'pk': 1} } } relationships = api_utils.parse_relationships(primary_data) self.assertEqual(relationships['important_info'], [1, 2, 3]) self.assertEqual(relationships['more_important_info'], [1]) self.assertEqual(relationships['bad_resource_data'], None)