2aa1a5f1b8
It's important to check that we correctly handle the server url for all API calls, so ensure that the test code uses test scenarios to cover. Fix get_info() api call creation of url. Change-Id: Idb0becc4c0c56df81bc5545919e530b7a77dadc9
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import json
|
|
from mock import patch
|
|
|
|
import jenkins
|
|
from tests.base import JenkinsTestBase
|
|
|
|
|
|
class JenkinsQuietDownTest(JenkinsTestBase):
|
|
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
|
def test_success(self, jenkins_mock):
|
|
job_info_to_return = {
|
|
"quietingDown": True,
|
|
}
|
|
jenkins_mock.return_value = json.dumps(job_info_to_return)
|
|
|
|
self.j.quiet_down()
|
|
|
|
self.assertEqual(
|
|
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
|
self.make_url('quietDown'))
|
|
self.assertEqual(
|
|
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
|
self.make_url('api/json'))
|
|
self._check_requests(jenkins_mock.call_args_list)
|
|
|
|
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
|
def test_fail(self, jenkins_mock):
|
|
job_info_to_return = {
|
|
"quietingDown": False,
|
|
}
|
|
jenkins_mock.return_value = json.dumps(job_info_to_return)
|
|
|
|
with self.assertRaises(jenkins.JenkinsException) as context_manager:
|
|
self.j.quiet_down()
|
|
|
|
self.assertEqual(
|
|
jenkins_mock.call_args_list[0][0][0].get_full_url(),
|
|
self.make_url('quietDown'))
|
|
self.assertEqual(
|
|
jenkins_mock.call_args_list[1][0][0].get_full_url(),
|
|
self.make_url('api/json'))
|
|
self.assertEqual(
|
|
str(context_manager.exception),
|
|
'quiet down failed')
|
|
self._check_requests(jenkins_mock.call_args_list)
|
|
|
|
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
|
def test_http_fail(self, jenkins_mock):
|
|
jenkins_mock.side_effect = jenkins.JenkinsException(
|
|
'Error in request. Possibly authentication failed [401]: '
|
|
'basic auth failed')
|
|
|
|
with self.assertRaises(jenkins.JenkinsException):
|
|
self.j.quiet_down()
|
|
|
|
self.assertEqual(
|
|
jenkins_mock.call_args[0][0].get_full_url(),
|
|
self.make_url('quietDown'))
|
|
self._check_requests(jenkins_mock.call_args_list)
|