Skip to content

Commit

Permalink
add cli method for doing all the processing on a barcode
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Dec 6, 2024
1 parent 52b4941 commit cf65049
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
18 changes: 17 additions & 1 deletion aim/cli/digifeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion aim/digifeeds/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
25 changes: 25 additions & 0 deletions tests/cli/test_digifeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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"
Expand Down Expand Up @@ -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

0 comments on commit cf65049

Please sign in to comment.