Skip to content

Commit db5bcd6

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

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

tests/unit/test_product.py

Lines changed: 7 additions & 17 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():
46-
batch = Batch('batch1', 'HEAVY-SPOON', 100, eta=today)
47-
different_sku_line = OrderLine('oref', 'SMALL-FORK', 10)
48-
product = Product(sku="HIGHBROW-POSTER", batches=[batch])
49-
50-
with pytest.raises(exceptions.OutOfStock, match='SMALL-FORK'):
51-
product.allocate(different_sku_line)
52-
53-
5444
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])
45+
batch = Batch("batch1", "HEAVY-SPOON", 100, eta=today)
46+
different_sku_line = OrderLine("oref", "SMALL-FORK", 10)
47+
product = Product(sku="HEAVY-SPOON", batches=[batch])
5848

59-
with pytest.raises(exceptions.OutOfStock):
60-
product.allocate(sku2_line)
61-
assert product.events[-1] == events.OutOfStock(sku='sku2')
49+
allocation = product.allocate(different_sku_line)
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)