Skip to content

Commit

Permalink
Merge pull request #248 from bryanyang0528/add_test_raise_s3_exception
Browse files Browse the repository at this point in the history
Add test raise s3 exception
  • Loading branch information
igorborgest authored May 20, 2020
2 parents c9ec52c + 3f14923 commit 9c18f95
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions testing/test_awswrangler/test_moto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import boto3
import mock
from botocore.exceptions import ClientError
import botocore
import moto
import pytest

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9c18f95

Please sign in to comment.