From 3f14923204ca3422985050a9bde8a4e6bd185046 Mon Sep 17 00:00:00 2001 From: Bryan Date: Wed, 20 May 2020 17:51:45 +0800 Subject: [PATCH] add test cases for s3 delete objects --- testing/test_awswrangler/test_moto.py | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/testing/test_awswrangler/test_moto.py b/testing/test_awswrangler/test_moto.py index 2adc7aec8..4c8c0f8b9 100644 --- a/testing/test_awswrangler/test_moto.py +++ b/testing/test_awswrangler/test_moto.py @@ -1,4 +1,7 @@ import boto3 +import mock +from botocore.exceptions import ClientError +import botocore import moto import pytest @@ -52,6 +55,36 @@ def test_parquet(s3): assert len(df.columns) == 18 +def test_s3_delete_object_success(s3): + path = "s3://bucket/test.parquet" + wr.s3.to_parquet(df=get_df_list(), path=path, index=False, dataset=True, partition_cols=["par0", "par1"]) + df = wr.s3.read_parquet(path=path, dataset=True) + ensure_data_types(df, has_list=True) + + wr.s3.delete_objects(path=path) + with pytest.raises(OSError): + wr.s3.read_parquet(path=path, dataset=True) + + +def test_s3_raise_delete_object_exception_success(s3): + path = "s3://bucket/test.parquet" + wr.s3.to_parquet(df=get_df_list(), path=path, index=False, dataset=True, partition_cols=["par0", "par1"]) + df = wr.s3.read_parquet(path=path, dataset=True) + ensure_data_types(df, has_list=True) + + call = botocore.client.BaseClient._make_api_call + + def mock_make_api_call(self, operation_name, kwarg): + if operation_name == 'DeleteObjects': + parsed_response = {'Error': {'Code': '500', 'Message': 'Test Error'}} + raise ClientError(parsed_response, operation_name) + return call(self, operation_name, kwarg) + + with mock.patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call): + with pytest.raises(ClientError): + wr.s3.delete_objects(path=path) + + def test_emr(s3, emr, sts, subnet): session = boto3.Session(region_name="us-west-1") cluster_id = wr.emr.create_cluster(