Skip to content

Commit a46cd5e

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

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

tests/unit/test_product.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from datetime import date, timedelta
2-
import pytest
3-
from allocation import events, exceptions
2+
from allocation import events
43
from allocation.model import Product, OrderLine, Batch
54

65
today = date.today()
@@ -42,23 +41,14 @@ def test_returns_allocated_batch_ref():
4241
assert allocation == in_stock_batch.reference
4342

4443

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

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

6353

6454
def test_increments_version_number():

tests/unit/test_services.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def test_sends_email_on_out_of_stock_error():
7070
services.add_batch("b1", "POPULAR-CURTAINS", 9, None, uow)
7171

7272
with mock.patch("allocation.email.send_mail") as mock_send_mail:
73-
with pytest.raises(exceptions.OutOfStock):
74-
services.allocate("o1", "POPULAR-CURTAINS", 10, uow)
73+
services.allocate("o1", "POPULAR-CURTAINS", 10, uow)
7574
assert mock_send_mail.call_args == mock.call(
7675
"stock@made.com",
7776
f"Out of stock for POPULAR-CURTAINS",

0 commit comments

Comments
 (0)