91 lines
2.9 KiB
Python
91 lines
2.9 KiB
Python
"""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')
|