コード例 #1
0
ファイル: test_pnc.py プロジェクト: hjmodi/atomic-reactor
    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 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