Fixing a few bugs in preparation for sneak peek.

This commit is contained in:
Roland 2022-01-15 18:05:51 -07:00
parent 064147a769
commit 474e68cc3d
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
8 changed files with 119 additions and 20 deletions

View file

@ -0,0 +1,51 @@
from http import HTTPStatus
from modules.inventory import Item
from modules.inventory.inventory import save_item
def test_delete_items(test_session, init_test_inventory, test_client):
"""
Multiple Items can be deleted in a single request.
"""
item = dict(
brand='Ocean',
name='Salt',
count='8.0',
unit='lbs',
item_size='25.0',
category='cooking ingredients',
subcategory='salt',
)
save_item(init_test_inventory.id, item)
save_item(init_test_inventory.id, item)
items = test_session.query(Item).filter(Item.brand != None).all()
request, response = test_client.delete(f'/api/inventory/item/{items[0].id},{items[1].id}')
assert response.status_code == HTTPStatus.NO_CONTENT, response.status_code
# Refresh all items. Verify they were deleted.
[test_session.refresh(i) for i in items]
assert all([i.deleted_at for i in items])
def test_delete_item(test_session, init_test_inventory, test_client):
"""
An item can be deleted by itself.
"""
item = dict(
brand='Ocean',
name='Salt',
count='8.0',
unit='lbs',
item_size='25.0',
category='cooking ingredients',
subcategory='salt',
)
save_item(init_test_inventory.id, item)
item = test_session.query(Item).filter(Item.brand != None).one()
assert not item.deleted_at
request, response = test_client.delete(f'/api/inventory/item/{item.id}')
assert response.status_code == HTTPStatus.NO_CONTENT, response.status_code
test_session.refresh(item)
assert item.deleted_at

View file

@ -277,7 +277,7 @@ def quantity_to_string(quantity: Quantity) -> str:
]
)
def test_compact_unit(quantity, expected):
# Round the result so we don't have to specify all those zeros for the test definition.
# Round the result, so we don't have to specify all those zeros for the test definition.
assert quantity_to_string(compact_unit(quantity)) == expected
@ -296,7 +296,7 @@ length = gallon.dimensionality
{(('grains',), oz.dimensionality): Decimal('1') * oz},
),
(
# The larger of the units is what is returned.
# The largest of the units is what is returned.
[
{'category': 'grains', 'count': Decimal('1'), 'item_size': Decimal('1'), 'unit': 'oz'},
{'category': 'grains', 'count': Decimal('1'), 'item_size': Decimal('1'), 'unit': 'lbs'},