Skip to content

Commit

Permalink
adds cli command to process multiple barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Dec 9, 2024
1 parent dc40696 commit a32e307
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions aim/cli/digifeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
21 changes: 21 additions & 0 deletions tests/cli/test_digifeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a32e307

Please sign in to comment.