1
+ from datetime import datetime
2
+
3
+ import pytest
4
+
5
+ from pagerduty_mcp .models .alerts import Alert , AlertBody , AlertQuery , AlertSeverity , AlertStatus
6
+ from pagerduty_mcp .models .references import IncidentReference , IntegrationReference , ServiceReference
7
+
8
+
9
+ class TestAlertModels :
10
+ def test_alert_model_validation (self ):
11
+ """Test Alert model validation with required fields."""
12
+ service_ref = ServiceReference (id = "PSERVICE1" , summary = "Test Service" )
13
+
14
+ alert = Alert (
15
+ id = "PALERT1" ,
16
+ summary = "Test alert" ,
17
+ status = "triggered" ,
18
+ severity = "error" ,
19
+ created_at = datetime .now (),
20
+ updated_at = datetime .now (),
21
+ service = service_ref ,
22
+ )
23
+
24
+ assert alert .id == "PALERT1"
25
+ assert alert .summary == "Test alert"
26
+ assert alert .status == "triggered"
27
+ assert alert .severity == "error"
28
+ assert alert .type == "alert"
29
+ assert alert .service .id == "PSERVICE1"
30
+
31
+ def test_alert_model_with_relationships (self ):
32
+ """Test Alert model with optional relationship fields."""
33
+ service_ref = ServiceReference (id = "PSERVICE1" , summary = "Test Service" )
34
+ incident_ref = IncidentReference (id = "PINCIDENT1" , summary = "Test Incident" )
35
+ integration_ref = IntegrationReference (id = "PINTEGRATION1" , summary = "Test Integration" )
36
+ alert_body = AlertBody (details = "Detailed alert information" )
37
+
38
+ alert = Alert (
39
+ id = "PALERT1" ,
40
+ summary = "Test alert" ,
41
+ status = "acknowledged" ,
42
+ severity = "critical" ,
43
+ alert_key = "test-alert-key" ,
44
+ created_at = datetime .now (),
45
+ updated_at = datetime .now (),
46
+ resolved_at = datetime .now (),
47
+ service = service_ref ,
48
+ incident = incident_ref ,
49
+ integration = integration_ref ,
50
+ body = alert_body ,
51
+ )
52
+
53
+ assert alert .incident .id == "PINCIDENT1"
54
+ assert alert .integration .id == "PINTEGRATION1"
55
+ assert alert .body .details == "Detailed alert information"
56
+ assert alert .alert_key == "test-alert-key"
57
+
58
+ def test_alert_query_to_params (self ):
59
+ """Test AlertQuery parameter conversion."""
60
+ query = AlertQuery (
61
+ service_ids = ["PSERVICE1" , "PSERVICE2" ],
62
+ since = datetime (2023 , 1 , 1 , 10 , 0 , 0 ),
63
+ until = datetime (2023 , 1 , 2 , 10 , 0 , 0 ),
64
+ statuses = ["triggered" , "acknowledged" ],
65
+ severities = ["error" , "critical" ],
66
+ limit = 50 ,
67
+ )
68
+
69
+ params = query .to_params ()
70
+
71
+ assert params ["service_ids[]" ] == ["PSERVICE1" , "PSERVICE2" ]
72
+ assert params ["since" ] == "2023-01-01T10:00:00"
73
+ assert params ["until" ] == "2023-01-02T10:00:00"
74
+ assert params ["statuses[]" ] == ["triggered" , "acknowledged" ]
75
+ assert params ["severities[]" ] == ["error" , "critical" ]
76
+
77
+ def test_alert_query_empty_filters (self ):
78
+ """Test AlertQuery with no filters."""
79
+ query = AlertQuery ()
80
+ params = query .to_params ()
81
+
82
+ assert params == {}
83
+ assert query .limit == 100 # default limit
84
+
85
+ def test_alert_body_type (self ):
86
+ """Test AlertBody model type property."""
87
+ body = AlertBody (details = "Test alert details" )
88
+
89
+ assert body .type == "alert_body"
90
+ assert body .details == "Test alert details"
91
+
92
+ def test_alert_status_literal (self ):
93
+ """Test AlertStatus literal values."""
94
+ valid_statuses = ["triggered" , "acknowledged" , "resolved" , "suppressed" ]
95
+
96
+ for status in valid_statuses :
97
+ alert = Alert (
98
+ id = "PALERT1" ,
99
+ summary = "Test alert" ,
100
+ status = status ,
101
+ severity = "error" ,
102
+ created_at = datetime .now (),
103
+ updated_at = datetime .now (),
104
+ service = ServiceReference (id = "PSERVICE1" ),
105
+ )
106
+ assert alert .status == status
107
+
108
+ def test_alert_severity_literal (self ):
109
+ """Test AlertSeverity literal values."""
110
+ valid_severities = ["critical" , "error" , "warning" , "info" ]
111
+
112
+ for severity in valid_severities :
113
+ alert = Alert (
114
+ id = "PALERT1" ,
115
+ summary = "Test alert" ,
116
+ status = "triggered" ,
117
+ severity = severity ,
118
+ created_at = datetime .now (),
119
+ updated_at = datetime .now (),
120
+ service = ServiceReference (id = "PSERVICE1" ),
121
+ )
122
+ assert alert .severity == severity
0 commit comments