@@ -49,26 +49,22 @@ def test_send_creates_email_message_with_html_body(
49
49
extra_headers = {"X-MC-Tags" : EmailTag .TEST },
50
50
)
51
51
52
- def test_send_creates_email_with_mention (
53
- self , email_data , task_data , email_service , pyramid_mailer , task_done_service
52
+ def test_send_creates_mention_email_when_sender_limit_not_reached (
53
+ self ,
54
+ mention_email_data ,
55
+ mention_task_data ,
56
+ email_service ,
57
+ pyramid_mailer ,
58
+ task_done_service ,
54
59
):
55
- email_data = EmailData (
56
-
57
- subject = "My email subject" ,
58
- body = "Some text body" ,
59
- tag = EmailTag .MENTION_NOTIFICATION ,
60
- )
61
- task_data = TaskData (
62
- tag = email_data .tag ,
63
- sender_id = 123 ,
64
- recipient_ids = [124 ],
60
+ task_done_service .sender_mention_count .return_value = (
61
+ DAILY_SENDER_MENTION_LIMIT - 1
65
62
)
66
- task_done_service .sender_mention_count .return_value = DAILY_SENDER_MENTION_LIMIT
67
63
68
- email_service .send (email_data , task_data )
64
+ email_service .send (mention_email_data , mention_task_data )
69
65
70
66
task_done_service .sender_mention_count .assert_called_once_with (
71
- task_data .sender_id , mock .ANY
67
+ mention_task_data .sender_id , mock .ANY
72
68
)
73
69
pyramid_mailer .message .Message .assert_called_once_with (
74
70
@@ -78,28 +74,20 @@ def test_send_creates_email_with_mention(
78
74
extra_headers = {"X-MC-Tags" : EmailTag .MENTION_NOTIFICATION },
79
75
)
80
76
81
- def test_send_does_not_create_email_with_mention (
82
- self , email_data , task_data , email_service , pyramid_mailer , task_done_service
77
+ def test_send_does_not_create_mention_email_when_sender_limit_reached (
78
+ self ,
79
+ mention_email_data ,
80
+ mention_task_data ,
81
+ email_service ,
82
+ pyramid_mailer ,
83
+ task_done_service ,
83
84
):
84
- email_data = EmailData (
85
-
86
- subject = "My email subject" ,
87
- body = "Some text body" ,
88
- tag = EmailTag .MENTION_NOTIFICATION ,
89
- )
90
- task_data = TaskData (
91
- tag = email_data .tag ,
92
- sender_id = 123 ,
93
- recipient_ids = [124 ],
94
- )
95
- task_done_service .sender_mention_count .return_value = (
96
- DAILY_SENDER_MENTION_LIMIT + 1
97
- )
85
+ task_done_service .sender_mention_count .return_value = DAILY_SENDER_MENTION_LIMIT
98
86
99
- email_service .send (email_data , task_data )
87
+ email_service .send (mention_email_data , mention_task_data )
100
88
101
89
task_done_service .sender_mention_count .assert_called_once_with (
102
- task_data .sender_id , mock .ANY
90
+ mention_task_data .sender_id , mock .ANY
103
91
)
104
92
pyramid_mailer .message .Message .assert_not_called ()
105
93
@@ -139,12 +127,29 @@ def test_send_logging_with_extra(self, email_data, email_service, info_caplog):
139
127
recipient_ids = [recipient_id ],
140
128
extra = {"annotation_id" : annotation_id },
141
129
)
130
+
142
131
email_service .send (email_data , task_data )
143
132
144
133
assert info_caplog .messages == [
145
134
f"Sent email: tag={ task_data .tag !r} , sender_id={ sender_id } , recipient_ids={ [recipient_id ]} , annotation_id={ annotation_id !r} "
146
135
]
147
136
137
+ def test_sender_limit_reached_logging (
138
+ self ,
139
+ mention_email_data ,
140
+ mention_task_data ,
141
+ email_service ,
142
+ task_done_service ,
143
+ info_caplog ,
144
+ ):
145
+ task_done_service .sender_mention_count .return_value = DAILY_SENDER_MENTION_LIMIT
146
+
147
+ email_service .send (mention_email_data , mention_task_data )
148
+
149
+ assert info_caplog .messages == [
150
+ f"Email not sent for sender_id={ mention_task_data .sender_id } : limit reached"
151
+ ]
152
+
148
153
def test_send_creates_task_done (
149
154
self , email_data , task_data , email_service , task_done_service
150
155
):
@@ -154,6 +159,7 @@ def test_send_creates_task_done(
154
159
recipient_ids = [124 ],
155
160
extra = {"annotation_id" : "annotation_id" },
156
161
)
162
+
157
163
email_service .send (email_data , task_data )
158
164
159
165
task_done_service .create .assert_called_once_with (task_data )
@@ -175,6 +181,23 @@ def task_data(self):
175
181
recipient_ids = [124 ],
176
182
)
177
183
184
+ @pytest .fixture
185
+ def mention_email_data (self ):
186
+ return EmailData (
187
+
188
+ subject = "My email subject" ,
189
+ body = "Some text body" ,
190
+ tag = EmailTag .MENTION_NOTIFICATION ,
191
+ )
192
+
193
+ @pytest .fixture
194
+ def mention_task_data (self ):
195
+ return TaskData (
196
+ tag = EmailTag .MENTION_NOTIFICATION ,
197
+ sender_id = 123 ,
198
+ recipient_ids = [124 ],
199
+ )
200
+
178
201
@pytest .fixture
179
202
def email_service (self , pyramid_request , pyramid_mailer , task_done_service ):
180
203
request_mailer = pyramid_mailer .get_mailer .return_value
0 commit comments