def test_transform_oai_record_catch_key_error(self): # Arrange del self.data[0]['identifier'] # Act + Assert with self.assertRaises(Exception): transform_operations.transform_dict_record_to_oai_record(self.data)
def test_transform_oai_record_return_list_object(self): # Act result = transform_operations.transform_dict_record_to_oai_record( self.data) # Assert self.assertTrue(all(isinstance(item, OaiRecord) for item in result))
def _harvest_records(registry, metadata_format, last_update, registry_all_sets, set_=None): """ Harvests records. Args: registry: Registry to harvest. metadata_format: Metadata Format to harvest. last_update: Last update date. registry_all_sets: List of all sets. set_: Set to harvest Returns: List of potential errors. """ errors = [] has_data = True resumption_token = None # Get all records. Use of the resumption token. while has_data: # Get the list of records set_h = None if set_ is not None: set_h = set_.set_spec http_response, resumption_token = oai_verbs_api.list_records( url=registry.url, metadata_prefix=metadata_format.metadata_prefix, set_h=set_h, from_date=last_update, resumption_token=resumption_token) if http_response.status_code == status.HTTP_200_OK: try: list_oai_record = transform_operations.transform_dict_record_to_oai_record( http_response.data, registry_all_sets) for oai_record in list_oai_record: _upsert_record_for_registry(oai_record, metadata_format, registry) except Exception as e: errors.append({ 'status_code': status.HTTP_400_BAD_REQUEST, 'error': e.message }) # Else, we get the status code with the error message provided by the http_response else: error = { 'status_code': http_response.status_code, 'error': http_response.data[oai_pmh_exceptions.OaiPmhMessage.label] } errors.append(error) # There is more records if we have a resumption token. has_data = resumption_token is not None and resumption_token != '' return errors
def mock_oai_record(version=1): with open( os.path.join(DUMP_OAI_PMH_TEST_PATH, 'oai_record_v{0}.json'.format(version))) as f: data = f.read() data_json = json.loads(data) list_records = transform_operations.transform_dict_record_to_oai_record( data_json) return list_records