diff --git a/ils_middleware/dags/stanford_folio.py b/ils_middleware/dags/stanford_folio.py index 4efefe5..e6dedd8 100644 --- a/ils_middleware/dags/stanford_folio.py +++ b/ils_middleware/dags/stanford_folio.py @@ -6,7 +6,6 @@ from airflow.operators.python import PythonOperator from airflow.utils.task_group import TaskGroup -from ils_middleware.tasks.amazon.s3 import get_from_s3, send_to_s3 from ils_middleware.tasks.amazon.sqs import SubscribeOperator, parse_messages from ils_middleware.tasks.sinopia.local_metadata import new_local_admin_metadata @@ -16,7 +15,8 @@ ) from ils_middleware.tasks.sinopia.login import sinopia_login -from ils_middleware.tasks.sinopia.metadata_check import existing_metadata_check + +# from ils_middleware.tasks.sinopia.metadata_check import existing_metadata_check from ils_middleware.tasks.folio.build import build_records from ils_middleware.tasks.folio.login import FolioLogin from ils_middleware.tasks.folio.graph import construct_graph diff --git a/ils_middleware/tasks/folio/build.py b/ils_middleware/tasks/folio/build.py index bed6f96..39f92df 100644 --- a/ils_middleware/tasks/folio/build.py +++ b/ils_middleware/tasks/folio/build.py @@ -18,7 +18,6 @@ def _default_transform(**kwargs) -> tuple: folio_field = kwargs["folio_field"] values = kwargs.get("values", []) - logger.debug(f"field: {folio_field} values: {values} type: {type(values)}") return folio_field, values @@ -119,29 +118,29 @@ def _instance_type_id(**kwargs) -> tuple: raise ValueError(f"instanceTypeId for {name} not found") return "instanceTypeId", ident + def _folio_hrid(folio_client: FolioClient) -> str: """Queries for instance hrid, increments, and saves back to folio""" endpoint = "/hrid-settings-storage/hrid-settings" hrid_settings = folio_client.folio_get_single_object(endpoint) - instance_count = hrid_settings['instances']['startNumber'] + instance_count = hrid_settings["instances"]["startNumber"] new_instance_count = instance_count + 1 - if hrid_settings['commonRetainLeadingZeroes']: + if hrid_settings["commonRetainLeadingZeroes"]: number = str(new_instance_count).zfill(11) else: number = new_instance_count instance_hrid = f"{hrid_settings['instances']['prefix']}{number}" - hrid_settings['instances']['startNumber'] = new_instance_count + hrid_settings["instances"]["startNumber"] = new_instance_count # Puts new instance startNumber back into FOLIO - hrid_put_result = requests.put(f"{folio_client.okapi_url}{endpoint}", - headers=folio_client.okapi_headers) + hrid_put_result = requests.put( + f"{folio_client.okapi_url}{endpoint}", headers=folio_client.okapi_headers + ) hrid_put_result.raise_for_status() return instance_hrid - - def _language(**kwargs) -> tuple: values = kwargs["values"] diff --git a/tests/tasks/folio/test_build.py b/tests/tasks/folio/test_build.py index ee90939..890db05 100644 --- a/tests/tasks/folio/test_build.py +++ b/tests/tasks/folio/test_build.py @@ -72,6 +72,18 @@ def __init__(self, *args): {"id": "6a2533a7-4de2-4e64-8466-074c2fa9308c", "name": "General note"}, ] + self.okapi_headers = {"tenant": "sul"} + self.okapi_url = "https://okapi.edu" + + def folio_get_single_object(self, endpoint): + match endpoint: + + case "/hrid-settings-storage/hrid-settings": + return { + "instances": {"startNumber": 1, "prefix": "i"}, + "commonRetainLeadingZeroes": True, + } + @pytest.fixture def mock_folio_client(monkeypatch): @@ -94,7 +106,7 @@ def test_happypath_build_records( ) record = test_task_instance().xcom_pull(key=instance_uri) - assert record["hrid"].startswith(instance_uri) + assert record["hrid"] == "i00000000002" assert record["metadata"]["createdByUserId"].startswith( "21eaac74-1b29-5546-a13b-bc2e7e4717c6" ) @@ -164,7 +176,7 @@ def test_instance_format_ids(mock_task_instance): # noqa: F811 assert (format_ids[1][0]).startswith("8d511d33-5e85-4c5d-9bce-6e3c9cd0c324") -def test_inventory_record(mock_task_instance): # noqa: F811 +def test_inventory_record(mock_task_instance, mock_requests_okapi): # noqa: F811 record = _inventory_record( instance_uri=instance_uri, task_instance=test_task_instance(), @@ -174,11 +186,12 @@ def test_inventory_record(mock_task_instance): # noqa: F811 username="test_user", tenant="sul", ) - assert record["hrid"].startswith(instance_uri) + assert record["hrid"].startswith("i00000000002") def test_inventory_record_existing_metadata( mock_task_instance, # noqa: F811 + mock_requests_okapi, # noqa ): # noqa: F811 metadata = { "createdDate": "2021-12-06T15:45:28.140795", @@ -193,7 +206,7 @@ def test_inventory_record_existing_metadata( folio_client=MockFolioClient(), metadata=metadata, ) - assert record["hrid"].startswith(instance_uri) + assert record["hrid"].startswith("i00000000002") assert record["metadata"]["createdDate"].startswith("2021-12-06T15:45:28.140795")