@@ -495,18 +495,32 @@ def test_integration_clone_alert_definition(test_linode_client):
495495 "trigger_occurrences" : 1 ,
496496 }
497497
498- channels = list (
499- client .monitor . alert_channels ( )
500- ) # TODO: create channel instead of relying on pre-existing one
501- if not channels :
502- pytest . skip (
503- "No alert channels available on account for creating/cloning alert definitions"
504- )
498+ # Get valid users to create an alert channel
499+ users = list ( client .account . users () )
500+ if len ( users ) == 0 :
501+ pytest . skip ( "No account users available for creating alert channels" )
502+
503+ # Use the first user for the alert channel
504+ usernames = [ users [ 0 ]. username ]
505505
506506 created = None
507507 cloned_alert = None
508+ created_channel = None
508509
509510 try :
511+ # Create a new alert channel for this test
512+ created_channel = client .monitor .channel_create (
513+ label = f"{ get_test_label ()} -channel-{ int (time .time ())} " ,
514+ channel_type = "email" ,
515+ details = ChannelDetails (
516+ email = EmailDetails (
517+ recipient_type = "user" ,
518+ usernames = usernames ,
519+ )
520+ ),
521+ )
522+ channels = [created_channel ]
523+
510524 # Create the source alert definition
511525 created = client .monitor .create_alert_definition (
512526 service_type = service_type ,
@@ -566,3 +580,13 @@ def test_integration_clone_alert_definition(test_linode_client):
566580 AlertDefinition , created .id , service_type
567581 )
568582 delete_source_alert .delete ()
583+
584+ if created_channel :
585+ # Clean up the created channel
586+ try :
587+ created_channel .delete ()
588+ except Exception as e :
589+ # Log but don't fail if cleanup fails
590+ print (
591+ f"Warning: Failed to delete channel { created_channel .id } : { e } "
592+ )
0 commit comments