def test_upload_unknown_error(caplog):
    """Tests whether unknown errors are handled as expected when uploading."""
    caplog.set_level(logging.DEBUG, 'snowflake.connector')
    mock_resource, mock_object = MagicMock(), MagicMock()
    mock_resource.Object.return_value = mock_object
    mock_object.bucket_name = 'bucket'
    mock_object.key = 'key'
    mock_object.upload_file.side_effect = botocore.exceptions.ClientError(
        {'Error': {'Code': 'unknown', 'Message': 'Just testing'}}, 'Testing')
    client_meta = {
        'cloud_client': mock_resource,
        'stage_info': {'location': 'loc'},
    }
    meta = {'name': 'f',
            'src_file_name': 'f',
            'stage_location_type': 'S3',
            'client_meta': SFResourceMeta(**client_meta),
            'sha256_digest': 'asd',
            'dst_file_name': 'f',
            'put_callback': None}
    meta = SnowflakeFileMeta(**meta)
    with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util.extract_bucket_name_and_path'):
        with pytest.raises(botocore.exceptions.ClientError,
                           match=r'An error occurred \(unknown\) when calling the Testing operation: Just testing'):
            SnowflakeS3Util.upload_file('f', meta, {}, 4, 67108864)
Пример #2
0
def test_upload_failed_error(caplog):
    """Tests whether token expiry error is handled as expected when uploading."""
    caplog.set_level(logging.DEBUG, "snowflake.connector")
    mock_resource, mock_object = MagicMock(), MagicMock()
    mock_resource.Object.return_value = mock_object
    mock_object.upload_file.side_effect = S3UploadFailedError("ExpiredToken")
    client_meta = {
        "cloud_client": mock_resource,
        "stage_info": {
            "location": "loc"
        },
    }
    meta = {
        "name": "f",
        "src_file_name": "f",
        "stage_location_type": "S3",
        "client_meta": SFResourceMeta(**client_meta),
        "sha256_digest": "asd",
        "dst_file_name": "f",
        "put_callback": None,
    }
    meta = SnowflakeFileMeta(**meta)
    with mock.patch(
            "snowflake.connector.s3_util.SnowflakeS3Util.extract_bucket_name_and_path"
    ):
        assert SnowflakeS3Util.upload_file("f", meta, {}, 4, 67108864) is None
    assert (
        "snowflake.connector.s3_util",
        logging.DEBUG,
        "Failed to upload a file: f, err: ExpiredToken. Renewing AWS Token and Retrying",
    ) in caplog.record_tuples
    assert meta.result_status == ResultStatus.RENEW_TOKEN
Пример #3
0
def test_upload_expiry_error(caplog):
    """Tests whether token expiry error is handled as expected when uploading."""
    caplog.set_level(logging.DEBUG, 'snowflake.connector')
    mock_resource, mock_object = MagicMock(), MagicMock()
    mock_resource.Object.return_value = mock_object
    mock_object.upload_file.side_effect = botocore.exceptions.ClientError(
        {'Error': {
            'Code': 'ExpiredToken',
            'Message': 'Just testing'
        }}, 'Testing')
    meta = {
        'client': mock_resource,
        'sha256_digest': 'asd',
        'stage_info': {
            'location': 'loc'
        },
        'dst_file_name': 'f',
        'put_callback': None
    }
    with mock.patch(
            'snowflake.connector.s3_util.SnowflakeS3Util.extract_bucket_name_and_path'
    ):
        assert SnowflakeS3Util.upload_file('f', meta, {}, 4) is None
    assert ('snowflake.connector.s3_util', logging.DEBUG,
            'AWS Token expired. Renew and retry') in caplog.record_tuples
    assert meta['result_status'] == ResultStatus.RENEW_TOKEN
Пример #4
0
def test_upload_unknown_error(caplog):
    """Tests whether unknown errors are handled as expected when uploading."""
    caplog.set_level(logging.DEBUG, "snowflake.connector")
    mock_resource, mock_object = MagicMock(), MagicMock()
    mock_resource.Object.return_value = mock_object
    mock_object.bucket_name = "bucket"
    mock_object.key = "key"
    mock_object.upload_file.side_effect = botocore.exceptions.ClientError(
        {"Error": {
            "Code": "unknown",
            "Message": "Just testing"
        }}, "Testing")
    client_meta = {
        "cloud_client": mock_resource,
        "stage_info": {
            "location": "loc"
        },
    }
    meta = {
        "name": "f",
        "src_file_name": "f",
        "stage_location_type": "S3",
        "client_meta": SFResourceMeta(**client_meta),
        "sha256_digest": "asd",
        "dst_file_name": "f",
        "put_callback": None,
    }
    meta = SnowflakeFileMeta(**meta)
    with mock.patch(
            "snowflake.connector.s3_util.SnowflakeS3Util.extract_bucket_name_and_path"
    ):
        with pytest.raises(
                botocore.exceptions.ClientError,
                match=
                r"An error occurred \(unknown\) when calling the Testing operation: Just testing",
        ):
            SnowflakeS3Util.upload_file("f", meta, {}, 4, 67108864)
def test_upload_failed_error(caplog):
    """Tests whether token expiry error is handled as expected when uploading."""
    mock_resource, mock_object = MagicMock(), MagicMock()
    mock_resource.Object.return_value = mock_object
    mock_object.upload_file.side_effect = S3UploadFailedError('ExpiredToken')
    meta = {'client': mock_resource,
            'sha256_digest': 'asd',
            'stage_info': {'location': 'loc'},
            'dst_file_name': 'f',
            'put_callback': None}
    with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util.extract_bucket_name_and_path'):
        assert SnowflakeS3Util.upload_file('f', meta, {}, 4) is None
    assert ('snowflake.connector.s3_util',
            logging.DEBUG,
            'Failed to upload a file: f, err: ExpiredToken. Renewing AWS Token and Retrying') in caplog.record_tuples
    assert meta['result_status'] == ResultStatus.RENEW_TOKEN