Skip to content

Commit 24d0a1b

Browse files
committed
fix mock in test, don't need to pass rules
1 parent d201ff2 commit 24d0a1b

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

src/sentry/api/endpoints/project_rule_details.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
from sentry.models.scheduledeletion import RegionScheduledDeletion
4242
from sentry.models.team import Team
4343
from sentry.models.user import User
44-
from sentry.rules import rules as rule_registry
4544
from sentry.rules.actions import trigger_sentry_app_action_creators_for_issues
4645
from sentry.signals import alert_rule_edited
4746
from sentry.tasks.integrations.slack import find_channel_id_for_rule
@@ -368,7 +367,7 @@ def put(self, request: Request, project, rule) -> Response:
368367
if features.has(
369368
"organizations:rule-create-edit-confirm-notification", project.organization
370369
):
371-
send_confirmation_notification(rule=rule, new=False, rules=rule_registry)
370+
send_confirmation_notification(rule=rule, new=False)
372371
return Response(serialize(updated_rule, request.user))
373372

374373
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

src/sentry/api/endpoints/project_rules.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,17 @@
3030
from sentry.models.rule import Rule, RuleActivity, RuleActivityType
3131
from sentry.models.team import Team
3232
from sentry.models.user import User
33-
from sentry.rules import rules as rule_registry
3433
from sentry.rules.actions import trigger_sentry_app_action_creators_for_issues
3534
from sentry.rules.actions.base import instantiate_action
3635
from sentry.rules.processor import is_condition_slow
37-
from sentry.rules.registry import RuleRegistry
3836
from sentry.signals import alert_rule_created
3937
from sentry.tasks.integrations.slack import find_channel_id_for_rule
4038
from sentry.utils.safe import safe_execute
4139

4240

43-
def send_confirmation_notification(rule: Rule, new: bool, rules: RuleRegistry):
41+
def send_confirmation_notification(rule: Rule, new: bool):
4442
for action in rule.data.get("actions", ()):
45-
action_inst = instantiate_action(rule, action, rules)
43+
action_inst = instantiate_action(rule, action)
4644
safe_execute(
4745
action_inst.send_confirmation_notification,
4846
rule=rule,
@@ -846,6 +844,6 @@ def post(self, request: Request, project) -> Response:
846844
if features.has(
847845
"organizations:rule-create-edit-confirm-notification", project.organization
848846
):
849-
send_confirmation_notification(rule=rule, new=True, rules=rule_registry)
847+
send_confirmation_notification(rule=rule, new=True)
850848

851849
return Response(serialize(rule, request.user))

src/sentry/rules/actions/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from sentry.eventstore.models import GroupEvent
88
from sentry.models.rule import Rule
99
from sentry.rules.base import CallbackFuture, EventState, RuleBase
10-
from sentry.rules.registry import RuleRegistry
1110

1211
logger = logging.getLogger("sentry.rules")
1312

1413

15-
def instantiate_action(rule: Rule, action, rules: RuleRegistry):
14+
def instantiate_action(rule: Rule, action):
15+
from sentry.rules import rules
16+
1617
action_cls = rules.get(action["id"])
1718
if action_cls is None:
1819
logger.warning("Unregistered action %r", action["id"])

src/sentry/rules/processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def apply_rule(self, rule: Rule, status: GroupRuleStatus) -> None:
268268
def activate_downstream_actions(self, rule: Rule, notification_uuid: str | None = None) -> None:
269269
state = self.get_state()
270270
for action in rule.data.get("actions", ()):
271-
action_inst = instantiate_action(rule, action, rules)
271+
action_inst = instantiate_action(rule, action)
272272
if not action_inst:
273273
continue
274274

tests/sentry/tasks/test_post_process.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,11 @@ def test_rule_processor_buffer_values(self):
403403
MOCK_RULES = ("sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter",)
404404

405405
redis_buffer = RedisBuffer()
406-
with (
407-
mock.patch("sentry.buffer.backend.get", redis_buffer.get),
408-
mock.patch("sentry.buffer.backend.incr", redis_buffer.incr),
409-
patch("sentry.constants._SENTRY_RULES", MOCK_RULES),
410-
patch("sentry.rules.processor.rules", init_registry()) as rules,
411-
):
406+
with mock.patch("sentry.buffer.backend.get", redis_buffer.get), mock.patch(
407+
"sentry.buffer.backend.incr", redis_buffer.incr
408+
), patch("sentry.constants._SENTRY_RULES", MOCK_RULES), patch(
409+
"sentry.rules.rules", init_registry()
410+
) as rules:
412411
MockAction = mock.Mock()
413412
MockAction.id = "tests.sentry.tasks.post_process.tests.MockAction"
414413
MockAction.return_value = mock.Mock(spec=EventAction)

0 commit comments

Comments
 (0)