Merge "Eliminate redundant calls to assert_job_exists()"
This commit is contained in:
commit
b0302b0d0f
@ -473,7 +473,6 @@ class Jenkins(object):
|
||||
:param from_name: Name of Jenkins job to copy from, ``str``
|
||||
:param to_name: Name of Jenkins job to copy to, ``str``
|
||||
'''
|
||||
self.assert_job_exists(from_name)
|
||||
self.jenkins_open(Request(
|
||||
self.server + COPY_JOB % self._get_encoded_params(locals()), ''))
|
||||
self.assert_job_exists(to_name, 'create[%s] failed')
|
||||
@ -484,7 +483,6 @@ class Jenkins(object):
|
||||
:param from_name: Name of Jenkins job to rename, ``str``
|
||||
:param to_name: New Jenkins job name, ``str``
|
||||
'''
|
||||
self.assert_job_exists(from_name)
|
||||
self.jenkins_open(Request(
|
||||
self.server + RENAME_JOB % self._get_encoded_params(locals()), ''))
|
||||
self.assert_job_exists(to_name, 'rename[%s] failed')
|
||||
@ -494,7 +492,6 @@ class Jenkins(object):
|
||||
|
||||
:param name: Name of Jenkins job, ``str``
|
||||
'''
|
||||
self.assert_job_exists(name)
|
||||
self.jenkins_open(Request(
|
||||
self.server + DELETE_JOB % self._get_encoded_params(locals()), ''))
|
||||
if self.job_exists(name):
|
||||
@ -505,7 +502,6 @@ class Jenkins(object):
|
||||
|
||||
:param name: Name of Jenkins job, ``str``
|
||||
'''
|
||||
self.assert_job_exists(name)
|
||||
self.jenkins_open(Request(
|
||||
self.server + ENABLE_JOB % self._get_encoded_params(locals()), ''))
|
||||
|
||||
@ -516,7 +512,6 @@ class Jenkins(object):
|
||||
|
||||
:param name: Name of Jenkins job, ``str``
|
||||
'''
|
||||
self.assert_job_exists(name)
|
||||
self.jenkins_open(Request(
|
||||
self.server + DISABLE_JOB % self._get_encoded_params(locals()), ''))
|
||||
|
||||
@ -572,7 +567,6 @@ class Jenkins(object):
|
||||
:param name: Name of Jenkins job, ``str``
|
||||
:param config_xml: New XML configuration, ``str``
|
||||
'''
|
||||
self.assert_job_exists(name)
|
||||
headers = {'Content-Type': 'text/xml'}
|
||||
reconfig_url = self.server + CONFIG_JOB % self._get_encoded_params(locals())
|
||||
self.jenkins_open(Request(reconfig_url, config_xml, headers))
|
||||
@ -605,7 +599,6 @@ class Jenkins(object):
|
||||
:param parameters: parameters for job, or ``None``, ``dict``
|
||||
:param token: Jenkins API token
|
||||
'''
|
||||
self.assert_job_exists(name, 'no such job[%s]')
|
||||
return self.jenkins_open(Request(
|
||||
self.build_job_url(name, parameters, token), ""))
|
||||
|
||||
|
@ -290,7 +290,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_build_job(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
{'foo': 'bar'},
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
@ -304,7 +303,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_build_job__with_token(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
{'foo': 'bar'},
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
@ -318,7 +316,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_build_job__with_parameters_and_token(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
{'foo': 'bar'},
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
@ -333,20 +330,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
self.assertTrue('why=because+I+felt+like+it' in jenkins_mock.call_args[0][0].get_full_url())
|
||||
self.assertEqual(build_info, {'foo': 'bar'})
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_build_job__job_doesnt_exist(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = jenkins.NotFoundException()
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
|
||||
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
||||
j.build_job(u'TestJob')
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/TestJob/api/json?tree=name')
|
||||
self.assertEqual(
|
||||
str(context_manager.exception),
|
||||
'no such job[TestJob]')
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_stop_build(self, jenkins_mock):
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
@ -831,7 +814,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_copy_job(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
json.dumps({'name': 'Test Job_2'}),
|
||||
json.dumps({'name': 'Test Job_2'}),
|
||||
json.dumps({'name': 'Test Job_2'}),
|
||||
@ -841,7 +823,7 @@ class JenkinsTest(unittest.TestCase):
|
||||
j.copy_job(u'Test Job', u'Test Job_2')
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/createItem'
|
||||
'?name=Test%20Job_2&mode=copy&from=Test%20Job')
|
||||
self.assertTrue(j.job_exists('Test Job_2'))
|
||||
@ -849,7 +831,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_copy_job__create_failed(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
None,
|
||||
jenkins.NotFoundException(),
|
||||
]
|
||||
@ -858,7 +839,7 @@ class JenkinsTest(unittest.TestCase):
|
||||
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
||||
j.copy_job(u'TestJob', u'TestJob_2')
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/createItem'
|
||||
'?name=TestJob_2&mode=copy&from=TestJob')
|
||||
self.assertEqual(
|
||||
@ -868,7 +849,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_rename_job(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
json.dumps({'name': 'Test Job_2'}),
|
||||
json.dumps({'name': 'Test Job_2'}),
|
||||
json.dumps({'name': 'Test Job_2'}),
|
||||
@ -878,14 +858,13 @@ class JenkinsTest(unittest.TestCase):
|
||||
j.rename_job(u'Test Job', u'Test Job_2')
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/Test%20Job/doRename?newName=Test%20Job_2')
|
||||
self.assertTrue(j.job_exists('Test Job_2'))
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_rename_job__rename_failed(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
None,
|
||||
jenkins.NotFoundException(),
|
||||
]
|
||||
@ -894,7 +873,7 @@ class JenkinsTest(unittest.TestCase):
|
||||
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
||||
j.rename_job(u'TestJob', u'TestJob_2')
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/TestJob/doRename?newName=TestJob_2')
|
||||
self.assertEqual(
|
||||
str(context_manager.exception),
|
||||
@ -903,7 +882,6 @@ class JenkinsTest(unittest.TestCase):
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_delete_job(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
None,
|
||||
jenkins.NotFoundException(),
|
||||
]
|
||||
@ -912,7 +890,7 @@ class JenkinsTest(unittest.TestCase):
|
||||
j.delete_job(u'Test Job')
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/Test%20Job/doDelete')
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
@ -921,14 +899,13 @@ class JenkinsTest(unittest.TestCase):
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
|
||||
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
||||
j.delete_job(u'TestJob')
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/TestJob/doDelete')
|
||||
self.assertEqual(
|
||||
str(context_manager.exception),
|
||||
@ -939,14 +916,13 @@ class JenkinsTest(unittest.TestCase):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
json.dumps({'name': 'TestJob'}),
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
|
||||
j.enable_job(u'TestJob')
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/TestJob/enable')
|
||||
self.assertTrue(j.job_exists('TestJob'))
|
||||
|
||||
@ -955,14 +931,13 @@ class JenkinsTest(unittest.TestCase):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
json.dumps({'name': 'Test Job'}),
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
|
||||
j.disable_job(u'Test Job')
|
||||
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
||||
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
||||
'http://example.com/job/Test%20Job/disable')
|
||||
self.assertTrue(j.job_exists('Test Job'))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user