a2c6f6a8ff
Other specific requests may need a body. Thus remove the general check for an empty body and add a more specific one where needed. I noticed this because when updating a Jenkins job with Jenkins Job Builder I got an EmptyResponseException even though updating worked correctly. Change-Id: Ie144e6fb0b922a681e6c65ffbe5120da72a495f0
46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
from mock import patch
|
|
|
|
import jenkins
|
|
from tests.base import JenkinsTestBase
|
|
from tests.helper import build_response_mock
|
|
|
|
|
|
class JenkinsVersionTest(JenkinsTestBase):
|
|
|
|
@patch('jenkins.requests.Session.send', autospec=True)
|
|
def test_some_version(self, session_send_mock):
|
|
session_send_mock.return_value = build_response_mock(
|
|
200, headers={'X-Jenkins': 'Version42', 'Content-Length': 0})
|
|
self.assertEqual(self.j.get_version(), 'Version42')
|
|
|
|
@patch('jenkins.requests.Session.send', autospec=True)
|
|
def test_raise_HTTPError(self, session_send_mock):
|
|
session_send_mock.side_effect = iter([
|
|
build_response_mock(404, reason="Not Found"), # crumb
|
|
build_response_mock(499, reason="Unhandled Error"), # request
|
|
])
|
|
|
|
with self.assertRaises(jenkins.BadHTTPException) as context_manager:
|
|
self.j.get_version()
|
|
self.assertEqual(
|
|
str(context_manager.exception),
|
|
'Error communicating with server[{0}/]'.format(self.base_url))
|
|
|
|
@patch('jenkins.requests.Session.send', autospec=True)
|
|
def test_raise_BadStatusLine(self, session_send_mock):
|
|
session_send_mock.side_effect = jenkins.BadStatusLine('not a valid status line')
|
|
with self.assertRaises(jenkins.BadHTTPException) as context_manager:
|
|
self.j.get_version()
|
|
self.assertEqual(
|
|
str(context_manager.exception),
|
|
'Error communicating with server[{0}/]'.format(self.base_url))
|
|
|
|
@patch('jenkins.requests.Session.send', autospec=True)
|
|
def test_return_without_version_header(self, session_send_mock):
|
|
session_send_mock.return_value = build_response_mock(0)
|
|
with self.assertRaises(KeyError) as context_manager:
|
|
self.j.get_version()
|
|
self.assertEqual(
|
|
str(context_manager.exception),
|
|
"'x-jenkins'")
|