コード例 #1
0
    def reimport_dataset(self, dataset_ids):
        '''Reimport all datasets in dataset_ids.'''

        fb_controller = controller.FISBrokerController()
        context = {'model': model, 'session': model.Session}
        result = fb_controller.reimport_batch(dataset_ids, context)

        return result
コード例 #2
0
    def test_reimport_batch_raise_error_if_no_fb_havester_defined(self):
        '''Calling reimport_batch when there is not FIS-Broker harvester
           defined should result in an error.'''

        fb_controller = controller.FISBrokerController()

        package_ids = []
        with assert_raises(NoFBHarvesterDefined):
            fb_controller.reimport_batch(package_ids, self.context)
コード例 #3
0
    def test_reimport_batch_raise_error_for_nonexisting_package(self):
        '''A batch reimport containing a package_id which doesn't exist should
           trigger a PackageIdDoesNotExistError.'''

        # FIS-Broker harvester needs to exist, or reimport won't work
        self._create_source()

        fb_controller = controller.FISBrokerController()

        package_ids = ['dunk']
        with assert_raises(PackageIdDoesNotExistError):
            fb_controller.reimport_batch(package_ids, self.context)
コード例 #4
0
    def test_raise_error_for_failed_getrecordbyid_request(self):
        '''A reimport should fail with a NoConnectionError when the
           getrecordbyid-Request failed with a timeout.'''

        fb_controller = controller.FISBrokerController()
        fb_dataset_dict, source, job = self._harvester_setup(
            FISBROKER_HARVESTER_CONFIG, fb_guid='cannot_connect')
        package_update(self.context, fb_dataset_dict)
        package_id = fb_dataset_dict['id']

        package_ids = [package_id]
        with assert_raises(NoConnectionError):
            fb_controller.reimport_batch(package_ids, self.context)
コード例 #5
0
    def test_reimport_batch_raise_error_for_package_without_fb_guid(self):
        '''A batch reimport containing a package which doesn't have a FIS-Broker guid
           should trigger a NoFisbrokerIdError.'''

        fb_controller = controller.FISBrokerController()
        fb_dataset_dict, source, job = self._harvester_setup(
            FISBROKER_HARVESTER_CONFIG, fb_guid=None)
        # datasets created in this way have no extras set, so also no 'guid'
        package_id = fb_dataset_dict['id']

        package_ids = [package_id]
        with assert_raises(NoFisbrokerIdError):
            fb_controller.reimport_batch(package_ids, self.context)
コード例 #6
0
    def test_reimport_batch_raise_error_for_nonharvested_package(self):
        '''A batch reimport containing a package which wasn't harvested should
           trigger a PackageNotHarvestedError.'''

        # FIS-Broker harvester needs to exist, or reimport won't work
        self._create_source()

        fb_controller = controller.FISBrokerController()
        non_fb_dataset_dict = ckan_factories.Dataset()
        package_id = non_fb_dataset_dict['id']

        package_ids = [package_id]
        with assert_raises(PackageNotHarvestedError):
            fb_controller.reimport_batch(package_ids, self.context)
コード例 #7
0
    def test_reimport_batch_raises_no_connection_error(self):
        '''A batch reimport show trigger a NoConnectionError if a connection to
           FIS-Broker cannot be established.'''

        fb_controller = controller.FISBrokerController()
        unreachable_config = {
            'title': 'Unreachable FIS-Broker Harvest Source',
            'name': 'unreachable-fis-broker-harvest-source',
            'source_type': HARVESTER_ID,
            'url': "http://somewhere.over.the.ra.invalid/csw"
        }
        fb_dataset_dict, source, job = self._harvester_setup(
            unreachable_config)
        package_update(self.context, fb_dataset_dict)
        package_id = fb_dataset_dict['id']

        package_ids = [package_id]
        with assert_raises(NoConnectionError):
            fb_controller.reimport_batch(package_ids, self.context)
コード例 #8
0
    def test_reimport_batch_raise_error_for_package_not_harvested_by_fbharvester(
            self):
        '''A batch reimport containing a package which wasn't harvested by ckanext-fisbroker
           should trigger a PackageNotHarvestedInFisbrokerError.'''

        # FIS-Broker harvester needs to exist, or reimport won't work
        self._create_source()

        fb_controller = controller.FISBrokerController()
        harvester_config = {
            'title': 'Dummy Harvester',
            'name': 'dummy-harvester',
            'source_type': 'dummyharvest',
            'url': "http://test.org/csw"
        }
        dataset_dict, source, job = self._harvester_setup(harvester_config)
        package_id = dataset_dict['id']

        package_ids = [package_id]
        with assert_raises(PackageNotHarvestedInFisbrokerError):
            fb_controller.reimport_batch(package_ids, self.context)