Skip to content

Commit 845286e

Browse files
committed
Adjust unit tests now we're no longer raising out of stock exception
1 parent ab4080c commit 845286e

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)
@@ -44,23 +43,14 @@ def test_returns_allocated_batch_ref():
4443
assert allocation == in_stock_batch.reference
4544

4645

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

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

6555

6656
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

@@ -69,8 +68,7 @@ def test_sends_email_on_out_of_stock_error():
6968
services.add_batch("b1", "POPULAR-CURTAINS", 9, None, uow)
7069

7170
with mock.patch("allocation.adapters.email.send_mail") as mock_send_mail:
72-
with pytest.raises(OutOfStock):
73-
services.allocate("o1", "POPULAR-CURTAINS", 10, uow)
71+
services.allocate("o1", "POPULAR-CURTAINS", 10, uow)
7472
assert mock_send_mail.call_args == mock.call(
7573
7674
f"Out of stock for POPULAR-CURTAINS",

0 commit comments

Comments
 (0)