Add Recipes
This commit is contained in:
101
tests/test_22_recipe_service.py
Normal file
101
tests/test_22_recipe_service.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""Test the Product Service Entry Points.
|
||||
|
||||
Simple Grocery List (Sigl) | sigl.app
|
||||
Copyright (c) 2022 Asymworks, LLC. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from sigl.domain.service import (
|
||||
product_create,
|
||||
recipe_addItem,
|
||||
recipe_by_id,
|
||||
recipe_create,
|
||||
)
|
||||
|
||||
# Always use 'app' fixture so ORM gets initialized
|
||||
pytestmark = pytest.mark.usefixtures('app')
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_recipe_create_defaults(session):
|
||||
"""Test newly created Recipes are empty."""
|
||||
lc = recipe_create(session, 'Test')
|
||||
recipe = recipe_by_id(session, lc.id)
|
||||
|
||||
assert recipe.name == 'Test'
|
||||
assert not recipe.entries
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_recipe_add_product_defaults(session):
|
||||
"""Test adding a Product to a Recipe."""
|
||||
recipe = recipe_create(session, 'Test')
|
||||
entry = recipe_addItem(session, recipe.id, productName='Eggs', productCategory='Dairy')
|
||||
|
||||
assert entry.id is not None
|
||||
assert entry.product is not None
|
||||
assert entry.product.name == 'Eggs'
|
||||
assert entry.product.category == 'Dairy'
|
||||
assert entry.product.remember is True
|
||||
|
||||
assert len(recipe.entries) == 1
|
||||
assert recipe.entries[0] == entry
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_recipe_add_product_by_id(session):
|
||||
"""Test adding an existing Product to a Recipe by Id."""
|
||||
p1 = product_create(session, 'Eggs', category='Dairy')
|
||||
|
||||
recipe = recipe_create(session, 'Test')
|
||||
entry = recipe_addItem(session, recipe.id, productId=p1.id)
|
||||
|
||||
assert entry.id is not None
|
||||
assert entry.product is not None
|
||||
assert entry.product.name == 'Eggs'
|
||||
assert entry.product.category == 'Dairy'
|
||||
assert entry.product.remember is True
|
||||
|
||||
assert len(recipe.entries) == 1
|
||||
assert recipe.entries[0] == entry
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_recipe_add_product_by_name(session):
|
||||
"""Test adding an existing Product to a Recipe by Name."""
|
||||
product_create(session, 'Eggs', category='Dairy')
|
||||
|
||||
recipe = recipe_create(session, 'Test')
|
||||
entry = recipe_addItem(session, recipe.id, productName='eggs')
|
||||
|
||||
assert entry.id is not None
|
||||
assert entry.product is not None
|
||||
assert entry.product.name == 'Eggs'
|
||||
assert entry.product.category == 'Dairy'
|
||||
assert entry.product.remember is True
|
||||
|
||||
assert len(recipe.entries) == 1
|
||||
assert recipe.entries[0] == entry
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_recipe_add_product_no_remember(session):
|
||||
"""Test adding a Product to a Recipe without remembering it."""
|
||||
recipe = recipe_create(session, 'Test')
|
||||
entry = recipe_addItem(
|
||||
session,
|
||||
recipe.id,
|
||||
productName='Eggs',
|
||||
productCategory='Dairy',
|
||||
remember=False,
|
||||
)
|
||||
|
||||
assert entry.id is not None
|
||||
assert entry.product is not None
|
||||
assert entry.product.name == 'Eggs'
|
||||
assert entry.product.category == 'Dairy'
|
||||
assert entry.product.remember is False
|
||||
|
||||
assert len(recipe.entries) == 1
|
||||
assert recipe.entries[0] == entry
|
||||
90
tests/test_31_list_recipes.py
Normal file
90
tests/test_31_list_recipes.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""Test the List Recipe Service Entry Points.
|
||||
|
||||
Simple Grocery List (Sigl) | sigl.app
|
||||
Copyright (c) 2022 Asymworks, LLC. All Rights Reserved.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from sigl.domain.service import (
|
||||
list_addItem,
|
||||
list_addRecipe,
|
||||
list_create,
|
||||
product_create,
|
||||
recipe_addItem,
|
||||
recipe_create,
|
||||
)
|
||||
|
||||
# Always use 'app' fixture so ORM gets initialized
|
||||
pytestmark = pytest.mark.usefixtures('app')
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_list_add_recipe_empty(session):
|
||||
"""Test adding a Recipe to an empty list."""
|
||||
pEggs = product_create(session, 'Eggs')
|
||||
|
||||
recipe = recipe_create(session, 'Test Recipe')
|
||||
recipe_addItem(session, recipe.id, productId=pEggs.id, quantity='2', notes='Extra Large')
|
||||
recipe_addItem(session, recipe.id, productName='Milk', quantity='1 cup')
|
||||
|
||||
lc = list_create(session, 'Test')
|
||||
lEntries = list_addRecipe(session, lc.id, recipe.id)
|
||||
|
||||
assert(len(lEntries) == 2)
|
||||
assert(len(lc.entries) == 2)
|
||||
|
||||
assert(lc.entries[0].product.name == 'Eggs')
|
||||
assert(lc.entries[0].quantity == '2')
|
||||
assert(lc.entries[0].notes == 'Extra Large')
|
||||
|
||||
assert(lc.entries[1].product.name == 'Milk')
|
||||
assert(lc.entries[1].quantity == '1 cup')
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_list_add_recipe_merge_quantity(session):
|
||||
"""Test adding a Recipe to a list with existing items, merging quantity."""
|
||||
pEggs = product_create(session, 'Eggs')
|
||||
|
||||
recipe = recipe_create(session, 'Test Recipe')
|
||||
recipe_addItem(session, recipe.id, productId=pEggs.id, quantity='2', notes='Extra Large')
|
||||
recipe_addItem(session, recipe.id, productName='Milk', quantity='1 cup')
|
||||
|
||||
lc = list_create(session, 'Test')
|
||||
list_addItem(session, lc.id, productId=pEggs.id, quantity='12')
|
||||
lEntries = list_addRecipe(session, lc.id, recipe.id)
|
||||
|
||||
assert(len(lEntries) == 2)
|
||||
assert(len(lc.entries) == 2)
|
||||
|
||||
assert(lc.entries[0].product.name == 'Eggs')
|
||||
assert(lc.entries[0].quantity == '12, 2 (Test Recipe)')
|
||||
assert(lc.entries[0].notes == 'Extra Large')
|
||||
|
||||
assert(lc.entries[1].product.name == 'Milk')
|
||||
assert(lc.entries[1].quantity == '1 cup')
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_list_add_recipe_merge_notes(session):
|
||||
"""Test adding a Recipe to a list with existing items, merging notes."""
|
||||
pEggs = product_create(session, 'Eggs')
|
||||
|
||||
recipe = recipe_create(session, 'Test Recipe')
|
||||
recipe_addItem(session, recipe.id, productId=pEggs.id, quantity='2', notes='Extra Large')
|
||||
recipe_addItem(session, recipe.id, productName='Milk', quantity='1 cup')
|
||||
|
||||
lc = list_create(session, 'Test')
|
||||
list_addItem(session, lc.id, productId=pEggs.id, notes='Brown, Cage Free')
|
||||
lEntries = list_addRecipe(session, lc.id, recipe.id)
|
||||
|
||||
assert(len(lEntries) == 2)
|
||||
assert(len(lc.entries) == 2)
|
||||
|
||||
assert(lc.entries[0].product.name == 'Eggs')
|
||||
assert(lc.entries[0].quantity == '2')
|
||||
assert(lc.entries[0].notes == 'Brown, Cage Free\nExtra Large')
|
||||
|
||||
assert(lc.entries[1].product.name == 'Milk')
|
||||
assert(lc.entries[1].quantity == '1 cup')
|
||||
Reference in New Issue
Block a user