From 32a79ddda71342b46b24d9f6f718ad153f93e90a Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 6 Dec 2024 16:18:41 +0000 Subject: [PATCH] cli check_zephir uses Item check_zephir method --- aim/cli/digifeeds.py | 5 ++- aim/digifeeds/functions.py | 13 ------ tests/cli/test_digifeeds.py | 2 +- tests/digifeeds/test_check_zephir.py | 67 ---------------------------- 4 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 tests/digifeeds/test_check_zephir.py diff --git a/aim/cli/digifeeds.py b/aim/cli/digifeeds.py index e05a697..7abfde4 100644 --- a/aim/cli/digifeeds.py +++ b/aim/cli/digifeeds.py @@ -74,8 +74,9 @@ def check_zephir( """ print(f"Checking Zephir for {barcode}") - item = functions.check_zephir(barcode) - if item: + item = get_item(barcode) + result = item.check_zephir() + if result: S.logger.info("in_zephir", message="Item is in zephir", barcode=barcode) else: S.logger.info("not_in_zephir", message="Item is NOT in zephir", barcode=barcode) diff --git a/aim/digifeeds/functions.py b/aim/digifeeds/functions.py index 21bd919..0456a39 100644 --- a/aim/digifeeds/functions.py +++ b/aim/digifeeds/functions.py @@ -44,16 +44,3 @@ def list_barcodes_in_input_bucket(): response = s3.list_objects_v2(Bucket=S.digifeeds_s3_bucket, Prefix=prefix) barcodes = [Path(object["Key"]).stem for object in response["Contents"]] return barcodes - - -def check_zephir(barcode: str): - item = Item(DBClient().get_or_add_item(barcode)) - if item.has_status("in_zephir"): - return item - - response = requests.get(f"{S.zephir_bib_api_url}/mdp.{barcode}") - if response.status_code == 200: - DBClient().add_item_status(barcode=barcode, status="in_zephir") - return item - else: - return None diff --git a/tests/cli/test_digifeeds.py b/tests/cli/test_digifeeds.py index c87ef60..884bc1d 100644 --- a/tests/cli/test_digifeeds.py +++ b/tests/cli/test_digifeeds.py @@ -58,7 +58,7 @@ def test_add_to_db_where_item_is_not_in_digifeeds_set(item_data): assert "added_to_digifeeds_set" in result.stdout -def test_add_to_db_where_item_is_not_in_alma(item_data, mocker): +def test_add_to_db_where_item_is_not_in_alma(mocker): item_mock = mocker.MagicMock(Item) item_mock.has_status.side_effect = [True, False] item_mock.add_to_digifeeds_set.return_value = item_mock diff --git a/tests/digifeeds/test_check_zephir.py b/tests/digifeeds/test_check_zephir.py deleted file mode 100644 index 3afcadb..0000000 --- a/tests/digifeeds/test_check_zephir.py +++ /dev/null @@ -1,67 +0,0 @@ -import pytest -import responses -import json -from aim.services import S -from aim.digifeeds import functions -from aim.digifeeds.functions import check_zephir - - -@pytest.fixture -def item_data(): - with open("tests/fixtures/digifeeds/item.json") as f: - output = json.load(f) - return output - - -@pytest.fixture -def barcode(): - return "some_barcode" - - -@responses.activate -def test_barcode_is_in_zephir(mocker, item_data, barcode): - get_item_mock = mocker.patch.object( - functions.DBClient, "get_or_add_item", return_value=item_data - ) - add_status_mock = mocker.patch.object( - functions.DBClient, "add_item_status", return_value=item_data - ) - - responses.get(f"{S.zephir_bib_api_url}/mdp.{barcode}", json={}, status=200) - result = check_zephir(barcode) - get_item_mock.assert_called_once() - add_status_mock.assert_called_once() - assert result.barcode == barcode - - -def test_barcode_already_has_in_zephir_status(mocker, item_data, barcode): - item_data["statuses"][0]["name"] = "in_zephir" - get_item_mock = mocker.patch.object( - functions.DBClient, "get_or_add_item", return_value=item_data - ) - - add_status_mock = mocker.patch.object( - functions.DBClient, "add_item_status", return_value=item_data - ) - - result = check_zephir(barcode) - get_item_mock.assert_called_once() - add_status_mock.assert_not_called() - assert result.barcode == barcode - - -@responses.activate -def test_barcode_not_in_zephir(mocker, item_data, barcode): - get_item_mock = mocker.patch.object( - functions.DBClient, "get_or_add_item", return_value=item_data - ) - - add_status_mock = mocker.patch.object( - functions.DBClient, "add_item_status", return_value=item_data - ) - - responses.get(f"{S.zephir_bib_api_url}/mdp.{barcode}", json={}, status=404) - result = check_zephir(barcode) - get_item_mock.assert_called_once() - add_status_mock.assert_not_called() - assert result is None