|
| 1 | +from unittest import mock |
1 | 2 | import pytest
|
2 | 3 | from allocation import services, exceptions, repository, unit_of_work
|
3 | 4 |
|
@@ -31,7 +32,7 @@ def rollback(self):
|
31 | 32 | def test_add_batch_for_new_product():
|
32 | 33 | uow = FakeUnitOfWork()
|
33 | 34 | 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 |
35 | 36 | assert uow.committed
|
36 | 37 |
|
37 | 38 |
|
@@ -62,3 +63,16 @@ def test_allocate_commits():
|
62 | 63 | services.add_batch("b1", "OMINOUS-MIRROR", 100, None, uow)
|
63 | 64 | services.allocate("o1", "OMINOUS-MIRROR", 10, uow)
|
64 | 65 | 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