Пример #1
0
    def test_get_builds(self):
        """Test get_builds API call"""

        # Set up a mock HTTP server
        body = read_file('data/jenkins_job_builds.json')
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_1,
                               body=body, status=200)

        client = JenkinsClient(JENKINS_SERVER_URL)
        response = client.get_builds(JENKINS_JOB_BUILDS_1)

        self.assertEqual(response, body)
Пример #2
0
    def test_get_builds_auth_api_token(self):
        """Test get_builds API call with username and API token"""

        # Set up a mock HTTP server
        body = read_file('data/jenkins/jenkins_job_builds.json')
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_1_DEPTH_1,
                               body=body, status=200)

        client = JenkinsClient(JENKINS_SERVER_URL, user=JENKINS_USER, api_token=JENKINS_TOKEN)
        response = client.get_builds(JENKINS_JOB_BUILDS_1)

        req = httpretty.last_request()
        self.assertEqual(response, body)

        authorization = [h for h in req.headers._headers if h[0] == 'Authorization'][0]
        self.assertEqual(req.method, 'GET')
        self.assertIn('Basic', authorization[1])
Пример #3
0
    def test_connection_error(self):
        """Test that HTTP connection error is correctly handled"""

        # Set up a mock HTTP server
        body = read_file('data/jenkins/jenkins_job_builds.json')
        httpretty.register_uri(httpretty.GET,
                               JENKINS_JOB_BUILDS_URL_1_DEPTH_1,
                               body=body, status=408)

        client = JenkinsClient(JENKINS_SERVER_URL, sleep_time=0.1)

        start = float(time.time())
        expected = start + (sum([i * client.sleep_time for i in range(client.MAX_RETRIES)]))

        with self.assertRaises(requests.exceptions.RequestException):
            _ = client.get_builds(JENKINS_JOB_BUILDS_1)

        end = float(time.time())
        self.assertGreater(end, expected)