Skip to content

Commit

Permalink
adds other filters; fixes not_found_in_alma
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Nov 18, 2024
1 parent 1c4eec3 commit 95f843c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
18 changes: 18 additions & 0 deletions aim/digifeeds/database/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ def get_items_query(db: Session, filter: schemas.ItemFilters = None):
query = query.filter(
~models.Item.statuses.any(models.ItemStatus.status_name == "in_zephir")
)
elif filter == "pending_deletion":
query = query.filter(
models.Item.statuses.any(
models.ItemStatus.status_name == "pending_deletion"
)
)
elif filter == "not_pending_deletion":
query = query.filter(
~models.Item.statuses.any(
models.ItemStatus.status_name == "pending_deletion"
)
)
elif filter == "not_found_in_alma":
query = query.filter(
models.Item.statuses.any(
models.ItemStatus.status_name == "not_found_in_alma"
)
)
return query


Expand Down
2 changes: 1 addition & 1 deletion aim/digifeeds/database/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ItemFilters(str, Enum):
not_in_zephir = "not_in_zephir"
pending_deletion = "pending_deletion"
not_pending_deletion = "not_pending_deletion"
not_in_alma = "not_in_alma"
not_found_in_alma = "not_found_in_alma"


class ItemCreate(ItemBase):
Expand Down
41 changes: 41 additions & 0 deletions tests/digifeeds/database/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,47 @@ def test_get_items_and_total_not_in_zephir(self, db_session):
assert (items[0]) == item2
assert count == 1

def test_get_items_and_total_pending_deletion(self, db_session):
item1 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode"))
item2 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode2"))
status = get_status(db=db_session, name="pending_deletion")
add_item_status(db=db_session, item=item1, status=status)
items = get_items(db=db_session, filter="pending_deletion", limit=2, offset=0)
count = get_items_total(db=db_session, filter="pending_deletion")
db_session.refresh(item1)
db_session.refresh(item2)
assert (len(items)) == 1
assert (items[0]) == item1
assert count == 1

def test_get_items_and_total_not_pending_deletion(self, db_session):
item1 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode"))
item2 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode2"))
status = get_status(db=db_session, name="pending_deletion")
add_item_status(db=db_session, item=item1, status=status)
items = get_items(
db=db_session, filter="not_pending_deletion", limit=2, offset=0
)
count = get_items_total(db=db_session, filter="pending_deletion")
db_session.refresh(item1)
db_session.refresh(item2)
assert (len(items)) == 1
assert (items[0]) == item2
assert count == 1

def test_get_items_and_total_not_found_in_alma(self, db_session):
item1 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode"))
item2 = add_item(db=db_session, item=ItemCreate(barcode="valid_barcode2"))
status = get_status(db=db_session, name="not_found_in_alma")
add_item_status(db=db_session, item=item1, status=status)
items = get_items(db=db_session, filter="not_found_in_alma", limit=2, offset=0)
count = get_items_total(db=db_session, filter="not_found_in_alma")
db_session.refresh(item1)
db_session.refresh(item2)
assert (len(items)) == 1
assert (items[0]) == item1
assert count == 1

def test_get_status_that_exists(self, db_session):
status = get_status(db=db_session, name="in_zephir")
assert (status.name) == "in_zephir"
Expand Down

0 comments on commit 95f843c

Please sign in to comment.