def test_replace_lower_priority(importer_test_data): document_cls = current_app_ils.document_record_cls eitem_cls = current_app_ils.eitem_record_cls eitem_search_cls = current_app_ils.eitem_search_cls # setup matched_document = document_cls.get_record_by_pid("docid-6") current_import_eitem = { "urls": [{ "description": "Protected URL", "value": "http://protected-cds-ils.ch/", "login_required": True }, { "description": "Another open URL", "value": "http://cds-ils.ch/", "login_required": True }] } metadata_provider = "springer" IS_PROVIDER_PRIORITY_SENSITIVE = True EITEM_OPEN_ACCESS = False EITEM_URLS_LOGIN_REQUIRED = True eitem_importer_preview = EItemImporter(matched_document, current_import_eitem, metadata_provider, IS_PROVIDER_PRIORITY_SENSITIVE, EITEM_OPEN_ACCESS, EITEM_URLS_LOGIN_REQUIRED) eitem_importer = EItemImporter(matched_document, current_import_eitem, metadata_provider, IS_PROVIDER_PRIORITY_SENSITIVE, EITEM_OPEN_ACCESS, EITEM_URLS_LOGIN_REQUIRED) preview_summary = eitem_importer_preview.preview_import(matched_document) # make sure ebl item exists eitem_cls.get_record_by_pid("eitemid-6") eitem_importer.update_eitems(matched_document) summary = eitem_importer.summary() current_search.flush_and_refresh(index="*") assert len(summary["deleted_eitems"]) == 1 # check if replaced in the import summary assert summary["deleted_eitems"][0]["pid"] == "eitemid-6" assert summary["eitem"]["document_pid"] == "docid-6" # check if deleted with pytest.raises(PIDDeletedError): eitem_cls.get_record_by_pid("eitemid-6") # check if deleted from the index search = eitem_search_cls().search_by_document_pid("docid-6") assert search.count() == 0 # check if preview equals report # this should be the only differing item summary["output_pid"] = "preview-doc-pid" assert preview_summary == summary
def test_import_equal_priority(importer_test_data): document_cls = current_app_ils.document_record_cls eitem_cls = current_app_ils.eitem_record_cls # setup matched_document = document_cls.get_record_by_pid("docid-6A") current_import_eitem = { "urls": [{ "description": "Protected URL", "value": "http://protected-cds-ils.ch/", "login_required": True }, { "description": "Another open URL", "value": "http://cds-ils.ch/", "login_required": True }] } metadata_provider = "ebl" IS_PROVIDER_PRIORITY_SENSITIVE = False EITEM_OPEN_ACCESS = False EITEM_URLS_LOGIN_REQUIRED = True eitem_importer = EItemImporter(matched_document, current_import_eitem, metadata_provider, IS_PROVIDER_PRIORITY_SENSITIVE, EITEM_OPEN_ACCESS, EITEM_URLS_LOGIN_REQUIRED) preview_eitem_importer = EItemImporter(matched_document, current_import_eitem, metadata_provider, IS_PROVIDER_PRIORITY_SENSITIVE, EITEM_OPEN_ACCESS, EITEM_URLS_LOGIN_REQUIRED) preview_summary = preview_eitem_importer.preview_import(matched_document) eitem_importer.update_eitems(matched_document) summary = eitem_importer.summary() assert len(summary["deleted_eitems"]) == 0 # check if replaced in the import summary assert summary["eitem"]["document_pid"] == "docid-6A" # check if safari not deleted eitem_cls.get_record_by_pid("eitemid-6A") # check if new record added eitem_cls.get_record_by_pid(summary["eitem"]["pid"]) # check if preview equals report summary["output_pid"] = "preview-doc-pid" assert preview_summary == summary
def test_do_not_import_lower_priority(importer_test_data): document_cls = current_app_ils.document_record_cls eitem_cls = current_app_ils.eitem_record_cls # setup matched_document = document_cls.get_record_by_pid("docid-7") current_import_eitem = { "urls": [{ "description": "Protected URL", "value": "http://protected-cds-ils.ch/", "login_required": True }, { "description": "Another open URL", "value": "http://cds-ils.ch/", "login_required": True }] } metadata_provider = "ebl" IS_PROVIDER_PRIORITY_SENSITIVE = False EITEM_OPEN_ACCESS = False EITEM_URLS_LOGIN_REQUIRED = True eitem_importer = EItemImporter(matched_document, current_import_eitem, metadata_provider, IS_PROVIDER_PRIORITY_SENSITIVE, EITEM_OPEN_ACCESS, EITEM_URLS_LOGIN_REQUIRED) preview_eitem_importer = EItemImporter(matched_document, current_import_eitem, metadata_provider, IS_PROVIDER_PRIORITY_SENSITIVE, EITEM_OPEN_ACCESS, EITEM_URLS_LOGIN_REQUIRED) preview_summary = preview_eitem_importer.preview_import(matched_document) eitem_importer.update_eitems(matched_document) current_search.flush_and_refresh(index="*") summary = eitem_importer.summary() assert len(summary["deleted_eitems"]) == 0 # check if doing nothing assert summary["eitem"] is None assert summary["action"] == "none" # check if higher priority record not deleted eitem_cls.get_record_by_pid("eitemid-7") # check if preview equals report summary["output_pid"] = "preview-doc-pid" assert preview_summary == summary
def __init__(self, json_data, metadata_provider): """Constructor.""" self.json_data = json_data self.metadata_provider = metadata_provider priority = current_app.config["CDS_ILS_IMPORTER_PROVIDERS"][ metadata_provider ]["priority"] self.document_importer = DocumentImporter( json_data, self.HELPER_METADATA_FIELDS, metadata_provider, self.UPDATE_DOCUMENT_FIELDS, ) self.eitem_importer = EItemImporter( json_data, metadata_provider, priority, self.IS_PROVIDER_PRIORITY_SENSITIVE, self.EITEM_OPEN_ACCESS, self.EITEM_URLS_LOGIN_REQUIRED, ) series_json = json_data.get("_serial", None) self.series_importer = SeriesImporter(series_json, metadata_provider) self.ambiguous_matches = [] self.created = None self.updated = None self.series_list = [] self.fuzzy_matches = []
def __init__(self, json_data, metadata_provider): """Constructor.""" self.json_data = json_data self.metadata_provider = metadata_provider eitem_json_data = self._extract_eitems_json() document_importer_class = self.get_document_importer(metadata_provider) self.document_importer = document_importer_class( json_data, self.HELPER_METADATA_FIELDS, metadata_provider, self.UPDATE_DOCUMENT_FIELDS, ) self.eitem_importer = EItemImporter( json_data, eitem_json_data, metadata_provider, self.IS_PROVIDER_PRIORITY_SENSITIVE, self.EITEM_OPEN_ACCESS, self.EITEM_URLS_LOGIN_REQUIRED, ) series_json = json_data.get("_serial", None) self.series_importer = SeriesImporter(series_json, metadata_provider)