Adds assert_node_exists()
This is similar to recently introduced assert_job_exists(). It will
throws an exception whenever a node is missing and further customize the
exception messages.
Replace an occurence of:
if not self.node_exists(name):
raise JenkinsException('node[%s] already exists' % (name))
By:
self.assert_node_exists(name, 'node[%s] already exists')
Change-Id: Ia2e91843b353c02fb19290eadbbb83db8d2a3124
This commit is contained in:
@@ -926,6 +926,25 @@ class JenkinsTest(unittest.TestCase):
|
||||
str(context_manager.exception),
|
||||
'node[test_node] does not exist')
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_assert_node_exists__node_missing(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [None]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
|
||||
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
||||
j.assert_node_exists('NonExistentNode')
|
||||
self.assertEqual(
|
||||
str(context_manager.exception),
|
||||
'node[NonExistentNode] does not exist')
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_assert_node_exists__node_exists(self, jenkins_mock):
|
||||
jenkins_mock.side_effect = [
|
||||
json.dumps({'name': 'ExistingNode'})
|
||||
]
|
||||
j = jenkins.Jenkins('http://example.com/', 'test', 'test')
|
||||
j.assert_node_exists('ExistingNode')
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_delete_node(self, jenkins_mock):
|
||||
node_info = {
|
||||
|
||||
Reference in New Issue
Block a user