|
1 | 1 | # pylint: disable=no-self-use |
2 | 2 | from __future__ import annotations |
| 3 | +from collections import defaultdict |
3 | 4 | from datetime import date |
4 | | -from unittest import mock |
| 5 | +from typing import Dict, List |
5 | 6 | import pytest |
6 | 7 | from allocation import bootstrap |
7 | | -from allocation.adapters import repository |
8 | 8 | from allocation.domain import commands |
9 | | -from allocation.service_layer import handlers, unit_of_work |
| 9 | +from allocation.service_layer import handlers |
| 10 | +from allocation.adapters import notifications, repository |
| 11 | +from allocation.service_layer import unit_of_work |
10 | 12 |
|
11 | 13 |
|
12 | 14 | class FakeRepository(repository.AbstractRepository): |
@@ -41,11 +43,21 @@ def rollback(self): |
41 | 43 | pass |
42 | 44 |
|
43 | 45 |
|
| 46 | +class FakeNotifications(notifications.AbstractNotifications): |
| 47 | + |
| 48 | + def __init__(self): |
| 49 | + self.sent = defaultdict(list) # type: Dict[str, List[str]] |
| 50 | + |
| 51 | + def send(self, destination, message): |
| 52 | + self.sent[destination].append(message) |
| 53 | + |
| 54 | + |
| 55 | + |
44 | 56 | def bootstrap_test_app(): |
45 | 57 | return bootstrap.bootstrap( |
46 | 58 | start_orm=False, |
47 | 59 | uow=FakeUnitOfWork(), |
48 | | - send_mail=lambda *args: None, |
| 60 | + notifications=FakeNotifications(), |
49 | 61 | publish=lambda *args: None, |
50 | 62 | ) |
51 | 63 |
|
@@ -92,19 +104,17 @@ def test_commits(self): |
92 | 104 |
|
93 | 105 |
|
94 | 106 | def test_sends_email_on_out_of_stock_error(self): |
95 | | - emails = [] |
96 | | - def fake_send_mail(*args): |
97 | | - emails.append(args) |
| 107 | + fake_notifs = FakeNotifications() |
98 | 108 | bus = bootstrap.bootstrap( |
99 | 109 | start_orm=False, |
100 | 110 | uow=FakeUnitOfWork(), |
101 | | - send_mail=fake_send_mail, |
| 111 | + notifications=fake_notifs, |
102 | 112 | publish=lambda *args: None, |
103 | 113 | ) |
104 | 114 | bus.handle(commands.CreateBatch("b1", "POPULAR-CURTAINS", 9, None)) |
105 | 115 | bus.handle(commands.Allocate("o1", "POPULAR-CURTAINS", 10)) |
106 | | - assert emails == [ |
107 | | - ("stock@made.com", f"Out of stock for POPULAR-CURTAINS"), |
| 116 | + assert fake_notifs.sent['stock@made.com'] == [ |
| 117 | + f"Out of stock for POPULAR-CURTAINS", |
108 | 118 | ] |
109 | 119 |
|
110 | 120 |
|
|
0 commit comments