@@ -97,13 +97,37 @@ def test_schedule_ssm_with_os(self, mock_shell):
9797 "owner" : "alice" ,
9898 }
9999 mock_shell .connection .api .create_schedule .return_value = {"id" : 1 }
100+ mock_shell .connection .api .get_os_list .return_value = [
101+ {"Id" : 1 , "Title" : "RHEL 9.4" , "Release Name" : "" , "Family" : "Redhat" },
102+ ]
100103
101104 user_cmd = UserCommands (mock_shell )
102105 user_cmd .cmd_schedule ('1 description "Test" os "RHEL 9.4"' )
103106
104107 call_args = mock_shell .connection .api .create_self_assignment .call_args [0 ][0 ]
105108 assert call_args ["ostype" ] == "RHEL 9.4"
106109
110+ def test_schedule_ssm_with_invalid_os (self , mock_shell ):
111+ """Test SSM schedule rejects invalid OS and does not call API"""
112+ mock_shell .connection .is_connected = True
113+ mock_shell .connection .is_authenticated = True
114+ mock_shell .connection .is_admin = False
115+ mock_shell .connection .username = "alice@example.com"
116+ mock_shell .connection .api .filter_available .return_value = [
117+ {"name" : "host01.example.com" },
118+ ]
119+ mock_shell .connection .api .get_os_list .return_value = [
120+ {"Id" : 1 , "Title" : "RHEL 9.4" , "Release Name" : "" , "Family" : "Redhat" },
121+ ]
122+
123+ user_cmd = UserCommands (mock_shell )
124+ user_cmd .cmd_schedule ('1 description "Test" os "--help"' )
125+
126+ mock_shell .connection .api .create_self_assignment .assert_not_called ()
127+ mock_shell .perror .assert_called ()
128+ error_msg = mock_shell .perror .call_args [0 ][0 ]
129+ assert "not found" in error_msg
130+
107131 def test_schedule_ssm_insufficient_hosts (self , mock_shell ):
108132 """Test SSM schedule with insufficient available hosts"""
109133 mock_shell .connection .is_connected = True
@@ -703,6 +727,9 @@ def test_schedule_admin_batch_with_os(self, mock_shell):
703727 "schedules_created" : 1 ,
704728 "hostnames" : ["host01.example.com" ],
705729 }
730+ mock_shell .connection .api .get_os_list .return_value = [
731+ {"Id" : 1 , "Title" : "RHEL 9.4" , "Release Name" : "" , "Family" : "Redhat" },
732+ ]
706733
707734 schedule_cmd = ScheduleCommands (mock_shell )
708735 cmd = (
@@ -713,3 +740,25 @@ def test_schedule_admin_batch_with_os(self, mock_shell):
713740
714741 batch_data = mock_shell .connection .api .create_schedules_batch .call_args [0 ][0 ]
715742 assert batch_data ["ostype" ] == "RHEL 9.4"
743+
744+ def test_schedule_admin_batch_with_invalid_os (self , mock_shell ):
745+ """Test batch schedule rejects invalid OS and does not call API"""
746+ mock_shell .connection .is_connected = True
747+ mock_shell .connection .is_authenticated = True
748+ mock_shell .connection .is_admin = True
749+ mock_shell .connection .api .filter_clouds .return_value = [{"name" : "cloud02" }]
750+ mock_shell .connection .api .get_os_list .return_value = [
751+ {"Id" : 1 , "Title" : "RHEL 9.4" , "Release Name" : "" , "Family" : "Redhat" },
752+ ]
753+
754+ schedule_cmd = ScheduleCommands (mock_shell )
755+ cmd = (
756+ 'cloud02 host01 "2026-05-11 22:00" "2026-06-11 22:00" '
757+ 'description "Test" cloud-owner jdoe cloud-ticket 123 os "bogus"'
758+ )
759+ schedule_cmd .cmd_schedule_admin (cmd )
760+
761+ mock_shell .connection .api .create_schedules_batch .assert_not_called ()
762+ mock_shell .perror .assert_called ()
763+ error_msg = mock_shell .perror .call_args [0 ][0 ]
764+ assert "not found" in error_msg
0 commit comments