Skip to content

Commit 77ad024

Browse files
committed
adap tests etc
1 parent c114941 commit 77ad024

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/allocation/domain/model.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ def allocate(line: OrderLine, batches: List[Batch]) -> str:
1818
except StopIteration:
1919
raise OutOfStock(f'Out of stock for sku {line.sku}')
2020

21+
class Product:
22+
''' dummy implementation, fixme'''
23+
24+
def __init__(self, *args, **kwargs):
25+
self.batches = kwargs.get('batches')
26+
27+
def allocate(self, line):
28+
return allocate(line, self.batches)
29+
2130

2231
@dataclass(unsafe_hash=True)
2332
class OrderLine:

src/allocation/service_layer/unit_of_work.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def rollback(self):
2727
raise NotImplementedError
2828

2929

30-
3130
DEFAULT_SESSION_FACTORY = sessionmaker(bind=create_engine(
3231
config.get_postgres_uri(),
3332
isolation_level="SERIALIZABLE",

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
@@ -50,6 +50,7 @@ def test_raises_out_of_stock_exception_if_cannot_allocate():
5050
product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
5151

5252

53+
@pytest.mark.skip
5354
def test_increments_version_number():
5455
line = OrderLine('oref', "SCANDI-PEN", 10)
5556
product = Product(sku="SCANDI-PEN", batches=[Batch('b1', "SCANDI-PEN", 100, eta=None)])

tests/unit/test_services.py

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

66
class FakeRepository(repository.AbstractRepository):
77

8-
def __init__(self, products):
9-
self._products = set(products)
8+
def __init__(self, batches):
9+
self._batches = set(batches)
1010

11-
def add(self, product):
12-
self._products.add(product)
11+
def add(self, batch):
12+
self._batches.add(batch)
1313

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

1720

1821
class FakeUnitOfWork(unit_of_work.AbstractUnitOfWork):

0 commit comments

Comments
 (0)