Skip to content

Commit

Permalink
write more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schew2381 committed Aug 29, 2024
1 parent 2e07d67 commit 609157f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/sentry/receivers/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def create_default_rules(
user = AnonymousUser()

# Prioritize sending notifications to teams over individual users.
if team_ids and access:
if team_ids:
target_ids = team_ids
target_type = TargetType.TEAM
else:
Expand Down
43 changes: 17 additions & 26 deletions tests/sentry/receivers/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def _setup_flags(self):
with self.feature(["organizations:priority-ga-features", "organizations:incidents"]):
yield

def assert_high_priority_alert_created(self):
def tearDown(self):
"""Ensure the default priority alert rule is always created."""
super().tearDown()
assert Rule.objects.count() == 1
assert Rule.objects.filter(
project=self.project,
Expand All @@ -71,14 +73,19 @@ def test_no_feature_flag(self):
team_ids=[self.team.id],
sender=self,
)
self.assert_high_priority_alert_created()
assert AlertRule.objects.count() == 0

# test no user and no team_ids

# test no user, team_ids
@with_feature("organizations:default-metric-alerts-new-projects")
def test_no_user_or_team_passed(self):
project_created.send(
project=self.project,
access=self.from_user(self.user, self.organization),
default_rules=True,
sender=self,
)
assert AlertRule.objects.count() == 0

# test sending to user
@with_feature({"organizations:default-metric-alerts-new-projects": True})
@with_feature("organizations:default-metric-alerts-new-projects")
def test_send_triggers_to_user(self):
project_created.send(
project=self.project,
Expand All @@ -97,28 +104,12 @@ def test_send_triggers_to_user(self):
# Ensure that the expected fields are a subset of the actual model fields
assert expected_fields.items() <= model_to_dict(metric_alert).items()

self.assert_high_priority_alert_created()
# TODO: Check triggers to ensure we're sending to the correct user

# test sending to user invalid access

# test sending to one team

# test sending to one team without correct access

# test sending to multiple teams

# assert Rule fetched rule

# def test_include_all_projects_enabled(self):
# request = self.make_request(user=self.user)
# accesses = [
# self.from_user(self.user, self.organization),
# self.from_request(request, self.organization),
# ]

# for access in accesses:
# project_created.send(
# project=self.project,
# default_rules=True,
# user=self.user,
# access=None,
# sender=DefaultRulesTest,
# )

0 comments on commit 609157f

Please sign in to comment.