From deb44cd1e2e4cf968294eb9c421274a59c0941ba Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Mon, 1 Aug 2022 20:02:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20S3=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/crm-datafetch/tests/aws/test_s3.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ecs/crm-datafetch/tests/aws/test_s3.py b/ecs/crm-datafetch/tests/aws/test_s3.py index 61c3d352..f341cd2c 100644 --- a/ecs/crm-datafetch/tests/aws/test_s3.py +++ b/ecs/crm-datafetch/tests/aws/test_s3.py @@ -15,6 +15,28 @@ def s3_test(s3_client, bucket_name): class TestS3Resource: + def test_get_object(self, s3_test, s3_client, bucket_name): + s3_client.put_object(Bucket=bucket_name, Key='hogehoge/test.txt', Body=b'aaaaaaaaaaaaaaa') + s3_resource = S3Resource(bucket_name) + actual = s3_resource.get_object('hogehoge/test.txt') + assert actual == 'aaaaaaaaaaaaaaa' + def test_put_object(self, s3_test, s3_client, bucket_name): s3_resource = S3Resource(bucket_name) - s3_resource.put_object('hogehoge', 'aaaaaaaaaaaaaaa') + s3_resource.put_object('hogehoge/test.txt', 'aaaaaaaaaaaaaaa') + actual = s3_client.get_object(Bucket=bucket_name, Key='hogehoge/test.txt') + assert actual['Body'].read() == b'aaaaaaaaaaaaaaa' + + def test_copy(self, s3_test, s3_client, bucket_name): + for_copy_bucket = 'for-copy-bucket' + s3_client.create_bucket(Bucket=for_copy_bucket) + s3_client.put_object(Bucket=bucket_name, Key='hogehoge/test.txt', Body=b'aaaaaaaaaaaaaaa') + s3_resource = S3Resource(bucket_name) + s3_resource.copy(bucket_name, 'hogehoge/test.txt', for_copy_bucket, 'test.txt') + actual = s3_client.get_object(Bucket=for_copy_bucket, Key='test.txt') + assert actual['Body'].read() == b'aaaaaaaaaaaaaaa' + + def test_init_raise_no_provide_bucket_name(self): + with pytest.raises(Exception) as e: + S3Resource() + assert e.value.args[0] == "__init__() missing 1 required positional argument: 'bucket_name'"