/
woodpecker86
/
cosmic-python-code
Обзор
Документация
Войти
/
woodpecker86
/
cosmic-python-code
Код
Запросы
0
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/unit/test_batches.py
46 строк
1 KB
Harry
change_batch_quantity on product, needed change to batch, also emit allocated event. [change_batch_model_layer]
01 мар 2024, 18:05
01 мар 2024, 18:05
e29cdca
Код
Авторство
О чём код?
from datetime import date from allocation.domain.model import Batch, OrderLine def test_allocating_to_a_batch_reduces_the_available_quantity(): batch = Batch("batch-001", "SMALL-TABLE", qty=20, eta=date.today()) line = OrderLine("order-ref", "SMALL-TABLE", 2) batch.allocate(line) assert batch.available_quantity == 18 def make_batch_and_line(sku, batch_qty, line_qty): return ( Batch("batch-001", sku, batch_qty, eta=date.today()), OrderLine("order-123", sku, line_qty), ) def test_can_allocate_if_available_greater_than_required(): large_batch, small_line = make_batch_and_line("ELEGANT-LAMP", 20, 2) assert large_batch.can_allocate(small_line) def test_cannot_allocate_if_available_smaller_than_required(): small_batch, large_line = make_batch_and_line("ELEGANT-LAMP", 2, 20) assert small_batch.can_allocate(large_line) is False def test_can_allocate_if_available_equal_to_required(): batch, line = make_batch_and_line("ELEGANT-LAMP", 2, 2) assert batch.can_allocate(line) def test_cannot_allocate_if_skus_do_not_match(): batch = Batch("batch-001", "UNCOMFORTABLE-CHAIR", 100, eta=None) different_sku_line = OrderLine("order-123", "EXPENSIVE-TOASTER", 10) assert batch.can_allocate(different_sku_line) is False def test_allocation_is_idempotent(): batch, line = make_batch_and_line("ANGULAR-DESK", 20, 2) batch.allocate(line) batch.allocate(line) assert batch.available_quantity == 18