Exemple #1
0
 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')
Exemple #2
0
 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')
Exemple #3
0
    def test_get_resource_with_recordset_info(self):
        data = api.get_resource('collectionobject', self.collectionobjects[0].id)
        self.assertFalse(hasattr(data, 'recordset_info'))

        data = api.get_resource('collectionobject', self.collectionobjects[0].id, self.recordset.id)
        self.assertEqual(data['recordset_info'], None)

        self.recordset.recordsetitems.create(recordid=self.collectionobjects[0].id)

        data = api.get_resource('collectionobject', self.collectionobjects[0].id, self.recordset.id)
        self.assertEqual(data['recordset_info']['recordsetid'], self.recordset.id)
Exemple #4
0
 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')
Exemple #5
0
    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')
Exemple #6
0
    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')
Exemple #7
0
 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')
Exemple #8
0
 def test_get_resource_with_to_one_inlines(self):
     self.collectionobjects[0].collectionobjectattribute = \
         models.Collectionobjectattribute.objects.create(collectionmemberid=self.collection.id)
     self.collectionobjects[0].save()
     data = api.get_resource('collectionobject', self.collectionobjects[0].id)
     self.assertTrue(isinstance(data['collectionobjectattribute'], dict))
     self.assertEqual(data['collectionobjectattribute']['id'],
                      self.collectionobjects[0].collectionobjectattribute.id)
Exemple #9
0
 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)
Exemple #10
0
 def test_get_to_many_uris_with_special_othersidename(self):
     data = api.get_resource('agent', self.agent.id)
     self.assertEqual(data['collectors'],
                      api.uri_for_model('collector') +
                      '?agent=%d' % self.agent.id)
     self.assertEqual(data['orgmembers'],
                      api.uri_for_model('agent') +
                      '?organization=%d' % self.agent.id)
Exemple #11
0
 def test_get_to_many_uris_with_special_othersidename(self):
     data = api.get_resource('agent', self.agent.id)
     self.assertEqual(
         data['collectors'],
         api.uri_for_model('collector') + '?agent=%d' % self.agent.id)
     self.assertEqual(
         data['orgmembers'],
         api.uri_for_model('agent') + '?organization=%d' % self.agent.id)
Exemple #12
0
 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)
Exemple #13
0
    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)
Exemple #14
0
    def test_get_resource_with_recordset_info(self):
        data = api.get_resource('collectionobject',
                                self.collectionobjects[0].id)
        self.assertFalse(hasattr(data, 'recordset_info'))

        data = api.get_resource('collectionobject',
                                self.collectionobjects[0].id,
                                self.recordset.id)
        self.assertEqual(data['recordset_info'], None)

        self.recordset.recordsetitems.create(
            recordid=self.collectionobjects[0].id)

        data = api.get_resource('collectionobject',
                                self.collectionobjects[0].id,
                                self.recordset.id)
        self.assertEqual(data['recordset_info']['recordsetid'],
                         self.recordset.id)
Exemple #15
0
 def test_get_resource_with_to_one_inlines(self):
     self.collectionobjects[0].collectionobjectattribute = \
         models.Collectionobjectattribute.objects.create(collectionmemberid=self.collection.id)
     self.collectionobjects[0].save()
     data = api.get_resource('collectionobject',
                             self.collectionobjects[0].id)
     self.assertTrue(isinstance(data['collectionobjectattribute'], dict))
     self.assertEqual(
         data['collectionobjectattribute']['id'],
         self.collectionobjects[0].collectionobjectattribute.id)
Exemple #16
0
 def test_get_resource_with_to_many_inlines(self):
     for i in range(3):
         self.collectionobjects[0].determinations.create(
             iscurrent=False, number1=i)
     data = api.get_resource('collectionobject', self.collectionobjects[0].id)
     self.assertTrue(isinstance(data['determinations'], list))
     self.assertEqual(len(data['determinations']), 3)
     ids = [d['id'] for d in data['determinations']]
     for det in self.collectionobjects[0].determinations.all():
         self.assertTrue(det.id in ids)
Exemple #17
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)
Exemple #18
0
 def test_get_resource_with_to_many_inlines(self):
     for i in range(3):
         self.collectionobjects[0].determinations.create(iscurrent=False,
                                                         number1=i)
     data = api.get_resource('collectionobject',
                             self.collectionobjects[0].id)
     self.assertTrue(isinstance(data['determinations'], list))
     self.assertEqual(len(data['determinations']), 3)
     ids = [d['id'] for d in data['determinations']]
     for det in self.collectionobjects[0].determinations.all():
         self.assertTrue(det.id in ids)
Exemple #19
0
    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)
Exemple #20
0
    def test_get_to_many_uris_with_special_othersidename(self):
        data = api.get_resource('agent', self.agent.id)

        # This one is actually a regular othersidename
        self.assertEqual(
            data['collectors'],
            api.uri_for_model('collector') + '?agent=%d' % self.agent.id)

        # This one is the special otherside name ("organization" instead of "agent")
        self.assertEqual(
            data['orgmembers'],
            api.uri_for_model('agent') + '?organization=%d' % self.agent.id)
Exemple #21
0
    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)
Exemple #22
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_resource(self.agent, 'collectionobject', data['id'],
                             data['version'])
     self.assertEqual(
         models.Collectionobject.objects.filter(id=obj.id).count(), 1)
Exemple #23
0
    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')
Exemple #24
0
    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')
Exemple #25
0
 def test_get_resouce(self):
     data = api.get_resource('institution', self.institution.id)
     self.assertEqual(data['id'], self.institution.id)
     self.assertEqual(data['name'], self.institution.name)
Exemple #26
0
 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)
Exemple #27
0
 def test_get_to_many_uris_with_regular_othersidename(self):
     data = api.get_resource('agent', self.agent.id)
     self.assertEqual(data['agentattachments'],
                      api.uri_for_model('agentattachment') +
                      '?agent=%d' % self.agent.id)
Exemple #28
0
 def test_get_resouce(self):
     data = api.get_resource('institution', self.institution.id)
     self.assertEqual(data['id'], self.institution.id)
     self.assertEqual(data['name'], self.institution.name)
Exemple #29
0
 def test_get_to_many_uris_with_regular_othersidename(self):
     data = api.get_resource('agent', self.agent.id)
     self.assertEqual(
         data['agentattachments'],
         api.uri_for_model('agentattachment') + '?agent=%d' % self.agent.id)
Exemple #30
0
    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)
Exemple #31
0
 def test_get_to_many_uris_with_regular_othersidename(self):
     data = api.get_resource('collectingevent', self.collectingevent.id)
     self.assertEqual(
         data['collectionobjects'],
         api.uri_for_model('collectionobject') +
         '?collectingevent=%d' % self.collectingevent.id)
Exemple #32
0
 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)