|
18 | 18 | CustomHeader, |
19 | 19 | CustomHTTPSLogsDestinationDetails, |
20 | 20 | DestinationAuthentication, |
| 21 | + EmailDetails, |
21 | 22 | LogsDestinationDetailsBase, |
22 | 23 | LogsStreamDetails, |
23 | 24 | LogsStreamType, |
@@ -195,6 +196,61 @@ def test_alert_channels(self): |
195 | 196 | ) |
196 | 197 | self.assertEqual(channels[0].alerts.alert_count, 0) |
197 | 198 |
|
| 199 | + def test_create_update_delete_channel(self): |
| 200 | + """Test the parent email channel create, update, and delete lifecycle.""" |
| 201 | + create_url = "/monitor/alert-channels" |
| 202 | + channel_id = 999 |
| 203 | + channel_url = f"{create_url}/{channel_id}" |
| 204 | + create_response = { |
| 205 | + "id": channel_id, |
| 206 | + "label": "CRUD Test Channel", |
| 207 | + "type": "user", |
| 208 | + "channel_type": "email", |
| 209 | + "details": { |
| 210 | + "email": { |
| 211 | + "usernames": ["crud_user1", "crud_user2"], |
| 212 | + "recipient_type": "user", |
| 213 | + } |
| 214 | + }, |
| 215 | + "alerts": { |
| 216 | + "url": f"{channel_url}/alerts", |
| 217 | + "type": "alerts-definitions", |
| 218 | + "alert_count": 0, |
| 219 | + }, |
| 220 | + "created": "2024-01-01T00:00:00", |
| 221 | + "updated": "2024-01-01T00:00:00", |
| 222 | + "created_by": "crud_user1", |
| 223 | + "updated_by": "crud_user1", |
| 224 | + } |
| 225 | + |
| 226 | + with self.mock_post(create_response) as mock_post: |
| 227 | + channel = self.client.monitor.channel_create( |
| 228 | + label="CRUD Test Channel", |
| 229 | + channel_type="email", |
| 230 | + details=ChannelDetails( |
| 231 | + email=EmailDetails( |
| 232 | + recipient_type="user", |
| 233 | + usernames=["crud_user1", "crud_user2"], |
| 234 | + ) |
| 235 | + ), |
| 236 | + ) |
| 237 | + self.assertEqual(mock_post.call_url, create_url) |
| 238 | + self.assertIsInstance(channel, AlertChannel) |
| 239 | + self.assertEqual(channel.channel_type, "email") |
| 240 | + |
| 241 | + updated_response = create_response.copy() |
| 242 | + updated_response["label"] = "CRUD Test Channel Updated" |
| 243 | + with self.mock_put(updated_response) as mock_put: |
| 244 | + channel.label = "CRUD Test Channel Updated" |
| 245 | + self.assertTrue(channel.save()) |
| 246 | + |
| 247 | + self.assertEqual(mock_put.call_url, channel_url) |
| 248 | + self.assertEqual(channel.label, "CRUD Test Channel Updated") |
| 249 | + |
| 250 | + with self.mock_delete() as mock_delete: |
| 251 | + self.assertTrue(channel.delete()) |
| 252 | + self.assertEqual(mock_delete.call_url, channel_url) |
| 253 | + |
198 | 254 | def test_webhook_channel_validation(self): |
199 | 255 | """ |
200 | 256 | Test webhook channel validation constraints for create and verify operations. |
@@ -288,14 +344,15 @@ def test_webhook_channel_validation(self): |
288 | 344 | self.client.monitor._validate_webhook_details(webhook_details) |
289 | 345 | self.assertIn("Content-Type", str(cm.exception)) |
290 | 346 |
|
291 | | - def test_create_update_verify_delete_webhook_channel(self): |
| 347 | + def test_create_get_update_verify_delete_webhook_channel(self): |
292 | 348 | """ |
293 | | - Test webhook channel create, update, verify, and delete operations. |
| 349 | + Test webhook channel create, get, update, verify, and delete operations. |
294 | 350 | Verifies the full lifecycle of a webhook alert channel object: |
295 | 351 | 1. POST /monitor/alert-channels - Create webhook channel |
296 | | - 2. PUT /monitor/alert-channels/{id} - Update channel label |
297 | | - 3. POST /monitor/alert-channels/verify - Verify webhook configuration |
298 | | - 4. DELETE /monitor/alert-channels/{id} - Delete the channel |
| 352 | + 2. GET /monitor/alert-channels/{id} - Retrieve webhook channel |
| 353 | + 3. PUT /monitor/alert-channels/{id} - Update channel label |
| 354 | + 4. POST /monitor/alert-channels/verify - Verify webhook configuration |
| 355 | + 5. DELETE /monitor/alert-channels/{id} - Delete the channel |
299 | 356 | """ |
300 | 357 | create_url = "/monitor/alert-channels" |
301 | 358 | channel_id = 888 |
@@ -367,6 +424,17 @@ def test_create_update_verify_delete_webhook_channel(self): |
367 | 424 | webhook_channel.details.webhook.authentication.type, "basic" |
368 | 425 | ) |
369 | 426 |
|
| 427 | + # GET: Retrieve the webhook channel by ID |
| 428 | + with self.mock_get(create_response) as m_get: |
| 429 | + webhook_channel = self.client.load(AlertChannel, channel_id) |
| 430 | + |
| 431 | + self.assertEqual(m_get.call_url, channel_url) |
| 432 | + self.assertEqual(webhook_channel.channel_type, "webhook") |
| 433 | + self.assertEqual( |
| 434 | + webhook_channel.details.webhook.endpoint_url, |
| 435 | + "https://example.com/webhook", |
| 436 | + ) |
| 437 | + |
370 | 438 | # UPDATE: Update the webhook channel label |
371 | 439 | update_response = create_response.copy() |
372 | 440 | update_response["label"] = "python-sdk-webhook-change-updated" |
|
0 commit comments