From cf650499a5c439569baba260f144ad399c86f496 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 6 Dec 2024 20:53:14 +0000 Subject: [PATCH] add cli method for doing all the processing on a barcode --- aim/cli/digifeeds.py | 18 +++++++++++++++++- aim/digifeeds/item.py | 2 +- tests/cli/test_digifeeds.py | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/aim/cli/digifeeds.py b/aim/cli/digifeeds.py index 9746d42..0511dba 100644 --- a/aim/cli/digifeeds.py +++ b/aim/cli/digifeeds.py @@ -6,7 +6,7 @@ from typing_extensions import Annotated from aim.digifeeds.database import models, main from aim.digifeeds import functions -from aim.digifeeds.item import get_item +from aim.digifeeds.item import get_item, process_item from aim.services import S import json @@ -130,3 +130,19 @@ def move_to_pickup( message="Item has been successfully moved to pickup", barcode=barcode, ) + + +@app.command() +def process_barcode( + barcode: Annotated[ + str, + typer.Argument(help="The barcode to run the digifeeds process on"), + ], +): + """ + Runs through the whole process for a barcode: adding it to the digifeeds set, + checking zephir, and moving the item to the pickup google drive. + """ + + item = get_item(barcode) + process_item(item) diff --git a/aim/digifeeds/item.py b/aim/digifeeds/item.py index 29f5891..8ef2a20 100644 --- a/aim/digifeeds/item.py +++ b/aim/digifeeds/item.py @@ -142,7 +142,7 @@ def in_zephir_for_long_enough(self) -> bool: return False -def get_item(barcode: str) -> Item: +def get_item(barcode: str) -> None: return Item(DBClient().get_or_add_item(barcode)) diff --git a/tests/cli/test_digifeeds.py b/tests/cli/test_digifeeds.py index 6cc60d3..e2aceb8 100644 --- a/tests/cli/test_digifeeds.py +++ b/tests/cli/test_digifeeds.py @@ -7,6 +7,7 @@ from aim.services import S from aim.digifeeds.item import Item from aim.digifeeds import functions +from datetime import datetime runner = CliRunner() @@ -18,6 +19,17 @@ def item_data(): return output +@pytest.fixture +def item_in_zephir_too_recent(item_data): + zephir_status = { + "name": "in_zephir", + "description": "Item is in zephir", + "created_at": datetime.now().isoformat(timespec="seconds"), + } + item_data["statuses"].append(zephir_status) + return item_data + + @responses.activate def test_add_to_db_where_item_is_not_in_digifeeds_set(item_data): item_data["statuses"][0]["name"] = "in_zephir" @@ -142,3 +154,16 @@ def test_move_to_pickup_where_not_in_zephir(mocker): assert "not_in_zephir_long_enough" in result.stdout assert result.exit_code == 0 + + +def test_process_barcode(mocker, item_in_zephir_too_recent): + item = Item(item_in_zephir_too_recent) + mocker.patch("aim.cli.digifeeds.get_item", return_value=item) + + result = runner.invoke(app, ["digifeeds", "process-barcode", "some_barcode"]) + + assert "add_to_digifeeds_set_start" in result.stdout + assert "added_to_digifeeds_set" in result.stdout + assert "in_zephir" in result.stdout + assert "not_in_zephir_long_enough" in result.stdout + assert result.exit_code == 0