Skip to content

Commit 5d5f194

Browse files
committed
Mocky test for email [mocky_test_for_send_email]
1 parent dfaa46a commit 5d5f194

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/allocation/adapters/email.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def send_mail(*args):
2+
print("SENDING EMAIL:", *args)

tests/unit/test_services.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from unittest import mock
12
import pytest
23
from allocation.adapters import repository
4+
from allocation.domain.model import OutOfStock
35
from allocation.service_layer import services, unit_of_work
46

57

@@ -60,3 +62,16 @@ def test_allocate_commits():
6062
services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow)
6163
services.allocate("o1", "OMINOUS-MIRROR", 10, uow)
6264
assert uow.committed
65+
66+
67+
def test_sends_email_on_out_of_stock_error():
68+
uow = FakeUnitOfWork()
69+
services.add_batch("b1", "POPULAR-CURTAINS", 9, None, uow)
70+
71+
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)
74+
assert mock_send_mail.call_args == mock.call(
75+
76+
f"Out of stock for POPULAR-CURTAINS",
77+
)

0 commit comments

Comments
 (0)