File: test_jenkins_sockets.py

package info (click to toggle)
python-jenkins 1.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 556 kB
  • sloc: python: 6,099; makefile: 150
file content (43 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)