@@ -254,5 +254,29 @@ def test_set_branch(self, patched_get_job_name, patched_get_job_config, patched_
254254 patched_reconfig_job .reset_mock ()
255255 self .patched_print .reset_mock ()
256256
257+ @mock .patch .object (jenkins .Jenkins , 'build_job' , return_value = None )
258+ @mock .patch .object (jenkins .Jenkins , 'get_job_name' , return_value = 'Job1' )
259+ def test_start (self , patched_job_name , patched_build_job ):
260+ self .args .job_name = ['Job1' ]
261+ JenkinsCli (self .args ).start (self .args )
262+ patched_build_job .assert_called_once_with ('Job1' )
263+ self .patched_print .assert_called_once_with ("%s: %s" % ('Job1' , 'started' ))
264+
265+ @mock .patch .object (jenkins .Jenkins , 'stop_build' , return_value = None )
266+ @mock .patch .object (jenkins .Jenkins , 'get_job_info' )
267+ @mock .patch .object (jenkins .Jenkins , 'get_job_name' , return_value = 'Job1' )
268+ def test_stop (self , patched_job_name , patched_job_info , patched_stop_build ):
269+ self .args .job_name = 'Job1'
270+ patched_job_info .return_value = {'lastBuild' : {}}
271+ JenkinsCli (self .args ).stop (self .args )
272+ self .assertFalse (patched_stop_build .called )
273+ self .patched_print .assert_called_once_with ("%s job is not running" % 'Job1' )
274+ self .patched_print .reset_mock ()
275+
276+ patched_job_info .return_value = {'lastBuild' : {'building' : True , 'number' : 22 }}
277+ JenkinsCli (self .args ).stop (self .args )
278+ patched_stop_build .assert_called_once_with ('Job1' , 22 )
279+ self .patched_print .assert_called_once_with ("Job1: stopped" )
280+
257281if __name__ == '__main__' :
258282 unittest .main ()
0 commit comments