@@ -69,26 +69,22 @@ def test_send_creates_email_message_with_subaccount(
69
69
extra_headers = {"X-MC-Tags" : EmailTag .TEST , "X-MC-Subaccount" : "subaccount" },
70
70
)
71
71
72
- def test_send_creates_email_with_mention (
73
- self , email_data , task_data , email_service , pyramid_mailer , task_done_service
72
+ def test_send_creates_mention_email_when_sender_limit_not_reached (
73
+ self ,
74
+ mention_email_data ,
75
+ mention_task_data ,
76
+ email_service ,
77
+ pyramid_mailer ,
78
+ task_done_service ,
74
79
):
75
- email_data = EmailData (
76
-
77
- subject = "My email subject" ,
78
- body = "Some text body" ,
79
- tag = EmailTag .MENTION_NOTIFICATION ,
80
- )
81
- task_data = TaskData (
82
- tag = email_data .tag ,
83
- sender_id = 123 ,
84
- recipient_ids = [124 ],
80
+ task_done_service .sender_mention_count .return_value = (
81
+ DAILY_SENDER_MENTION_LIMIT - 1
85
82
)
86
- task_done_service .sender_mention_count .return_value = DAILY_SENDER_MENTION_LIMIT
87
83
88
- email_service .send (email_data , task_data )
84
+ email_service .send (mention_email_data , mention_task_data )
89
85
90
86
task_done_service .sender_mention_count .assert_called_once_with (
91
- task_data .sender_id , mock .ANY
87
+ mention_task_data .sender_id , mock .ANY
92
88
)
93
89
pyramid_mailer .message .Message .assert_called_once_with (
94
90
@@ -98,28 +94,20 @@ def test_send_creates_email_with_mention(
98
94
extra_headers = {"X-MC-Tags" : EmailTag .MENTION_NOTIFICATION },
99
95
)
100
96
101
- def test_send_does_not_create_email_with_mention (
102
- self , email_data , task_data , email_service , pyramid_mailer , task_done_service
97
+ def test_send_does_not_create_mention_email_when_sender_limit_reached (
98
+ self ,
99
+ mention_email_data ,
100
+ mention_task_data ,
101
+ email_service ,
102
+ pyramid_mailer ,
103
+ task_done_service ,
103
104
):
104
- email_data = EmailData (
105
-
106
- subject = "My email subject" ,
107
- body = "Some text body" ,
108
- tag = EmailTag .MENTION_NOTIFICATION ,
109
- )
110
- task_data = TaskData (
111
- tag = email_data .tag ,
112
- sender_id = 123 ,
113
- recipient_ids = [124 ],
114
- )
115
- task_done_service .sender_mention_count .return_value = (
116
- DAILY_SENDER_MENTION_LIMIT + 1
117
- )
105
+ task_done_service .sender_mention_count .return_value = DAILY_SENDER_MENTION_LIMIT
118
106
119
- email_service .send (email_data , task_data )
107
+ email_service .send (mention_email_data , mention_task_data )
120
108
121
109
task_done_service .sender_mention_count .assert_called_once_with (
122
- task_data .sender_id , mock .ANY
110
+ mention_task_data .sender_id , mock .ANY
123
111
)
124
112
pyramid_mailer .message .Message .assert_not_called ()
125
113
@@ -159,12 +147,29 @@ def test_send_logging_with_extra(self, email_data, email_service, info_caplog):
159
147
recipient_ids = [recipient_id ],
160
148
extra = {"annotation_id" : annotation_id },
161
149
)
150
+
162
151
email_service .send (email_data , task_data )
163
152
164
153
assert info_caplog .messages == [
165
154
f"Sent email: tag={ task_data .tag !r} , sender_id={ sender_id } , recipient_ids={ [recipient_id ]} , annotation_id={ annotation_id !r} "
166
155
]
167
156
157
+ def test_sender_limit_reached_logging (
158
+ self ,
159
+ mention_email_data ,
160
+ mention_task_data ,
161
+ email_service ,
162
+ task_done_service ,
163
+ info_caplog ,
164
+ ):
165
+ task_done_service .sender_mention_count .return_value = DAILY_SENDER_MENTION_LIMIT
166
+
167
+ email_service .send (mention_email_data , mention_task_data )
168
+
169
+ assert info_caplog .messages == [
170
+ f"Not sending email: tag={ mention_task_data .tag !r} sender_id={ mention_task_data .sender_id } recipient_ids={ mention_task_data .recipient_ids } . Sender limit reached."
171
+ ]
172
+
168
173
def test_send_creates_task_done (
169
174
self , email_data , task_data , email_service , task_done_service
170
175
):
@@ -174,6 +179,7 @@ def test_send_creates_task_done(
174
179
recipient_ids = [124 ],
175
180
extra = {"annotation_id" : "annotation_id" },
176
181
)
182
+
177
183
email_service .send (email_data , task_data )
178
184
179
185
task_done_service .create .assert_called_once_with (task_data )
@@ -195,6 +201,23 @@ def task_data(self):
195
201
recipient_ids = [124 ],
196
202
)
197
203
204
+ @pytest .fixture
205
+ def mention_email_data (self ):
206
+ return EmailData (
207
+
208
+ subject = "My email subject" ,
209
+ body = "Some text body" ,
210
+ tag = EmailTag .MENTION_NOTIFICATION ,
211
+ )
212
+
213
+ @pytest .fixture
214
+ def mention_task_data (self ):
215
+ return TaskData (
216
+ tag = EmailTag .MENTION_NOTIFICATION ,
217
+ sender_id = 123 ,
218
+ recipient_ids = [124 ],
219
+ )
220
+
198
221
@pytest .fixture
199
222
def email_service (self , pyramid_request , pyramid_mailer , task_done_service ):
200
223
request_mailer = pyramid_mailer .get_mailer .return_value
0 commit comments