示例#1
0
    def test_connection_failure(self):
        build_id = '1234'
        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)
示例#2
0
    def test_get_scm_archive_filename_in_url(self):
        build_id = '1234'
        filename = 'source.tar.gz'
        scm_url = f'https://code.example.com/{filename}'
        # to mock this URL we have to construct it manually first
        get_scm_archive_request_url = PNC_BASE_API_URL + '/' + PNC_GET_SCM_ARCHIVE_PATH

        responses.add(responses.GET, get_scm_archive_request_url.format(build_id), body='',
                      status=302, headers={'Location': scm_url})

        pnc_util = PNCUtil(mock_pnc_map())

        url, dest_filename = pnc_util.get_scm_archive_from_build_id(build_id)

        assert url == scm_url
        assert dest_filename == filename
示例#3
0
 def pnc_util(self):
     if not self._pnc_util:
         pnc_map = self.workflow.conf.pnc
         if not pnc_map:
             raise RuntimeError(
                 'No PNC configuration found in reactor config map')
         self._pnc_util = PNCUtil(pnc_map)
     return self._pnc_util
示例#4
0
 def pnc_util(self):
     if not self._pnc_util:
         try:
             pnc_map = get_pnc(self.workflow)
         except KeyError:
             raise RuntimeError('No PNC configuration found in reactor config map') from KeyError
         self._pnc_util = PNCUtil(pnc_map)
     return self._pnc_util
示例#5
0
    def test_get_scm_archive_filename_in_header(self):
        build_id = '1234'
        filename = 'source.tar.gz'
        scm_url = f'https://code.example.com/{filename};sf=tgz'
        content = b'abc'
        reader = BufferedReader(BytesIO(content), buffer_size=1)
        # to mock this URL we have to construct it manually first
        get_scm_archive_request_url = PNC_BASE_API_URL + '/' + PNC_GET_SCM_ARCHIVE_PATH

        responses.add(responses.GET, get_scm_archive_request_url.format(build_id), body=reader,
                      status=302, headers={'Location': scm_url})
        responses.add(responses.HEAD, scm_url, body='', status=200,
                      headers={'Content-disposition': f'filename="{filename}"'})

        pnc_util = PNCUtil(mock_pnc_map())

        url, dest_filename = pnc_util.get_scm_archive_from_build_id(build_id)

        assert url == scm_url
        assert dest_filename == filename
示例#6
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'}
示例#7
0
    def test_get_artifact_purl_specs(self):
        artifact_id = '12345'
        public_url = 'https://code.example.com/artifact.jar'
        purl_spec = 'pkg:maven/org.example.artifact/[email protected]?type=jar'
        artifact_response = {
            'id': artifact_id,
            'publicUrl': public_url,
            'md5': 'abcd',
            'sha1': 'abcd',
            'sha256': 'abcd',
            'purl': purl_spec
        }
        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)

        pnc_artifact_purl_specs = pnc_util.get_artifact_purl_specs([artifact_id])

        assert pnc_artifact_purl_specs == [purl_spec]