|
2 | 2 | from test.unit.base import ClientBaseCase |
3 | 3 |
|
4 | 4 | from linode_api4.objects import AlertChannel, MonitorDashboard, MonitorService |
| 5 | +from linode_api4.objects.monitor import ChannelDetails, EmailDetails |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class MonitorTest(ClientBaseCase): |
@@ -169,3 +170,59 @@ def test_alert_channels(self): |
169 | 170 | "/monitor/alert-channels/123/alerts", |
170 | 171 | ) |
171 | 172 | self.assertEqual(channels[0].alerts.alert_count, 0) |
| 173 | + |
| 174 | + def test_create_channel(self): |
| 175 | + |
| 176 | + create_response = { |
| 177 | + "id": 456, |
| 178 | + "label": "Email channel for api change", |
| 179 | + "type": "user", |
| 180 | + "channel_type": "email", |
| 181 | + "details": { |
| 182 | + "email": { |
| 183 | + "recipient_type": "user", |
| 184 | + "usernames": ["mawasthy_tenant02_admin"], |
| 185 | + } |
| 186 | + }, |
| 187 | + "alerts": { |
| 188 | + "url": "/monitor/alert-channels/456/alerts", |
| 189 | + "type": "alerts-definitions", |
| 190 | + "alert_count": 0, |
| 191 | + }, |
| 192 | + "created": "2024-01-01T00:00:00", |
| 193 | + "updated": "2024-01-01T00:00:00", |
| 194 | + "created_by": "mawasthy_tenant02_admin", |
| 195 | + "updated_by": "mawasthy_tenant02_admin", |
| 196 | + } |
| 197 | + |
| 198 | + with self.mock_post(create_response) as m: |
| 199 | + result = self.client.monitor.channel_create( |
| 200 | + label="Email channel for api change", |
| 201 | + channel_type="email", |
| 202 | + details=ChannelDetails( |
| 203 | + email=EmailDetails( |
| 204 | + recipient_type="user", |
| 205 | + usernames=["mawasthy_tenant02_admin"], |
| 206 | + ) |
| 207 | + ), |
| 208 | + ) |
| 209 | + |
| 210 | + self.assertEqual(m.call_url, "/monitor/alert-channels") |
| 211 | + self.assertEqual(m.call_data["label"], "Email channel for api change") |
| 212 | + self.assertEqual(m.call_data["channel_type"], "email") |
| 213 | + self.assertEqual( |
| 214 | + m.call_data["details"]["email"]["recipient_type"], "user" |
| 215 | + ) |
| 216 | + self.assertEqual( |
| 217 | + m.call_data["details"]["email"]["usernames"], ["mawasthy_tenant02_admin"] |
| 218 | + ) |
| 219 | + |
| 220 | + self.assertIsInstance(result, AlertChannel) |
| 221 | + self.assertEqual(result.id, 456) |
| 222 | + self.assertEqual(result.label, "Email channel for api change") |
| 223 | + self.assertEqual(result.type, "user") |
| 224 | + self.assertEqual(result.channel_type, "email") |
| 225 | + self.assertIsNotNone(result.details) |
| 226 | + self.assertIsNotNone(result.details.email) |
| 227 | + self.assertEqual(result.details.email.recipient_type, "user") |
| 228 | + self.assertEqual(result.details.email.usernames, ["mawasthy_tenant02_admin"]) |
0 commit comments