Skip to content

Commit 9fe6483

Browse files
committed
Adjust unit tests now we're no longer raising out of stock exception
1 parent f90098f commit 9fe6483

2 files changed

Lines changed: 7 additions & 19 deletions

File tree

‎tests/unit/test_product.py‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from datetime import date, timedelta
2-
import pytest
3-
42
from allocation.domain import events
5-
from allocation.domain.model import Product, OrderLine, Batch, OutOfStock
3+
from allocation.domain.model import Product, OrderLine, Batch
4+
65

76
today = date.today()
87
tomorrow = today + timedelta(days=1)
@@ -43,23 +42,14 @@ def test_returns_allocated_batch_ref():
4342
assert allocation == in_stock_batch.reference
4443

4544

46-
def test_raises_out_of_stock_exception_if_cannot_allocate():
45+
def test_records_out_of_stock_event_if_cannot_allocate():
4746
batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
4847
product = Product(sku="SMALL-FORK", batches=[batch])
4948
product.allocate(OrderLine('order1', 'SMALL-FORK', 10))
5049

51-
with pytest.raises(OutOfStock, match='SMALL-FORK'):
52-
product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
53-
54-
55-
def test_records_out_of_stock_event_if_cannot_allocate():
56-
sku1_batch = Batch('batch1', 'sku1', 100, eta=today)
57-
sku2_line = OrderLine('oref', 'sku2', 10)
58-
product = Product(sku='sku1', batches=[sku1_batch])
59-
60-
with pytest.raises(OutOfStock):
61-
product.allocate(sku2_line)
62-
assert product.events[-1] == events.OutOfStock(sku='sku2')
50+
allocation = product.allocate(OrderLine('order2', 'SMALL-FORK', 1))
51+
assert product.events[-1] == events.OutOfStock(sku="SMALL-FORK")
52+
assert allocation is None
6353

6454

6555
def test_increments_version_number():

‎tests/unit/test_services.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from unittest import mock
22
import pytest
33
from allocation.adapters import repository
4-
from allocation.domain.model import OutOfStock
54
from allocation.service_layer import services, unit_of_work
65

76

@@ -72,8 +71,7 @@ def test_sends_email_on_out_of_stock_error():
7271
services.add_batch("b1", "POPULAR-CURTAINS", 9, None, uow)
7372

7473
with mock.patch("allocation.adapters.email.send_mail") as mock_send_mail:
75-
with pytest.raises(OutOfStock):
76-
services.allocate("o1", "POPULAR-CURTAINS", 10, uow)
74+
services.allocate("o1", "POPULAR-CURTAINS", 10, uow)
7775
assert mock_send_mail.call_args == mock.call(
7876
"stock@made.com",
7977
f"Out of stock for POPULAR-CURTAINS",

0 commit comments

Comments
 (0)