Skip to content

Commit

Permalink
ref: make condition_data / action_data param names match for create_p…
Browse files Browse the repository at this point in the history
…roject_rule (#80781)

<!-- Describe your PR here. -->
  • Loading branch information
asottile-sentry authored Nov 15, 2024
1 parent 350ad66 commit 1b66eaa
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 77 deletions.
18 changes: 2 additions & 16 deletions src/sentry/testutils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,10 @@ def create_project_key(self, project=None, *args, **kwargs):
project = self.project
return Factories.create_project_key(project=project, *args, **kwargs)

def create_project_rule(
self,
project=None,
action_match=None,
condition_match=None,
comparison_interval=None,
*args,
**kwargs,
) -> Rule:
def create_project_rule(self, project=None, *args, **kwargs) -> Rule:
if project is None:
project = self.project
return Factories.create_project_rule(
project=project,
action_data=action_match,
condition_data=condition_match,
*args,
**kwargs,
)
return Factories.create_project_rule(project, *args, **kwargs)

def create_slack_project_rule(
self, project=None, integration_id=None, channel_id=None, channel_name=None, *args, **kwargs
Expand Down
32 changes: 16 additions & 16 deletions tests/sentry/api/endpoints/test_project_rule_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ def test_remove_conditions(self):
"""Test that you can edit an alert rule to have no conditions (aka fire on every event)"""
rule = self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=self.first_seen_condition,
action_data=self.notify_issue_owners_action,
condition_data=self.first_seen_condition,
name="no conditions",
)
payload = {
Expand Down Expand Up @@ -729,8 +729,8 @@ def test_update_duplicate_rule(self):
]
rule = self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=conditions,
action_data=self.notify_issue_owners_action,
condition_data=conditions,
)
conditions.append(
{
Expand All @@ -742,8 +742,8 @@ def test_update_duplicate_rule(self):
)
rule2 = self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=conditions,
action_data=self.notify_issue_owners_action,
condition_data=conditions,
)
conditions.pop(1)
payload = {
Expand All @@ -769,13 +769,13 @@ def test_duplicate_rule_environment(self):
that does have one set, we consider this when determining if it's a duplicate"""
self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=self.first_seen_condition,
action_data=self.notify_issue_owners_action,
condition_data=self.first_seen_condition,
)
env_rule = self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=self.first_seen_condition,
action_data=self.notify_issue_owners_action,
condition_data=self.first_seen_condition,
)
payload = {
"name": "hello world",
Expand Down Expand Up @@ -812,15 +812,15 @@ def test_duplicate_rule_both_have_environments(self):
"""
rule = self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=self.first_seen_condition,
action_data=self.notify_issue_owners_action,
condition_data=self.first_seen_condition,
name="rule_with_env",
environment_id=self.environment.id,
)
rule2 = self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=self.first_seen_condition,
action_data=self.notify_issue_owners_action,
condition_data=self.first_seen_condition,
name="rule_wo_env",
)
payload = {
Expand Down Expand Up @@ -890,8 +890,8 @@ def test_edit_rule(self):
]
self.create_project_rule(
project=self.project,
action_match=self.notify_issue_owners_action,
condition_match=conditions,
action_data=self.notify_issue_owners_action,
condition_data=conditions,
)
conditions.append(
{
Expand Down
20 changes: 10 additions & 10 deletions tests/sentry/api/endpoints/test_project_rule_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def test_duplicate_rule(self):
}
]
rule = self.create_project_rule(
project=self.project, action_match=actions, condition_match=conditions
project=self.project, action_data=actions, condition_data=conditions
)

rule2 = self.create_project_rule(
project=self.project, action_match=actions, condition_match=conditions
project=self.project, action_data=actions, condition_data=conditions
)
rule2.status = ObjectStatus.DISABLED
rule2.save()
Expand Down Expand Up @@ -114,15 +114,15 @@ def test_duplicate_rule_diff_env(self):
)
self.create_project_rule(
project=self.project,
action_match=actions,
condition_match=conditions,
action_data=actions,
condition_data=conditions,
environment_id=dev_env.id,
)

rule2 = self.create_project_rule(
project=self.project,
action_match=actions,
condition_match=conditions,
action_data=actions,
condition_data=conditions,
environment_id=prod_env.id,
)
rule2.status = ObjectStatus.DISABLED
Expand Down Expand Up @@ -154,15 +154,15 @@ def test_duplicate_rule_one_env_one_not(self):
dev_env = self.create_environment(self.project, name="dev", organization=self.organization)
self.create_project_rule(
project=self.project,
action_match=actions,
condition_match=conditions,
action_data=actions,
condition_data=conditions,
environment_id=dev_env.id,
)

rule2 = self.create_project_rule(
project=self.project,
action_match=actions,
condition_match=conditions,
action_data=actions,
condition_data=conditions,
)
rule2.status = ObjectStatus.DISABLED
rule2.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self) -> None:
}
]
self.rule = self.create_project_rule(
project=self.project, action_match=self.notify_issue_owners_action
project=self.project, action_data=self.notify_issue_owners_action
)
self.event_id = 456
self.notification_uuid = str(uuid4())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def setUp(self) -> None:
"channel": "test-notifications",
"uuid": self.uuid,
}
self.rule = self.create_project_rule(project=self.project, action_match=[self.action_data])
self.rule = self.create_project_rule(project=self.project, action_data=[self.action_data])
self.notification_uuid = str(uuid4())
self.event = self.store_event(
data={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_issue_alert_issue_owners_environment_block(self):
)
rule = self.create_project_rule(
project=self.project,
action_match=[action_data],
action_data=[action_data],
name="ja rule",
environment_id=environment.id,
)
Expand Down
8 changes: 4 additions & 4 deletions tests/sentry/integrations/slack/service/test_slack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setUp(self) -> None:
}
]
self.rule = self.create_project_rule(
project=self.project, action_match=self.notify_issue_owners_action
project=self.project, action_data=self.notify_issue_owners_action
)
self.rule_fire_history = RuleFireHistory.objects.create(
project=self.project,
Expand Down Expand Up @@ -205,7 +205,7 @@ def setUp(self) -> None:
"uuid": self.rule_action_uuid,
}
self.rule = self.create_project_rule(
project=self.project, action_match=self.notify_issue_owners_action
project=self.project, action_data=self.notify_issue_owners_action
)
self.rule_fire_history = RuleFireHistory.objects.create(
project=self.project,
Expand All @@ -216,7 +216,7 @@ def setUp(self) -> None:
)

self.slack_rule = self.create_project_rule(
project=self.project, action_match=[self.slack_action]
project=self.project, action_data=[self.slack_action]
)
self.slack_rule_fire_history = RuleFireHistory.objects.create(
project=self.project,
Expand Down Expand Up @@ -314,7 +314,7 @@ def test_raises_exception_when_rule_action_does_not_exist(self) -> None:
}
]
rule = self.create_project_rule(
project=self.project, action_match=notify_issue_owners_action
project=self.project, action_data=notify_issue_owners_action
)
rule_fire_history = RuleFireHistory.objects.create(
project=self.project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BackfillAddUuidToAllRuleActions(TestMigrations):
def setup_before_migration(self, apps):
# Create your db state here
self.notify_event_action = [{"id": "sentry.rules.actions.notify_event.NotifyEventAction"}]
self.rule = self.create_project_rule(action_match=self.notify_event_action)
self.rule = self.create_project_rule(action_data=self.notify_event_action)

@pytest.mark.skip(
reason="This reaches into code to create projects, rather than migration code. Don't need this test anymore"
Expand Down
8 changes: 4 additions & 4 deletions tests/sentry/models/test_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self) -> None:
},
]
self.rule = self.create_project_rule(
project=self.project, action_match=self.notify_issue_owners_action
project=self.project, action_data=self.notify_issue_owners_action
)

def test_simple(self) -> None:
Expand All @@ -38,15 +38,15 @@ def test_returns_none(self) -> None:
def test_when_no_actions_are_in_rule(self) -> None:
rule = self.create_project_rule(
project=self.project,
action_match=[],
action_data=[],
)
result = rule.get_rule_action_details_by_uuid(str(uuid4()))
assert result is None

def test_when_actions_have_missing_uuid_key(self) -> None:
rule = self.create_project_rule(
project=self.project,
action_match=[
action_data=[
{
"targetType": "IssueOwners",
"fallthroughType": "ActiveMembers",
Expand All @@ -61,7 +61,7 @@ def test_when_actions_have_missing_uuid_key(self) -> None:
def test_when_action_has_missing_uuid_value(self) -> None:
rule = self.create_project_rule(
project=self.project,
action_match=[
action_data=[
{
"targetType": "IssueOwners",
"fallthroughType": "ActiveMembers",
Expand Down
Loading

0 comments on commit 1b66eaa

Please sign in to comment.