@@ -1133,6 +1133,79 @@ def test_create_schedule(self, mock_post):
11331133 assert mock_post .call_args [1 ]["json" ] == schedule_data
11341134 assert result == schedule_data
11351135
1136+ @patch ("requests.Session.request" )
1137+ def test_create_schedules_batch (self , mock_post ):
1138+ batch_data = {
1139+ "cloud" : "cloud1" ,
1140+ "hostnames" : ["host1" , "host2" , "host3" ],
1141+ "start" : "2024-03-20 10:00" ,
1142+ "end" : "2024-03-21 10:00" ,
1143+ }
1144+ expected_response = {
1145+ "assignment_id" : 42 ,
1146+ "schedules_created" : 3 ,
1147+ "hostnames" : ["host1" , "host2" , "host3" ],
1148+ "jira_updated" : True ,
1149+ }
1150+ mock_response = Mock ()
1151+ mock_response .status_code = 200
1152+ mock_response .json .return_value = expected_response
1153+ mock_post .return_value = mock_response
1154+
1155+ result = self .api .create_schedules_batch (batch_data )
1156+
1157+ mock_post .assert_called_once ()
1158+ assert str (mock_post .call_args [0 ][1 ]).endswith ("/schedules/batch" )
1159+ assert mock_post .call_args [1 ]["json" ] == batch_data
1160+ assert result == expected_response
1161+
1162+ @patch ("requests.Session.request" )
1163+ def test_create_schedules_batch_with_assignment_params (self , mock_post ):
1164+ batch_data = {
1165+ "cloud" : "cloud2" ,
1166+ "hostnames" : ["host1" , "host2" ],
1167+ "start" : "now" ,
1168+ "end" : "2024-03-21 10:00" ,
1169+ "description" : "Test assignment" ,
1170+ "owner" : "testuser" ,
1171+ "ticket" : "JIRA-123" ,
1172+ "ccuser" : "user1,user2" ,
1173+ "vlan" : 1234 ,
1174+ "qinq" : 1 ,
1175+ }
1176+ expected_response = {
1177+ "assignment_id" : 158 ,
1178+ "schedules_created" : 2 ,
1179+ "hostnames" : ["host1" , "host2" ],
1180+ "jira_updated" : True ,
1181+ }
1182+ mock_response = Mock ()
1183+ mock_response .status_code = 200
1184+ mock_response .json .return_value = expected_response
1185+ mock_post .return_value = mock_response
1186+
1187+ result = self .api .create_schedules_batch (batch_data )
1188+
1189+ mock_post .assert_called_once ()
1190+ assert str (mock_post .call_args [0 ][1 ]).endswith ("/schedules/batch" )
1191+ assert mock_post .call_args [1 ]["json" ] == batch_data
1192+ assert result == expected_response
1193+
1194+ @patch ("requests.Session.request" )
1195+ def test_create_schedules_batch_error (self , mock_post ):
1196+ batch_data = {
1197+ "cloud" : "cloud1" ,
1198+ "hostnames" : ["host1" ],
1199+ "start" : "2024-03-20 10:00" ,
1200+ "end" : "2024-03-21 10:00" ,
1201+ }
1202+ mock_response = Mock ()
1203+ mock_response .status_code = 400
1204+ mock_post .return_value = mock_response
1205+
1206+ with pytest .raises (APIBadRequest ):
1207+ self .api .create_schedules_batch (batch_data )
1208+
11361209 @patch ("requests.Session.request" )
11371210 def test_get_available (self , mock_get ):
11381211 expected_response = {
0 commit comments