def test_create_object_with_inlines(self): data = { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar', 'determinations': [{ 'iscurrent': False, 'number1': 1 }, { 'iscurrent': False, 'number1': 2 }], 'collectionobjectattribute': { 'text1': 'some text' } } obj = api.create_obj(self.collection, self.agent, 'collectionobject', data) co = models.Collectionobject.objects.get(id=obj.id) self.assertEqual( set(co.determinations.values_list('number1', flat=True)), set((1, 2))) self.assertEqual(co.collectionobjectattribute.text1, 'some text')
def test_create_object(self): obj = api.create_obj(self.collection, self.agent, 'collectionobject', { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar'}) obj = models.Collectionobject.objects.get(id=obj.id) self.assertTrue(obj.id is not None) self.assertEqual(obj.collection, self.collection) self.assertEqual(obj.catalognumber, 'foobar') self.assertEqual(obj.createdbyagent, self.agent)
def test_delete_object(self): obj = api.create_obj( self.collection, self.agent, 'collectionobject', { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar' }) api.delete_obj(self.agent, 'collectionobject', obj.id, obj.version) self.assertEqual( models.Collectionobject.objects.filter(id=obj.id).count(), 0)
def test_delete_object(self): obj = api.create_obj(self.collection, self.agent, 'collectionobject', { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar'}) data = api.get_resource('collectionobject', obj.id) obj.version += 1 obj.save() with self.assertRaises(api.StaleObjectException) as cm: api.delete_obj(self.agent, 'collectionobject', data['id'], data['version']) self.assertEqual(models.Collectionobject.objects.filter(id=obj.id).count(), 1)
def test_create_object(self): obj = api.create_obj( self.collection, self.agent, 'collectionobject', { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar' }) obj = models.Collectionobject.objects.get(id=obj.id) self.assertTrue(obj.id is not None) self.assertEqual(obj.collection, self.collection) self.assertEqual(obj.catalognumber, 'foobar') self.assertEqual(obj.createdbyagent, self.agent)
def test_create_object_with_inlined_existing_resource(self): coa = models.Collectionobjectattribute.objects.create( collectionmemberid=self.collection.id) coa_data = api.get_resource('collectionobjectattribute', coa.id) co_data = { 'collection': api.uri_for_model('collection', self.collection.id), 'collectionobjectattribute': coa_data, 'catalognumber': 'foobar'} obj = api.create_obj(self.collection, self.agent, 'collectionobject', co_data) co = models.Collectionobject.objects.get(id=obj.id) self.assertEqual(co.collectionobjectattribute, coa)
def test_create_object_with_inlined_existing_resource(self): coa = models.Collectionobjectattribute.objects.create( collectionmemberid=self.collection.id) coa_data = api.get_resource('collectionobjectattribute', coa.id) co_data = { 'collection': api.uri_for_model('collection', self.collection.id), 'collectionobjectattribute': coa_data, 'catalognumber': 'foobar' } obj = api.create_obj(self.collection, self.agent, 'collectionobject', co_data) co = models.Collectionobject.objects.get(id=obj.id) self.assertEqual(co.collectionobjectattribute, coa)
def test_delete_object(self): obj = api.create_obj( self.collection, self.agent, 'collectionobject', { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar' }) data = api.get_resource('collectionobject', obj.id) obj.version += 1 obj.save() with self.assertRaises(api.StaleObjectException) as cm: api.delete_resource(self.agent, 'collectionobject', data['id'], data['version']) self.assertEqual( models.Collectionobject.objects.filter(id=obj.id).count(), 1)
def test_create_object_with_inlines(self): data = { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar', 'determinations': [{ 'iscurrent': False, 'number1': 1 }, { 'iscurrent': False, 'number1': 2 }], 'collectionobjectattribute': { 'text1': 'some text'}} obj = api.create_obj(self.collection, self.agent, 'collectionobject', data) co = models.Collectionobject.objects.get(id=obj.id) self.assertEqual(set(co.determinations.values_list('number1', flat=True)), set((1, 2))) self.assertEqual(co.collectionobjectattribute.text1, 'some text')
def test_delete_object(self): obj = api.create_obj(self.collection, self.agent, 'collectionobject', { 'collection': api.uri_for_model('collection', self.collection.id), 'catalognumber': 'foobar'}) api.delete_obj(self.agent, 'collectionobject', obj.id, obj.version) self.assertEqual(models.Collectionobject.objects.filter(id=obj.id).count(), 0)