def test_collection_resource_to_json(self): ds = MagicMock() ds.get_resource.return_value = { 'href': '/', 'offset': 0, 'limit': 25, 'size': 2, 'items': [ {'href': 'test/resource'}, {'href': 'another/resource'} ] } props = { 'href': '/', 'offset': 0, 'limit': 25, 'size': 2, 'items': [ {'href': 'test/resource'}, {'href': 'another/resource'} ] } rl = CollectionResource(client=MagicMock(data_store=ds), properties=props) self.assertEqual(props, json.loads(rl.to_json())) # collection resource as attribute rds = MagicMock() class Res(Resource, SaveMixin, DictMixin): writable_attrs = ('foo_val', 'bar', 'rl') res = Res(MagicMock(data_store=rds), href='test/resource1') res.rl = rl data = { 'foo_val': True, 'bar': False } res.update(data) data.update({'href': 'test/resource1'}) data.update({'rl': props}) res._expand = Expansion(*['rl']) self.assertEqual(data, json.loads(res.to_json()))
def test_collection_resource_to_json(self): ds = MagicMock() ds.get_resource.return_value = { 'href': '/', 'offset': 0, 'limit': 25, 'size': 2, 'items': [{ 'href': 'test/resource' }, { 'href': 'another/resource' }] } props = { 'href': '/', 'offset': 0, 'limit': 25, 'size': 2, 'items': [{ 'href': 'test/resource' }, { 'href': 'another/resource' }] } rl = CollectionResource(client=MagicMock(data_store=ds), properties=props) self.assertEqual(props, json.loads(rl.to_json())) # collection resource as attribute rds = MagicMock() class Res(Resource, SaveMixin, DictMixin): writable_attrs = ('foo_val', 'bar', 'rl') res = Res(MagicMock(data_store=rds), href='test/resource1') res.rl = rl data = {'foo_val': True, 'bar': False} res.update(data) data.update({'href': 'test/resource1'}) data.update({'rl': props}) res._expand = Expansion(*['rl']) self.assertEqual(data, json.loads(res.to_json()))