Skip to content

Commit a65d544

Browse files
committed
Mocky test for email [mocky_test_for_send_email]
1 parent 81ce752 commit a65d544

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/allocation/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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from unittest import mock
12
import pytest
23
from allocation import services, exceptions, repository, unit_of_work
34

@@ -31,7 +32,7 @@ def rollback(self):
3132
def test_add_batch_for_new_product():
3233
uow = FakeUnitOfWork()
3334
services.add_batch("b1", "CRUNCHY-ARMCHAIR", 100, None, uow)
34-
assert uow.products.get('CRUNCHY-ARMCHAIR') is not None
35+
assert uow.products.get("CRUNCHY-ARMCHAIR") is not None
3536
assert uow.committed
3637

3738

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

0 commit comments

Comments
 (0)