Skip to content

Commit 4aa165e

Browse files
committed
Mocky test for email [mocky_test_for_send_email]
1 parent 6571c4d commit 4aa165e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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: 16 additions & 1 deletion
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

@@ -32,7 +34,7 @@ def rollback(self):
3234
def test_add_batch_for_new_product():
3335
uow = FakeUnitOfWork()
3436
services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, uow)
35-
assert uow.products.get('CRUNCHY-ARMCHAIR') is not None
37+
assert uow.products.get("CRUNCHY-ARMCHAIR") is not None
3638
assert uow.committed
3739

3840

@@ -63,3 +65,16 @@ def test_allocate_commits():
6365
services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow)
6466
services.allocate("o1", "OMINOUS-MIRROR", 10, uow)
6567
assert uow.committed
68+
69+
70+
def test_sends_email_on_out_of_stock_error():
71+
uow = FakeUnitOfWork()
72+
services.add_batch("b1", "POPULAR-CURTAINS", 9, None, uow)
73+
74+
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)
77+
assert mock_send_mail.call_args == mock.call(
78+
"stock@made.com",
79+
f"Out of stock for POPULAR-CURTAINS",
80+
)

0 commit comments

Comments
 (0)