
This commit intentionally introduces a number of important API breakages. Specifically, the jenkins_jobs.cmd module has been pared down to some of its most difficult-to-refactor elements. * Create jenkins_jobs.cli.entry.JenkinsJobs class to organize command line parsing and execution. * Remove references to ConfigParser object in test code, hidden as an implementation detail of JenkinsJobs command line parsing. This will be necessary in the next stage of JJB 2.0 code which will be to create a JJBConfig object that handles logic and presentation of configuration from various sources--defaults, command line arguments, configuration file, and maybe environment variables in the future. * Remove references to Namespace object produced by argparse module. Required rewrite of multipath & recursive path tests with a new MatchesDir testtools Matcher class that validates the expected output for a run of JJB against a given set of yamldirs with the specified command line arguments. * Use stevedore to dynamically load subcommand parsers. * Move configuration loading/testing to its own test file. Also fix the global vs home directory JJB config file test. Change-Id: If62280418ba7319c313033ab387af4284237747e
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import os
|
|
|
|
from tests.base import mock
|
|
from tests.cmd.test_cmd import CmdTestsBase
|
|
|
|
|
|
@mock.patch('jenkins_jobs.builder.Jenkins.get_plugins_info', mock.MagicMock)
|
|
class DeleteTests(CmdTestsBase):
|
|
|
|
@mock.patch('jenkins_jobs.cmd.Builder.delete_job')
|
|
def test_delete_single_job(self, delete_job_mock):
|
|
"""
|
|
Test handling the deletion of a single Jenkins job.
|
|
"""
|
|
|
|
args = ['--conf', self.default_config_file, 'delete', 'test_job']
|
|
self.execute_jenkins_jobs_with_args(args)
|
|
|
|
@mock.patch('jenkins_jobs.cmd.Builder.delete_job')
|
|
def test_delete_multiple_jobs(self, delete_job_mock):
|
|
"""
|
|
Test handling the deletion of multiple Jenkins jobs.
|
|
"""
|
|
|
|
args = ['--conf', self.default_config_file,
|
|
'delete', 'test_job1', 'test_job2']
|
|
self.execute_jenkins_jobs_with_args(args)
|
|
|
|
@mock.patch('jenkins_jobs.builder.Jenkins.delete_job')
|
|
def test_delete_using_glob_params(self, delete_job_mock):
|
|
"""
|
|
Test handling the deletion of multiple Jenkins jobs using the glob
|
|
parameters feature.
|
|
"""
|
|
|
|
args = ['--conf', self.default_config_file,
|
|
'delete', '--path',
|
|
os.path.join(self.fixtures_path,
|
|
'cmd-002.yaml'),
|
|
'*bar*']
|
|
self.execute_jenkins_jobs_with_args(args)
|
|
calls = [mock.call('bar001'), mock.call('bar002')]
|
|
delete_job_mock.assert_has_calls(calls, any_order=True)
|
|
self.assertEqual(delete_job_mock.call_count, len(calls),
|
|
"Jenkins.delete_job() was called '%s' times when "
|
|
"expected '%s'" % (delete_job_mock.call_count,
|
|
len(calls)))
|