def test_list_collection_resources(self):
        ims_cli = self.ims_cli
        rr_cli = self.rr_cli
        #========================================
        # Resource Pool
        #========================================
        resources = [
            InformationResource(name='bean_counter'),
            InformationResource(name='lunar_rock'),
            InformationResource('aperature'),
            InformationResource('lemons')
        ]

        resources = [rr_cli.create(i)[0] for i in resources]

        collection = Collection(name='park_bench')

        collection_id = ims_cli.create_collection(name='park_bench',
                                                  resources=resources)
        retval = ims_cli.list_collection_resources(collection_id, id_only=True)

        retval.sort()
        resources.sort()

        self.assertTrue(retval == resources, '%s != %s' % (retval, resources))
 def test_read_collection(self):
     ims_cli = self.ims_cli
     rr_cli = self.rr_cli
     collection = Collection(name='working_collection')
     collection_id, _ = rr_cli.create(collection)
     collection = ims_cli.read_collection(collection_id)
     self.assertTrue(collection.name == 'working_collection')
    def test_update_collection(self):
        ims_cli = self.ims_cli
        rr_cli = self.rr_cli

        collection = Collection(name='useful_collection')
        collection_id, _ = rr_cli.create(collection)
        collection = rr_cli.read(collection_id)
        collection.name = 'nub'
        ims_cli.update_collection(collection)
        collection = rr_cli.read(collection_id)
        self.assertTrue(collection.name == 'nub')
示例#4
0
    def test_delete_collection(self):
        ims_cli = self.ims_cli
        rr_cli = self.rr_cli

        collection = Collection(name='nub')
        collection_id, _ = rr_cli.create(collection)

        ims_cli.delete_collection(collection_id)

        with self.assertRaises(NotFound):
            rr_cli.read(collection_id)
    def test_find_collection(self):
        self.rr_find_resources.return_value = (['test'], [])

        retval = self.index_management.find_collection(collection_name='hi')
        self.assertTrue(retval == ['test'], '%s' % retval)

        fake_collection = Collection(resources=['test_res_id'])
        fake_assoc = Association(s='test_id')
        self.rr_find_assocs.return_value = [fake_assoc]

        retval = self.index_management.find_collection(
            resource_ids=['test_res_id'])
        self.assertTrue(retval == ['test_id'], '%s' % retval)

        with self.assertRaises(BadRequest):
            self.index_management.find_collection()
    def create_collection(self, name='', resources=None):
        res, _ = self.clients.resource_registry.find_resources(name=name)
        if len(res) > 0:
            raise BadRequest('Resource with name %s already exists.' % name)

        if resources is None:
            raise BadRequest('No resources provided to make collection.')

        validate_true(
            len(resources) > 0, 'No resources provided to make collection.')

        collection = Collection(name=name)
        collection_id, _ = self.clients.resource_registry.create(collection)
        for resource in resources:
            self.clients.resource_registry.create_association(
                subject=collection_id,
                predicate=PRED.hasElement,
                object=resource)

        return collection_id
 def test_update_collection(self):
     with self.assertRaises(BadRequest):
         ind = Index()
         self.index_management.update_collection(ind)
     self.index_management.update_collection(Collection())
     self.assertTrue(self.rr_update.called)