@@ -211,15 +211,23 @@ def test_sends_emails_to_all_users_across_orgs(self, mock_now, builder):
211
211
project_id = second_project .id ,
212
212
environment_id = second_env .id ,
213
213
)
214
+ third_monitor , third_monitor_environment = self .create_monitor_and_env (
215
+ name = "third monitor" ,
216
+ organization_id = second_org .id ,
217
+ project_id = second_project .id ,
218
+ environment_id = second_env .id ,
219
+ )
214
220
215
221
self .create_incident_for_monitor_env (monitor , monitor_environment )
216
222
self .create_incident_for_monitor_env (second_monitor , second_monitor_environment )
223
+ self .create_incident_for_monitor_env (third_monitor , third_monitor_environment )
217
224
218
225
detect_broken_monitor_envs ()
219
226
broken_detections = MonitorEnvBrokenDetection .objects .all ()
220
- assert len (broken_detections ) == 2
227
+ assert len (broken_detections ) == 3
221
228
assert broken_detections [0 ].user_notified_timestamp == now
222
229
assert broken_detections [1 ].user_notified_timestamp == now
230
+ assert broken_detections [2 ].user_notified_timestamp == now
223
231
# should build 3 emails, 2 for self.user from the 2 orgs, and 1 for second_user
224
232
expected_contexts = [
225
233
{
@@ -238,7 +246,12 @@ def test_sends_emails_to_all_users_across_orgs(self, mock_now, builder):
238
246
second_monitor .slug ,
239
247
f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ second_monitor .slug } /?environment={ second_env .name } " ,
240
248
timezone .now () - timedelta (days = 14 ),
241
- )
249
+ ),
250
+ (
251
+ third_monitor .slug ,
252
+ f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ third_monitor .slug } /?environment={ second_env .name } " ,
253
+ timezone .now () - timedelta (days = 14 ),
254
+ ),
242
255
],
243
256
"view_monitors_link" : f"http://testserver/organizations/{ second_org .slug } /crons/" ,
244
257
},
@@ -248,24 +261,34 @@ def test_sends_emails_to_all_users_across_orgs(self, mock_now, builder):
248
261
second_monitor .slug ,
249
262
f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ second_monitor .slug } /?environment={ second_env .name } " ,
250
263
timezone .now () - timedelta (days = 14 ),
251
- )
264
+ ),
265
+ (
266
+ third_monitor .slug ,
267
+ f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ third_monitor .slug } /?environment={ second_env .name } " ,
268
+ timezone .now () - timedelta (days = 14 ),
269
+ ),
252
270
],
253
271
"view_monitors_link" : f"http://testserver/organizations/{ second_org .slug } /crons/" ,
254
272
},
255
273
]
274
+ expected_subjects = [
275
+ "1 of your Cron Monitors isn't working" ,
276
+ "2 of your Cron Monitors aren't working" ,
277
+ "2 of your Cron Monitors aren't working" ,
278
+ ]
256
279
257
280
builder .assert_has_calls (
258
281
[
259
282
call (
260
283
** {
261
- "subject" : "Your Cron Monitors Aren't Working" ,
284
+ "subject" : subject ,
262
285
"template" : "sentry/emails/crons/broken-monitors.txt" ,
263
286
"html_template" : "sentry/emails/crons/broken-monitors.html" ,
264
287
"type" : "crons.broken_monitors" ,
265
288
"context" : context ,
266
289
}
267
290
)
268
- for context in expected_contexts [: 1 ]
291
+ for subject , context in zip ( expected_subjects , expected_contexts )
269
292
],
270
293
any_order = True ,
271
294
)
@@ -291,11 +314,20 @@ def test_disables_environments_and_sends_email(self, mock_now, builder):
291
314
project_id = second_project .id ,
292
315
environment_id = second_env .id ,
293
316
)
317
+ third_monitor , third_monitor_environment = self .create_monitor_and_env (
318
+ name = "third monitor" ,
319
+ organization_id = second_org .id ,
320
+ project_id = second_project .id ,
321
+ environment_id = second_env .id ,
322
+ )
294
323
295
324
incident = self .create_incident_for_monitor_env (monitor , monitor_environment )
296
325
second_incident = self .create_incident_for_monitor_env (
297
326
second_monitor , second_monitor_environment
298
327
)
328
+ third_incident = self .create_incident_for_monitor_env (
329
+ third_monitor , third_monitor_environment
330
+ )
299
331
300
332
broken_detection = MonitorEnvBrokenDetection .objects .create (
301
333
monitor_incident = incident ,
@@ -307,19 +339,29 @@ def test_disables_environments_and_sends_email(self, mock_now, builder):
307
339
detection_timestamp = now - timedelta (days = 14 ),
308
340
user_notified_timestamp = now - timedelta (days = 14 ),
309
341
)
342
+ third_broken_detection = MonitorEnvBrokenDetection .objects .create (
343
+ monitor_incident = third_incident ,
344
+ detection_timestamp = now - timedelta (days = 14 ),
345
+ user_notified_timestamp = now - timedelta (days = 14 ),
346
+ )
310
347
311
348
detect_broken_monitor_envs ()
312
349
313
350
# should have the two monitor environments as muted
314
351
monitor_environment .refresh_from_db ()
315
352
second_monitor_environment .refresh_from_db ()
353
+ third_monitor_environment .refresh_from_db ()
316
354
assert monitor_environment .is_muted
317
355
assert second_monitor_environment .is_muted
356
+ assert third_monitor_environment .is_muted
318
357
319
358
broken_detection .refresh_from_db ()
320
359
second_broken_detection .refresh_from_db ()
360
+ third_broken_detection .refresh_from_db ()
361
+
321
362
assert broken_detection .env_muted_timestamp == now
322
363
assert second_broken_detection .env_muted_timestamp == now
364
+ assert third_broken_detection .env_muted_timestamp == now
323
365
324
366
# should build 3 emails, 2 for self.user from the 2 orgs, and 1 for second_user
325
367
expected_contexts = [
@@ -339,7 +381,12 @@ def test_disables_environments_and_sends_email(self, mock_now, builder):
339
381
second_monitor .slug ,
340
382
f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ second_monitor .slug } /?environment={ second_env .name } " ,
341
383
timezone .now () - timedelta (days = 14 ),
342
- )
384
+ ),
385
+ (
386
+ third_monitor .slug ,
387
+ f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ third_monitor .slug } /?environment={ second_env .name } " ,
388
+ timezone .now () - timedelta (days = 14 ),
389
+ ),
343
390
],
344
391
"view_monitors_link" : f"http://testserver/organizations/{ second_org .slug } /crons/" ,
345
392
},
@@ -349,24 +396,34 @@ def test_disables_environments_and_sends_email(self, mock_now, builder):
349
396
second_monitor .slug ,
350
397
f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ second_monitor .slug } /?environment={ second_env .name } " ,
351
398
timezone .now () - timedelta (days = 14 ),
352
- )
399
+ ),
400
+ (
401
+ third_monitor .slug ,
402
+ f"http://testserver/organizations/{ second_org .slug } /crons/{ second_project .slug } /{ third_monitor .slug } /?environment={ second_env .name } " ,
403
+ timezone .now () - timedelta (days = 14 ),
404
+ ),
353
405
],
354
406
"view_monitors_link" : f"http://testserver/organizations/{ second_org .slug } /crons/" ,
355
407
},
356
408
]
409
+ expected_subjects = [
410
+ "1 of your Cron Monitors has been muted" ,
411
+ "2 of your Cron Monitors have been muted" ,
412
+ "2 of your Cron Monitors have been muted" ,
413
+ ]
357
414
358
415
builder .assert_has_calls (
359
416
[
360
417
call (
361
418
** {
362
- "subject" : "Your Cron Monitors have been muted" ,
419
+ "subject" : subject ,
363
420
"template" : "sentry/emails/crons/muted-monitors.txt" ,
364
421
"html_template" : "sentry/emails/crons/muted-monitors.html" ,
365
422
"type" : "crons.muted_monitors" ,
366
423
"context" : context ,
367
424
}
368
425
)
369
- for context in expected_contexts
426
+ for subject , context in zip ( expected_subjects , expected_contexts )
370
427
],
371
428
any_order = True ,
372
429
)
@@ -451,7 +508,7 @@ def test_disables_corrects_environments_and_sends_email(self, mock_now, builder)
451
508
[
452
509
call (
453
510
** {
454
- "subject" : "Your Cron Monitors have been muted" ,
511
+ "subject" : "1 of your Cron Monitors has been muted" ,
455
512
"template" : "sentry/emails/crons/muted-monitors.txt" ,
456
513
"html_template" : "sentry/emails/crons/muted-monitors.html" ,
457
514
"type" : "crons.muted_monitors" ,
0 commit comments