def test_update_object_with_more_inlines(self): for i in range(6): self.collectionobjects[0].determinations.create( collectionmemberid=self.collection.id, number1=i) data = api.get_resource('collectionobject', self.collectionobjects[0].id) even_dets = [ d for d in data['determinations'] if d['number1'] % 2 == 0 ] for d in even_dets: data['determinations'].remove(d) data['collectionobjectattribute'] = {'text1': 'look! an attribute'} api.update_obj(self.collection, self.agent, 'collectionobject', data['id'], data['version'], data) obj = models.Collectionobject.objects.get( id=self.collectionobjects[0].id) self.assertEqual(obj.determinations.count(), 3) for d in obj.determinations.all(): self.assertFalse(d.number1 % 2 == 0) self.assertEqual(obj.collectionobjectattribute.text1, 'look! an attribute')
def test_update_object(self): data = api.get_resource('collection', self.collection.id) data['collectionname'] = 'New Name' api.update_obj(self.collection, self.agent, 'collection', data['id'], data['version'], data) obj = models.Collection.objects.get(id=self.collection.id) self.assertEqual(obj.collectionname, 'New Name')
def test_update_object_with_inlines(self): self.collectionobjects[0].determinations.create( collectionmemberid=self.collection.id, number1=1, remarks='original value') data = api.get_resource('collectionobject', self.collectionobjects[0].id) data['determinations'][0]['remarks'] = 'changed value' data['determinations'].append({ 'number1': 2, 'remarks': 'a new determination' }) data['collectionobjectattribute'] = {'text1': 'added an attribute'} api.update_obj(self.collection, self.agent, 'collectionobject', data['id'], data['version'], data) obj = models.Collectionobject.objects.get( id=self.collectionobjects[0].id) self.assertEqual(obj.determinations.count(), 2) self.assertEqual( obj.determinations.get(number1=1).remarks, 'changed value') self.assertEqual( obj.determinations.get(number1=2).remarks, 'a new determination') self.assertEqual(obj.collectionobjectattribute.text1, 'added an attribute')
def test_missing_version(self): data = api.get_resource('collection', self.collection.id) data['collectionname'] = 'New Name' self.collection.version += 1 self.collection.save() with self.assertRaises(api.MissingVersionException) as cm: api.update_obj(self.collection, self.agent, 'collection', data['id'], None, data)
def test_update_object(self): data = api.get_resource('collection', self.collection.id) data['collectionname'] = 'New Name' self.collection.version += 1 self.collection.save() with self.assertRaises(api.StaleObjectException) as cm: api.update_obj(self.collection, self.agent, 'collection', data['id'], data['version'], data) data = api.get_resource('collection', self.collection.id) self.assertNotEqual(data['collectionname'], 'New Name')
def test_update_object(self): data = api.get_resource('collectionobject', self.collectionobjects[0].id, self.recordset.id) self.assertEqual(data['recordset_info'], None) obj = api.update_obj(self.collection, self.agent, 'collectionobject', data['id'], data['version'], data)
def test_update_object_with_more_inlines(self): for i in range(6): self.collectionobjects[0].determinations.create( collectionmemberid=self.collection.id, number1=i) data = api.get_resource('collectionobject', self.collectionobjects[0].id) even_dets = [d for d in data['determinations'] if d['number1'] % 2 == 0] for d in even_dets: data['determinations'].remove(d) data['collectionobjectattribute'] = {'text1': 'look! an attribute'} api.update_obj(self.collection, self.agent, 'collectionobject', data['id'], data['version'], data) obj = models.Collectionobject.objects.get(id=self.collectionobjects[0].id) self.assertEqual(obj.determinations.count(), 3) for d in obj.determinations.all(): self.assertFalse(d.number1 % 2 == 0) self.assertEqual(obj.collectionobjectattribute.text1, 'look! an attribute')
def test_update_object_with_inlines(self): self.collectionobjects[0].determinations.create( collectionmemberid=self.collection.id, number1=1, remarks='original value') data = api.get_resource('collectionobject', self.collectionobjects[0].id) data['determinations'][0]['remarks'] = 'changed value' data['determinations'].append({ 'number1': 2, 'remarks': 'a new determination'}) data['collectionobjectattribute'] = { 'text1': 'added an attribute'} api.update_obj(self.collection, self.agent, 'collectionobject', data['id'], data['version'], data) obj = models.Collectionobject.objects.get(id=self.collectionobjects[0].id) self.assertEqual(obj.determinations.count(), 2) self.assertEqual(obj.determinations.get(number1=1).remarks, 'changed value') self.assertEqual(obj.determinations.get(number1=2).remarks, 'a new determination') self.assertEqual(obj.collectionobjectattribute.text1, 'added an attribute')
def test_bump_version(self): data = api.get_resource('collection', self.collection.id) data['collectionname'] = 'New Name' obj = api.update_obj(self.collection, self.agent, 'collection', data['id'], data['version'], data) self.assertEqual(obj.version, data['version'] + 1)