Exemple #1
0
    def test_connection_failure(self):
        build_id = '1234'
        artifact_id = '12345'
        session = get_retrying_requests_session()

        (flexmock(session)
         .should_receive('get')
         .and_raise(requests.exceptions.RetryError))

        pnc_util = PNCUtil(mock_pnc_map(), session)

        with pytest.raises(requests.exceptions.RetryError):
            pnc_util.get_scm_archive_from_build_id(build_id)

        with pytest.raises(requests.exceptions.RetryError):
            pnc_util.get_artifact(artifact_id)
Exemple #2
0
    def test_get_artifact(self):
        artifact_id = '12345'
        public_url = 'https://code.example.com/artifact.jar'
        artifact_response = {
            'id': artifact_id,
            'publicUrl': public_url,
            'md5': 'abcd',
            'sha1': 'abcd',
            'sha256': 'abcd',
        }
        pnc_util = PNCUtil(mock_pnc_map())

        # to mock this URL we have to construct it manually first
        get_artifact_request_url = PNC_BASE_API_URL + '/' + PNC_GET_ARTIFACT_PATH

        responses.add(responses.GET, get_artifact_request_url.format(artifact_id),
                      body=json.dumps(artifact_response), status=200)
        responses.add(responses.HEAD, public_url, body='abc', status=200)

        url, checksums = pnc_util.get_artifact(artifact_id)

        assert public_url == url
        assert checksums == {'md5': 'abcd', 'sha1': 'abcd', 'sha256': 'abcd'}