@@ -473,6 +473,83 @@ def test_no_conditions(self):
473
473
assert futures [0 ].rule == self .rule
474
474
assert futures [0 ].kwargs == {}
475
475
476
+ def test_environment_mismatch (self ):
477
+ Rule .objects .filter (project = self .group_event .project ).delete ()
478
+ env = self .create_environment (project = self .project )
479
+ self .store_event (
480
+ data = {"release" : "2021-02.newRelease" , "environment" : env .name },
481
+ project_id = self .project .id ,
482
+ )
483
+ self .rule = Rule .objects .create (
484
+ project = self .group_event .project ,
485
+ environment_id = env .id ,
486
+ data = {"actions" : [EMAIL_ACTION_DATA ], "action_match" : "any" },
487
+ )
488
+
489
+ rp = RuleProcessor (
490
+ self .group_event ,
491
+ is_new = True ,
492
+ is_regression = True ,
493
+ is_new_group_environment = True ,
494
+ has_reappeared = True ,
495
+ )
496
+ results = list (rp .apply ())
497
+ assert len (results ) == 0
498
+
499
+ def test_last_active_too_recent (self ):
500
+ Rule .objects .filter (project = self .group_event .project ).delete ()
501
+ self .rule = Rule .objects .create (
502
+ project = self .group_event .project ,
503
+ data = {"actions" : [EMAIL_ACTION_DATA ], "action_match" : "any" },
504
+ )
505
+
506
+ rp = RuleProcessor (
507
+ self .group_event ,
508
+ is_new = True ,
509
+ is_regression = True ,
510
+ is_new_group_environment = True ,
511
+ has_reappeared = True ,
512
+ )
513
+ grs = GroupRuleStatus .objects .create (
514
+ rule = self .rule ,
515
+ group = self .group ,
516
+ project = self .rule .project ,
517
+ last_active = timezone .now () - timedelta (minutes = 10 ),
518
+ )
519
+
520
+ with mock .patch (
521
+ "sentry.rules.processor.RuleProcessor.bulk_get_rule_status" ,
522
+ return_value = {self .rule .id : grs },
523
+ ):
524
+ results = list (rp .apply ())
525
+ assert len (results ) == 0
526
+
527
+ @mock .patch ("sentry.rules.processor.RuleProcessor.logger" )
528
+ def test_invalid_predicate (self , mock_logger ):
529
+ filter_data = {"id" : "tests.sentry.rules.test_processor.MockFilterTrue" }
530
+
531
+ Rule .objects .filter (project = self .group_event .project ).delete ()
532
+ ProjectOwnership .objects .create (project_id = self .project .id , fallthrough = True )
533
+ self .rule = Rule .objects .create (
534
+ project = self .group_event .project ,
535
+ data = {
536
+ "conditions" : [EVERY_EVENT_COND_DATA , filter_data ],
537
+ "actions" : [EMAIL_ACTION_DATA ],
538
+ },
539
+ )
540
+
541
+ with patch ("sentry.rules.processor.get_match_function" , return_value = None ):
542
+ rp = RuleProcessor (
543
+ self .group_event ,
544
+ is_new = True ,
545
+ is_regression = True ,
546
+ is_new_group_environment = True ,
547
+ has_reappeared = True ,
548
+ )
549
+ results = list (rp .apply ())
550
+ assert len (results ) == 0
551
+ mock_logger .error .assert_called_once ()
552
+
476
553
def test_latest_release (self ):
477
554
# setup an alert rule with 1 conditions and no filters that passes
478
555
self .create_release (project = self .project , version = "2021-02.newRelease" )
0 commit comments