add test for globbed parameters feature
add a test to verify commmand processing of the globbed parameters feature to delete jobs. Change-Id: Ib13a2c644388ac65cb1af5728019912d6452d852
This commit is contained in:
parent
0c7e623f6f
commit
4ce214b288
23
tests/cmd/fixtures/cmd-002.yaml
Normal file
23
tests/cmd/fixtures/cmd-002.yaml
Normal file
@ -0,0 +1,23 @@
|
||||
- job-template:
|
||||
name: 'bar001'
|
||||
description: 'My first job'
|
||||
|
||||
- job-template:
|
||||
name: 'bar002'
|
||||
description: 'My second job'
|
||||
|
||||
- job-template:
|
||||
name: 'baz001'
|
||||
description: 'My third job'
|
||||
|
||||
- job-template:
|
||||
name: 'bam001'
|
||||
description: 'My fourth job'
|
||||
|
||||
- project:
|
||||
name: my-projects
|
||||
jobs:
|
||||
- 'bar001'
|
||||
- 'bar002'
|
||||
- 'baz001'
|
||||
- 'bam001'
|
@ -11,12 +11,21 @@ from jenkins_jobs import cmd
|
||||
# attempting to create the cache directory multiple times as the tests
|
||||
# are run in parallel. Stub out the CacheStorage to ensure that each
|
||||
# test can safely create the cache directory without risk of interference.
|
||||
@mock.patch('jenkins_jobs.builder.CacheStorage', mock.MagicMock)
|
||||
class CmdTests(testtools.TestCase):
|
||||
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
parser = cmd.create_parser()
|
||||
|
||||
def setUp(self):
|
||||
super(CmdTests, self).setUp()
|
||||
self.cache_patch = mock.patch('jenkins_jobs.builder.CacheStorage',
|
||||
autospec=True)
|
||||
self.cache_patch.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.cache_patch.stop()
|
||||
super(CmdTests, self).tearDown()
|
||||
|
||||
def test_with_empty_args(self):
|
||||
"""
|
||||
User passes no args, should fail with SystemExit
|
||||
@ -230,3 +239,25 @@ class CmdTests(testtools.TestCase):
|
||||
config = configparser.ConfigParser()
|
||||
config.readfp(StringIO(cmd.DEFAULT_CONF))
|
||||
cmd.execute(args, config) # passes if executed without error
|
||||
|
||||
@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 = self.parser.parse_args(['delete',
|
||||
'--path',
|
||||
os.path.join(self.fixtures_path,
|
||||
'cmd-002.yaml'),
|
||||
'*bar*'])
|
||||
config = configparser.ConfigParser()
|
||||
config.readfp(StringIO(cmd.DEFAULT_CONF))
|
||||
cmd.execute(args, config)
|
||||
calls = [mock.call('bar001'), mock.call('bar002')]
|
||||
delete_job_mock.assert_has_calls(calls, any_order=True)
|
||||
self.assertEquals(delete_job_mock.call_count, len(calls),
|
||||
"Jenkins.delete_job() was called '%s' times when "
|
||||
"expected '%s'" % (delete_job_mock.call_count,
|
||||
len(calls)))
|
||||
|
Loading…
Reference in New Issue
Block a user