|
32 | 32 | get_rules_to_groups, |
33 | 33 | get_rules_to_slow_conditions, |
34 | 34 | get_slow_conditions, |
| 35 | + parse_rulegroup_to_event_data, |
35 | 36 | process_delayed_alert_conditions, |
36 | 37 | ) |
37 | 38 | from sentry.rules.processing.processor import PROJECT_ID_BUFFER_LIST_KEY |
@@ -562,8 +563,44 @@ def test_get_slow_conditions__only_fast(self): |
562 | 563 |
|
563 | 564 |
|
564 | 565 | class ParseRuleGroupToEventDataTest(TestCase): |
565 | | - def test_parse_rulegroup_to_event_data(self): |
566 | | - pass |
| 566 | + def setUp(self): |
| 567 | + self.project = self.create_project() |
| 568 | + self.group = self.create_group(self.project) |
| 569 | + self.group_two = self.create_group(self.project) |
| 570 | + self.rule = self.create_alert_rule(self.organization, [self.project]) |
| 571 | + self.rule_two = self.create_alert_rule(self.organization, [self.project]) |
| 572 | + |
| 573 | + self.event_data = { |
| 574 | + "event_id": "1", |
| 575 | + "occurrence_id": "1", |
| 576 | + } |
| 577 | + |
| 578 | + def test_parse_rulegroup(self): |
| 579 | + input_data = { |
| 580 | + f"{self.rule.id}:{self.group.id}": json.dumps(self.event_data), |
| 581 | + f"{self.rule_two.id}:{self.group_two.id}": json.dumps(self.event_data), |
| 582 | + } |
| 583 | + |
| 584 | + result = parse_rulegroup_to_event_data(input_data) |
| 585 | + assert result == { |
| 586 | + (str(self.rule.id), str(self.group.id)): self.event_data, |
| 587 | + (str(self.rule_two.id), str(self.group_two.id)): self.event_data, |
| 588 | + } |
| 589 | + |
| 590 | + def test_parse_rulegroup_empty(self): |
| 591 | + input_data: dict[str, str] = {} |
| 592 | + result = parse_rulegroup_to_event_data(input_data) |
| 593 | + assert result == {} |
| 594 | + |
| 595 | + def test_parse_rulegroup_basic(self): |
| 596 | + input_data = {f"{self.rule.id}:{self.group.id}": json.dumps(self.event_data)} |
| 597 | + result = parse_rulegroup_to_event_data(input_data) |
| 598 | + assert result == {(str(self.rule.id), str(self.group.id)): self.event_data} |
| 599 | + |
| 600 | + def test_parse_rulegroup_invalid_json(self): |
| 601 | + input_data = {f"{self.rule.id}:{self.group.id}": "}"} |
| 602 | + with pytest.raises(json.JSONDecodeError): |
| 603 | + parse_rulegroup_to_event_data(input_data) |
567 | 604 |
|
568 | 605 |
|
569 | 606 | class ProcessDelayedAlertConditionsTest(CreateEventTestCase, PerformanceIssueTestCase): |
|
0 commit comments