Our custom ordering system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.3 KiB

import pytest
@pytest.fixture
def prefilled_repo():
from datetime import datetime, timedelta
from itertools import count
from ordr3.models import OrderItem, OrderStatus
from ordr3.repo import FakeOrderRepository
i = count()
catalog = {
1: "Ethanol",
2: "Aceton",
3: "NaOH",
4: "Coffee",
5: "Water",
}
def _create_order(item, date, status):
order = OrderItem(next(i), catalog[item], item, "", "", "", "", "")
order.created_on = date
order.status = status
return order
month = timedelta(days=30)
today = datetime.now()
repo = FakeOrderRepository()
# should be consumables
repo.add(_create_order(1, today - month * 1, OrderStatus.ORDERED))
repo.add(_create_order(1, today - month * 2, OrderStatus.ORDERED))
repo.add(_create_order(1, today - month * 3, OrderStatus.COMPLETED))
repo.add(_create_order(2, today - month * 1, OrderStatus.ORDERED))
repo.add(_create_order(2, today - month * 2, OrderStatus.ORDERED))
repo.add(_create_order(2, today - month * 3, OrderStatus.COMPLETED))
# no consumable, only two repeats
repo.add(_create_order(3, today - month * 1, OrderStatus.ORDERED))
repo.add(_create_order(3, today - month * 2, OrderStatus.ORDERED))
# no consumable, only two repeats in the last two years
repo.add(_create_order(4, today - month * 1, OrderStatus.ORDERED))
repo.add(_create_order(4, today - month * 2, OrderStatus.ORDERED))
repo.add(_create_order(4, today - month * 50, OrderStatus.ORDERED))
# no consumable, one order on hold
repo.add(_create_order(5, today - month * 1, OrderStatus.ORDERED))
repo.add(_create_order(5, today - month * 2, OrderStatus.ORDERED))
repo.add(_create_order(5, today - month * 3, OrderStatus.HOLD))
return repo
def test_fakerepo_add():
from ordr3.repo import FakeOrderRepository
repo = FakeOrderRepository()
repo.add("Something")
assert len(repo._orders) == 1
assert repo._orders[0] == "Something"
def test_fakerepo_get(prefilled_repo):
reference = 8
result = prefilled_repo.get(reference)
assert result.id == reference
def test_fakerepo_find_consumables(prefilled_repo):
result = prefilled_repo.find_consumables()
assert len(result) == 2
assert result == [prefilled_repo._orders[3], prefilled_repo._orders[0]]