63 lines
1.8 KiB
Python
63 lines
1.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_by_id, product_create, products_all
|
|
|
|
# Always use 'app' fixture so ORM gets initialized
|
|
pytestmark = pytest.mark.usefixtures('app')
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_product_create_defaults(session):
|
|
"""Test newly created Products have no Locations."""
|
|
pc = product_create(session, 'Eggs', category='Dairy')
|
|
p = product_by_id(session, pc.id)
|
|
|
|
assert p.name == 'Eggs'
|
|
assert p.category == 'Dairy'
|
|
assert p.remember is True
|
|
assert not p.locations
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_product_create_without_category(session):
|
|
"""Test that a Product can be created with a blank Category."""
|
|
pc = product_create(session, 'Eggs')
|
|
|
|
assert pc.id is not None
|
|
assert pc.name == 'Eggs'
|
|
assert pc.category == ''
|
|
assert pc.remember is True
|
|
assert not pc.locations
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_product_create_forget(session):
|
|
"""Test newly created Products can have remember as false."""
|
|
pc = product_create(session, 'Eggs', category='Dairy', remember=False)
|
|
p = product_by_id(session, pc.id)
|
|
|
|
assert p.name == 'Eggs'
|
|
assert p.category == 'Dairy'
|
|
assert p.remember is False
|
|
assert not p.locations
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_product_all_items_skips_non_remembered(session):
|
|
"""Test that querying all Product items skips non-remembered Products."""
|
|
p1 = product_create(session, 'Apples')
|
|
p2 = product_create(session, 'Bananas', remember=False)
|
|
p3 = product_create(session, 'Carrots')
|
|
|
|
products = products_all(session)
|
|
assert len(products) == 2
|
|
assert p1 in products
|
|
assert p3 in products
|
|
assert p2 not in products
|