def test_allocate_errors_for_invalid_sku(): uow = FakeUnitOfWork() services.add_batch("b1", "AREALSKU", 100, None, uow) with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"): services.allocate("o1", "NONEXISTENTSKU", 10, uow)
def test_add_batch_for_existing_product(): uow = FakeUnitOfWork() services.add_batch("b1", "GARISH-RUG", 100, None, uow) services.add_batch("b2", "GARISH-RUG", 99, None, uow) assert "b2" in [ b.reference for b in uow.products.get("GARISH-RUG").batches ]
def add_batch(): uow = unit_of_work.SqlAlchemyUnitOfWork() eta = request.json['eta'] if eta is not None: eta = datetime.fromisoformat(eta).date() services.add_batch(request.json['ref'], request.json['sku'], request.json['qty'], eta, uow) return 'OK', 201
def test_error_for_not_allocated_line(): uow = FakeUnitOfWork() services.add_batch("b1", "AREALSKU", 100, None, uow) with pytest.raises(NotAllocatedOrder, match=f"Given order hasn't been allocated" f" o1"): services.deallocate("o1", 'AREALSKU', 10, uow)
def add_batch(): session = get_session() repo = repository.SqlAlchemyRepository(session) eta = request.json['eta'] if eta is not None: eta = datetime.fromisoformat(eta).date() services.add_batch(request.json['ref'], request.json['sku'], request.json['qty'], eta, repo, session)
def test_deallocate_decrements_available_quantity(): uow = FakeUnitOfWork() services.add_batch("b1", "BLUE-PLINTH", 100, None, uow) services.allocate('o1', 'BLUE-PLINTH', 10, uow) batch = uow.batches.get(sku="BLUE-PLINTH") assert batch.available_quantity == 90 services.deallocate('o1', 'BLUE-PLINTH', 10, uow) batch = uow.batches.get(sku='BLUE-PLINTH') assert batch.available_quantity == 100
def test_commits(): uow = FakeUnitOfWork() services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow) services.allocate("o1", "OMINOUS-MIRROR", 10, uow) assert uow.committed
def test_allocate_returns_allocation(): uow = FakeUnitOfWork() services.add_batch("batch1", "COMPLICATED-LAMP", 100, None, uow) result = services.allocate("o1", "COMPLICATED-LAMP", 10, uow) assert result == "batch1"
def test_add_batch_for_new_product(): uow = FakeUnitOfWork() services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, uow) assert uow.products.get("CRUNCHY-ARMCHAIR") assert uow.committed
def test_error_for_invalid_sku(): uow = FakeUnitOfWork() services.add_batch("batch", "EXISTINGSKU", 100, None, uow) with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTINGSKU"): services.allocate("o1", 'NONEXISTINGSKU', 10, uow)