def test_native_download_access_token(caplog):
    """Tests that GCS access token error is correctly logged when downloading."""
    meta = {}
    SnowflakeGCSUtil._native_download_file(meta, None, 99)
    assert meta['result_status'] == ResultStatus.ERROR
    assert (('snowflake.connector.gcs_util', logging.ERROR, "GCS download operation with an access token is "
                                                            "currently unsupported") in caplog.record_tuples)
def test_download_uncaught_exception(tmpdir):
    """Tests whether non-retryable errors are handled correctly when downloading."""
    resp = Response()
    resp.status_code = 501
    meta = {'presigned_url': ['some_url'], 'sha256_digest': 'asd'}
    with mock.patch('requests.get', side_effect=requests.exceptions.HTTPError(response=resp)):
        with pytest.raises(requests.exceptions.HTTPError):
            SnowflakeGCSUtil._native_download_file(meta, str(tmpdir), 99)
def test_download_retry_errors(errno, tmpdir):
    """Tests whether retryable errors are handled correctly when downloading."""
    resp = Response()
    resp.status_code = errno
    meta = {'presigned_url': ['some_url'], 'sha256_digest': 'asd'}
    with mock.patch('requests.get', side_effect=requests.exceptions.HTTPError(response=resp)):
        SnowflakeGCSUtil._native_download_file(meta, str(tmpdir), 99)
        assert isinstance(meta['last_error'], requests.exceptions.HTTPError)
        assert meta['result_status'] == ResultStatus.NEED_RETRY
def test_upload_get_timeout(tmpdir, caplog):
    """Tests whether timeout error is handled correctly when downloading."""
    resp = Response()
    meta = {'presigned_url': ['some_url'], 'sha256_digest': 'asd'}
    with mock.patch('requests.get', side_effect=requests.exceptions.Timeout(response=resp)):
        SnowflakeGCSUtil._native_download_file(meta, str(tmpdir), 99)
    assert isinstance(meta['last_error'], requests.exceptions.Timeout)
    assert meta['result_status'] == ResultStatus.NEED_RETRY
    assert ('snowflake.connector.gcs_util', logging.DEBUG, 'GCS file download Timeout Error: ') in caplog.record_tuples
Ejemplo n.º 5
0
def test_download_uncaught_exception(tmp_path):
    """Tests whether non-retryable errors are handled correctly when downloading."""
    resp = requests.Response()
    resp.status_code = 501
    meta = SnowflakeFileMeta(
        name=str(tmp_path / 'some_file'),
        src_file_name=str(tmp_path / 'some_file'),
        stage_location_type='GCS',
        presigned_url='some_url',
        sha256_digest='asd',
    )
    with mock.patch('snowflake.connector.vendored.requests.get'
                    if vendored_request else 'requests.get',
                    side_effect=requests.exceptions.HTTPError(response=resp)):
        with pytest.raises(requests.exceptions.HTTPError):
            SnowflakeGCSUtil._native_download_file(meta, str(tmp_path), 99)
Ejemplo n.º 6
0
def test_download_retry_errors(errno, tmp_path):
    """Tests whether retryable errors are handled correctly when downloading."""
    resp = requests.Response()
    resp.status_code = errno
    meta = SnowflakeFileMeta(
        name=str(tmp_path / 'some_file'),
        src_file_name=str(tmp_path / 'some_file'),
        stage_location_type='GCS',
        presigned_url='some_url',
        sha256_digest='asd',
    )
    with mock.patch('snowflake.connector.vendored.requests.get'
                    if vendored_request else 'requests.get',
                    side_effect=requests.exceptions.HTTPError(response=resp)):
        SnowflakeGCSUtil._native_download_file(meta, str(tmp_path), 99)
        assert isinstance(meta.last_error, requests.exceptions.HTTPError)
        assert meta.result_status == ResultStatus.NEED_RETRY
Ejemplo n.º 7
0
def test_upload_get_timeout(tmp_path, caplog):
    """Tests whether timeout error is handled correctly when downloading."""
    caplog.set_level(logging.DEBUG, 'snowflake.connector')
    resp = requests.Response()
    meta = SnowflakeFileMeta(
        name=str(tmp_path / 'some_file'),
        src_file_name=str(tmp_path / 'some_file'),
        stage_location_type='GCS',
        presigned_url='some_url',
        sha256_digest='asd',
    )
    with mock.patch('snowflake.connector.vendored.requests.get'
                    if vendored_request else 'requests.get',
                    side_effect=requests.exceptions.Timeout(response=resp)):
        SnowflakeGCSUtil._native_download_file(meta, str(tmp_path), 99)
    assert isinstance(meta.last_error, requests.exceptions.Timeout)
    assert meta.result_status == ResultStatus.NEED_RETRY
    assert ('snowflake.connector.gcs_util', logging.DEBUG,
            'GCS file download Timeout Error: ') in caplog.record_tuples