Skip to content

Commit ea2dafc

Browse files
committed
adap tests etc
1 parent f784d74 commit ea2dafc

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

src/allocation/domain/model.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ def allocate(line: OrderLine, batches: List[Batch]) -> str:
1717
raise OutOfStock(f"Out of stock for sku {line.sku}")
1818

1919

20+
class Product:
21+
""" dummy implementation, fixme"""
22+
23+
def __init__(self, *args, **kwargs):
24+
self.batches = kwargs.get("batches")
25+
26+
def allocate(self, line):
27+
return allocate(line, self.batches)
28+
29+
2030
@dataclass(unsafe_hash=True)
2131
class OrderLine:
2232
orderid: str

tests/integration/test_uow.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111

1212
def insert_batch(session, ref, sku, qty, eta, product_version=1):
13-
session.execute(
14-
"INSERT INTO products (sku, version_number) VALUES (:sku, :version)",
15-
dict(sku=sku, version=product_version),
16-
)
13+
# session.execute(
14+
# 'INSERT INTO products ...?
15+
# )
1716
session.execute(
1817
"INSERT INTO batches (reference, sku, _purchased_quantity, eta)"
1918
" VALUES (:ref, :sku, :qty, :eta)",
@@ -88,6 +87,7 @@ def try_to_allocate(orderid, sku, exceptions):
8887
exceptions.append(e)
8988

9089

90+
@pytest.mark.skip("do this for an advanced challenge")
9191
def test_concurrent_updates_to_version_are_not_allowed(postgres_session_factory):
9292
sku, batch = random_sku(), random_batchref()
9393
session = postgres_session_factory()

tests/unit/test_product.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def test_raises_out_of_stock_exception_if_cannot_allocate():
5151
product.allocate(OrderLine("order2", "SMALL-FORK", 1))
5252

5353

54+
@pytest.mark.skip
5455
def test_increments_version_number():
5556
line = OrderLine("oref", "SCANDI-PEN", 10)
5657
product = Product(

tests/unit/test_services.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55

66
class FakeRepository(repository.AbstractRepository):
7-
def __init__(self, products):
8-
self._products = set(products)
7+
def __init__(self, batches):
8+
self._batches = set(batches)
99

10-
def add(self, product):
11-
self._products.add(product)
10+
def add(self, batch):
11+
self._batches.add(batch)
1212

1313
def get(self, sku):
14-
return next((p for p in self._products if p.sku == sku), None)
14+
return next((p for p in self._batches if p.sku == sku), None)
15+
16+
def list(self):
17+
return list(self._batches)
1518

1619

1720
class FakeUnitOfWork(unit_of_work.AbstractUnitOfWork):

0 commit comments

Comments
 (0)