34cca0c4d9
Convert to the requests library to allow for more sophisticated response handling to be added. Want to allow for applications to override the response handling in certain cases where the default is incorrect. Handling of urlopen responses results in version specific handling to ensure correct behaviour across multiple versions of python. Changing to use the requests package, provides a higher level interface and removes some of the version specific handling for exceptions. Change-Id: I5369a0d35be4bf8b3b197a51e60aba21b5742cc7 Depends-On: Iabd70aa457ceb4dbc147d7cbaeec913148cb3b56
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from six.moves import StringIO
|
|
import testtools
|
|
from testtools.content import text_content
|
|
|
|
import jenkins
|
|
from tests.helper import NullServer
|
|
from tests.helper import TestsTimeoutException
|
|
from tests.helper import time_limit
|
|
|
|
|
|
class JenkinsRequestTimeoutTests(testtools.TestCase):
|
|
|
|
def setUp(self):
|
|
super(JenkinsRequestTimeoutTests, self).setUp()
|
|
self.server = NullServer(("127.0.0.1", 0))
|
|
self.messages = StringIO()
|
|
self.addOnException(self._get_messages)
|
|
|
|
def _get_messages(self, exc_info):
|
|
self.addDetail('timeout-tests-messages',
|
|
text_content(self.messages.getvalue()))
|
|
|
|
def test_jenkins_open_timeout(self):
|
|
j = jenkins.Jenkins("http://%s:%s" % self.server.server_address,
|
|
None, None, timeout=0.1)
|
|
request = jenkins.requests.Request('GET', 'http://%s:%s/job/TestJob' %
|
|
self.server.server_address)
|
|
|
|
# assert our request times out when no response
|
|
with testtools.ExpectedException(jenkins.TimeoutException):
|
|
j.jenkins_open(request, add_crumb=False)
|
|
|
|
def test_jenkins_open_no_timeout(self):
|
|
j = jenkins.Jenkins("http://%s:%s" % self.server.server_address,
|
|
None, None)
|
|
request = jenkins.requests.Request('GET', 'http://%s:%s/job/TestJob' %
|
|
self.server.server_address)
|
|
|
|
# assert we don't timeout quickly like previous test when
|
|
# no timeout defined.
|
|
with testtools.ExpectedException(TestsTimeoutException):
|
|
time_limit(0.5, self.messages,
|
|
j.jenkins_open, request, add_crumb=False)
|