From a32e30796558fb28a0c1ae301c07bb01cfce50b2 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Mon, 9 Dec 2024 15:55:30 +0000 Subject: [PATCH] adds cli command to process multiple barcodes --- aim/cli/digifeeds.py | 18 ++++++++++++++++++ tests/cli/test_digifeeds.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/aim/cli/digifeeds.py b/aim/cli/digifeeds.py index 0511dba..36a203b 100644 --- a/aim/cli/digifeeds.py +++ b/aim/cli/digifeeds.py @@ -4,6 +4,7 @@ import typer from typing_extensions import Annotated +from typing import List from aim.digifeeds.database import models, main from aim.digifeeds import functions from aim.digifeeds.item import get_item, process_item @@ -146,3 +147,20 @@ def process_barcode( item = get_item(barcode) process_item(item) + + +@app.command() +def process_barcodes( + barcodes: Annotated[ + List[str], + typer.Argument(help="The list of barcodes to run the digifeeds process on"), + ], +): + """ + Runs through the whole process for each of the given barcodes: adding it to + the digifeeds set, checking zephir, and moving the item to the pickup google + drive. + """ + for barcode in barcodes: + item = get_item(barcode) + process_item(item) diff --git a/tests/cli/test_digifeeds.py b/tests/cli/test_digifeeds.py index e2aceb8..98f2f63 100644 --- a/tests/cli/test_digifeeds.py +++ b/tests/cli/test_digifeeds.py @@ -167,3 +167,24 @@ def test_process_barcode(mocker, item_in_zephir_too_recent): assert "in_zephir" in result.stdout assert "not_in_zephir_long_enough" in result.stdout assert result.exit_code == 0 + + +def test_process_barcodes(mocker, item_in_zephir_too_recent): + item1 = Item(item_in_zephir_too_recent) + data2 = item_in_zephir_too_recent.copy() + data2["barcode"] = "other_barcode" + item2 = Item(data2) + + mocker.patch("aim.cli.digifeeds.get_item", side_effect=[item1, item2]) + + result = runner.invoke( + app, ["digifeeds", "process-barcodes", "some_barcode", "other_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 "some_barcode" in result.stdout + assert "other_barcode" in result.stdout + assert result.exit_code == 0