2
2
3
3
from datetime import datetime , timezone
4
4
from typing import Any , Mapping
5
- from unittest import mock
6
- from unittest .mock import call , patch
5
+ from unittest .mock import patch
7
6
8
- import pytest
9
7
import responses
10
8
from freezegun import freeze_time
11
9
@@ -49,6 +47,8 @@ def assert_rule_from_payload(rule: Rule, payload: Mapping[str, Any]) -> None:
49
47
# any(a.items() <= b.items()) to check if the payload dict is a subset of the rule.data dict
50
48
# E.g. payload["actions"] = [{"name": "Test1"}], rule.data["actions"] = [{"name": "Test1", "id": 1}]
51
49
for payload_action in payload .get ("actions" , []):
50
+ if payload_action .get ("name" ):
51
+ del payload_action ["name" ]
52
52
# The Slack payload will contain '#channel' or '@user', but we save 'channel' or 'user' on the Rule
53
53
if (
54
54
payload_action ["id" ]
@@ -60,6 +60,8 @@ def assert_rule_from_payload(rule: Rule, payload: Mapping[str, Any]) -> None:
60
60
)
61
61
payload_conditions = payload .get ("conditions" , []) + payload .get ("filters" , [])
62
62
for payload_condition in payload_conditions :
63
+ if payload_condition .get ("name" ):
64
+ del payload_condition ["name" ]
63
65
assert any (
64
66
payload_condition .items () <= rule_condition .items ()
65
67
for rule_condition in rule .data ["conditions" ]
@@ -102,6 +104,7 @@ def test_simple(self):
102
104
)
103
105
assert response .data ["id" ] == str (self .rule .id )
104
106
assert response .data ["environment" ] is None
107
+ assert response .data ["conditions" ][0 ]["name" ]
105
108
106
109
def test_non_existing_rule (self ):
107
110
self .get_error_response (self .organization .slug , self .project .slug , 12345 , status_code = 404 )
@@ -313,11 +316,6 @@ def test_with_jira_action_error(self):
313
316
314
317
@region_silo_test (stable = True )
315
318
class UpdateProjectRuleTest (ProjectRuleDetailsBaseTestCase ):
316
- @pytest .fixture (autouse = True )
317
- def _setup_metric_patch (self ):
318
- with mock .patch ("sentry.api.endpoints.project_rule_details.metrics" ) as self .metrics :
319
- yield
320
-
321
319
method = "PUT"
322
320
323
321
@patch ("sentry.signals.alert_rule_edited.send_robust" )
@@ -638,7 +636,12 @@ def test_rule_form_missing_action(self):
638
636
)
639
637
640
638
def test_update_filters (self ):
641
- conditions = [{"id" : "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition" }]
639
+ conditions = [
640
+ {
641
+ "id" : "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition" ,
642
+ "name" : "A new issue is created" ,
643
+ }
644
+ ]
642
645
filters = [
643
646
{"id" : "sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter" , "value" : 10 }
644
647
]
@@ -735,10 +738,6 @@ def test_edit_condition_metric(self):
735
738
self .get_success_response (
736
739
self .organization .slug , self .project .slug , self .rule .id , status_code = 200 , ** payload
737
740
)
738
- assert (
739
- call ("sentry.issue_alert.conditions.edited" , sample_rate = 1.0 )
740
- in self .metrics .incr .call_args_list
741
- )
742
741
743
742
def test_edit_non_condition_metric (self ):
744
743
payload = {
@@ -752,10 +751,6 @@ def test_edit_non_condition_metric(self):
752
751
self .get_success_response (
753
752
self .organization .slug , self .project .slug , self .rule .id , status_code = 200 , ** payload
754
753
)
755
- assert (
756
- call ("sentry.issue_alert.conditions.edited" , sample_rate = 1.0 )
757
- not in self .metrics .incr .call_args_list
758
- )
759
754
760
755
761
756
@region_silo_test (stable = True )
0 commit comments