102 lines
2.8 KiB
Python
102 lines
2.8 KiB
Python
"""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
|