Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(aci milestone 3): refactor migration helper tests #84285

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/sentry/testutils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
query_datasets_to_type,
)
from sentry.incidents.models.alert_rule import (
AlertRule,
AlertRuleDetectionType,
AlertRuleThresholdType,
AlertRuleTriggerAction,
Expand Down Expand Up @@ -170,6 +171,8 @@
from sentry.utils.performance_issues.performance_problem import PerformanceProblem
from sentry.workflow_engine.models import (
Action,
AlertRuleDetector,
AlertRuleWorkflow,
DataCondition,
DataConditionGroup,
DataConditionGroupAction,
Expand Down Expand Up @@ -2215,3 +2218,29 @@ def create_data_condition_group_action(
return DataConditionGroupAction.objects.create(
action=action, condition_group=condition_group, **kwargs
)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_alert_rule_detector(
alert_rule: AlertRule | None = None,
detector: Detector | None = None,
**kwargs,
) -> AlertRuleDetector:
if alert_rule is None:
alert_rule = Factories.create_alert_rule()
if detector is None:
detector = Factories.create_detector()
return AlertRuleDetector.objects.create(alert_rule=alert_rule, detector=detector)

@staticmethod
@assume_test_silo_mode(SiloMode.REGION)
def create_alert_rule_workflow(
alert_rule: AlertRule | None = None,
workflow: Workflow | None = None,
**kwargs,
) -> AlertRuleWorkflow:
if alert_rule is None:
alert_rule = Factories.create_alert_rule()
if workflow is None:
workflow = Factories.create_workflow()
return AlertRuleWorkflow.objects.create(alert_rule=alert_rule, workflow=workflow)
mifu67 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions src/sentry/testutils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,12 @@ def create_detector_workflow(self, *args, **kwargs):
def create_workflow_data_condition_group(self, *args, **kwargs):
return Factories.create_workflow_data_condition_group(*args, **kwargs)

def create_alert_rule_detector(self, *args, **kwargs):
return Factories.create_alert_rule_detector(*args, **kwargs)

def create_alert_rule_workflow(self, *args, **kwargs):
return Factories.create_alert_rule_workflow(*args, **kwargs)

mifu67 marked this conversation as resolved.
Show resolved Hide resolved
# workflow_engine.models.action
def create_action(self, *args, **kwargs):
return Factories.create_action(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def migrate_alert_rule(
)


def update_migrated_alert_rule(alert_rule: AlertRule, updated_fields: dict[str, Any]) -> (
def dual_update_migrated_alert_rule(alert_rule: AlertRule, updated_fields: dict[str, Any]) -> (
tuple[
DetectorState,
Detector,
Expand Down
Loading
Loading