@@ -251,3 +251,99 @@ def test_create_update_delete_alert_channel(self):
251251
252252 assert mock_delete .call_url == channel_url
253253 assert result is True
254+
255+ def test_alert_channel (self ):
256+ """
257+ Test retrieval of a specific alert channel by ID.
258+ Verifies the alert_channel method returns a single AlertChannel object.
259+ """
260+ channel_id = 123
261+ channel_url = f"/monitor/alert-channels/{ channel_id } "
262+
263+ channel_response = {
264+ "id" : channel_id ,
265+ "label" : "alert notification channel" ,
266+ "type" : "user" ,
267+ "channel_type" : "email" ,
268+ "details" : {
269+ "email" : {
270+ "usernames" : ["admin-user1" , "admin-user2" ],
271+ "recipient_type" : "user" ,
272+ }
273+ },
274+ "alerts" : {
275+ "url" : f"{ channel_url } /alerts" ,
276+ "type" : "alerts-definitions" ,
277+ "alert_count" : 2 ,
278+ },
279+ "created" : "2024-01-01T00:00:00" ,
280+ "updated" : "2024-01-01T00:00:00" ,
281+ "created_by" : "tester" ,
282+ "updated_by" : "tester" ,
283+ }
284+
285+ with self .mock_get (channel_response ) as mock_get :
286+ channel = self .client .monitor .alert_channel (channel_id = channel_id )
287+
288+ assert mock_get .call_url == channel_url
289+ assert isinstance (channel , AlertChannel )
290+ assert channel .id == channel_id
291+ assert channel .label == "alert notification channel"
292+ assert channel .channel_type == "email"
293+ assert channel .details .email .usernames == [
294+ "admin-user1" ,
295+ "admin-user2" ,
296+ ]
297+ assert channel .alerts .alert_count == 2
298+
299+ def test_alert_channel_alerts (self ):
300+ """
301+ Test retrieval of alerts associated with a specific alert channel.
302+ Verifies the alert_channel_alerts method returns a paginated list
303+ of AlertDefinition objects associated with the channel.
304+ """
305+ channel_id = 123
306+ alerts_url = f"/monitor/alert-channels/{ channel_id } /alerts"
307+
308+ alerts_response = {
309+ "data" : [
310+ {
311+ "id" : 12345 ,
312+ "label" : "DBAAS Alert 1" ,
313+ "service_type" : "dbaas" ,
314+ "type" : "alerts-definitions" ,
315+ "url" : "/monitor/services/dbaas/alerts-definitions/12345" ,
316+ },
317+ {
318+ "id" : 12346 ,
319+ "label" : "DBAAS Alert 2" ,
320+ "service_type" : "dbaas" ,
321+ "type" : "alerts-definitions" ,
322+ "url" : "/monitor/services/dbaas/alerts-definitions/12346" ,
323+ },
324+ ],
325+ "page" : 1 ,
326+ "pages" : 1 ,
327+ "results" : 2 ,
328+ }
329+
330+ with self .mock_get (alerts_response ) as mock_get :
331+ alerts = self .client .monitor .alert_channel_alerts (
332+ channel_id = channel_id
333+ )
334+
335+ assert mock_get .call_url == alerts_url
336+ assert isinstance (alerts , PaginatedList )
337+ assert len (alerts ) == 2
338+
339+ # Verify first alert
340+ assert isinstance (alerts [0 ], AlertDefinition )
341+ assert alerts [0 ].id == 12345
342+ assert alerts [0 ].label == "DBAAS Alert 1"
343+ assert alerts [0 ].service_type == "dbaas"
344+
345+ # Verify second alert
346+ assert isinstance (alerts [1 ], AlertDefinition )
347+ assert alerts [1 ].id == 12346
348+ assert alerts [1 ].label == "DBAAS Alert 2"
349+ assert alerts [1 ].service_type == "dbaas"
0 commit comments