def test_download_syscall_error(caplog, error_no, result_status): """Tests whether a syscall error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, "snowflake.connector") mock_resource = MagicMock() mock_resource.download_file.side_effect = OpenSSL.SSL.SysCallError( error_no) client_meta = { "cloud_client": mock_resource, "stage_info": { "location": "loc" }, } meta = { "name": "f", "stage_location_type": "S3", "client_meta": SFResourceMeta(**client_meta), "sha256_digest": "asd", "src_file_name": "f", "src_file_size": 99, "get_callback_output_stream": None, "show_progress_bar": False, "get_callback": None, } meta = SnowflakeFileMeta(**meta) with mock.patch( "snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object", return_value=mock_resource, ): SnowflakeS3Util._native_download_file(meta, "f", 4) assert meta.last_error is mock_resource.download_file.side_effect assert meta.result_status == result_status
def test_download_expiry_error(caplog): """Tests whether token expiry error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, "snowflake.connector") mock_resource = MagicMock() mock_resource.download_file.side_effect = botocore.exceptions.ClientError( {"Error": { "Code": "ExpiredToken", "Message": "Just testing" }}, "Testing") client_meta = { "cloud_client": mock_resource, "stage_info": { "location": "loc" }, } meta_dict = { "name": "f", "src_file_name": "f", "stage_location_type": "S3", "sha256_digest": "asd", "client_meta": SFResourceMeta(**client_meta), "src_file_size": 99, "get_callback_output_stream": None, "show_progress_bar": False, "get_callback": None, } meta = SnowflakeFileMeta(**meta_dict) with mock.patch( "snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object", return_value=mock_resource, ): SnowflakeS3Util._native_download_file(meta, "f", 4) assert meta.result_status == ResultStatus.RENEW_TOKEN
def test_download_unknown_error(caplog): """Tests whether an unknown error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, 'snowflake.connector') mock_resource = MagicMock() mock_resource.download_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', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None} meta = SnowflakeFileMeta(**meta) with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): with pytest.raises(botocore.exceptions.ClientError, match=r'An error occurred \(unknown\) when calling the Testing operation: Just testing'): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert ('snowflake.connector.s3_util', logging.DEBUG, 'Failed to download a file: f, err: An error occurred (unknown) when ' 'calling the Testing operation: Just testing') in caplog.record_tuples
def test_download_expiry_error(caplog): """Tests whether token expiry error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, 'snowflake.connector') mock_resource = MagicMock() mock_resource.download_file.side_effect = botocore.exceptions.ClientError( {'Error': { 'Code': 'ExpiredToken', 'Message': 'Just testing' }}, 'Testing') meta = { 'client': mock_resource, 'sha256_digest': 'asd', 'stage_info': { 'location': 'loc' }, 'src_file_name': 'f', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None } with mock.patch( 'snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert meta['result_status'] == ResultStatus.RENEW_TOKEN
def test_download_syscall_error(caplog, error_no, result_status): """Tests whether a syscall error is handled as expected when downloading.""" mock_resource = MagicMock() mock_resource.download_file.side_effect = OpenSSL.SSL.SysCallError(error_no) meta = {'client': mock_resource, 'sha256_digest': 'asd', 'stage_info': {'location': 'loc'}, 'src_file_name': 'f', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None} with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert meta['last_error'] is mock_resource.download_file.side_effect assert meta['result_status'] == result_status
def test_download_retry_exceeded_error(caplog): """Tests whether a retry exceeded error is handled as expected when downloading.""" mock_resource = MagicMock() mock_resource.download_file.side_effect = RetriesExceededError(Boto3Error()) meta = {'client': mock_resource, 'sha256_digest': 'asd', 'stage_info': {'location': 'loc'}, 'src_file_name': 'f', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None} with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert meta['last_error'] is mock_resource.download_file.side_effect assert meta['result_status'] == ResultStatus.NEED_RETRY
def test_download_unknown_error(caplog): """Tests whether an unknown error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, "snowflake.connector") mock_resource = MagicMock() mock_resource.download_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", "src_file_size": 99, "get_callback_output_stream": None, "show_progress_bar": False, "get_callback": None, } meta = SnowflakeFileMeta(**meta) with mock.patch( "snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object", return_value=mock_resource, ): with pytest.raises( botocore.exceptions.ClientError, match= r"An error occurred \(unknown\) when calling the Testing operation: Just testing", ): SnowflakeS3Util._native_download_file(meta, "f", 4) assert ( "snowflake.connector.s3_util", logging.DEBUG, "Failed to download a file: f, err: An error occurred (unknown) when " "calling the Testing operation: Just testing", ) in caplog.record_tuples
def test_download_syscall_error(caplog, error_no, result_status): """Tests whether a syscall error is handled as expected when downloading.""" caplog.set_level(logging.DEBUG, 'snowflake.connector') mock_resource = MagicMock() mock_resource.download_file.side_effect = OpenSSL.SSL.SysCallError(error_no) client_meta = { 'cloud_client': mock_resource, 'stage_info': {'location': 'loc'}, } meta = {'name': 'f', 'stage_location_type': 'S3', 'client_meta': SFResourceMeta(**client_meta), 'sha256_digest': 'asd', 'src_file_name': 'f', 'src_file_size': 99, 'get_callback_output_stream': None, 'show_progress_bar': False, 'get_callback': None} meta = SnowflakeFileMeta(**meta) with mock.patch('snowflake.connector.s3_util.SnowflakeS3Util._get_s3_object', return_value=mock_resource): SnowflakeS3Util._native_download_file(meta, 'f', 4) assert meta.last_error is mock_resource.download_file.side_effect assert meta.result_status == result_status