From ea6ebbc0a1f972bea5ef904c9e8f66f6f5e89c46 Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Tue, 2 Aug 2022 16:19:32 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=82=B3=E3=83=B3=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=82=B0=E3=83=90=E3=82=B1=E3=83=83=E3=83=88=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=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 | 29 ++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ecs/crm-datafetch/tests/aws/test_s3.py b/ecs/crm-datafetch/tests/aws/test_s3.py index db4f1c09..db97825a 100644 --- a/ecs/crm-datafetch/tests/aws/test_s3.py +++ b/ecs/crm-datafetch/tests/aws/test_s3.py @@ -1,7 +1,5 @@ import pytest from src.aws.s3 import ConfigBucket, S3Resource -from src.system_var import environments -from src.system_var.constants import OBJECT_INFO_FILENAME, OBJECT_INFO_FOLDER @pytest.fixture @@ -27,7 +25,7 @@ class TestS3Resource: s3_resource = S3Resource(bucket_name) 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' + assert actual['Body'].read().decode('utf-8') == 'aaaaaaaaaaaaaaa' def test_copy(self, s3_test, s3_client, bucket_name): for_copy_bucket = 'for-copy-bucket' @@ -47,7 +45,6 @@ class TestS3Resource: class TestConfigBucket: def test_get_object_info_file(self, s3_test, s3_client, bucket_name, monkeypatch): - # = bucket_name monkeypatch.setattr('src.aws.s3.CRM_CONFIG_BUCKET', bucket_name) monkeypatch.setattr('src.aws.s3.OBJECT_INFO_FOLDER', 'crm') monkeypatch.setattr('src.aws.s3.OBJECT_INFO_FILENAME', 'objects.json') @@ -57,3 +54,27 @@ class TestConfigBucket: actual = config_bucket.get_object_info_file() print(actual) assert actual == 'aaaaaaaaaaaaaaa' + + def test_get_last_fetch_datetime_file(self, s3_test, s3_client, bucket_name, monkeypatch): + monkeypatch.setattr('src.aws.s3.CRM_CONFIG_BUCKET', bucket_name) + monkeypatch.setattr('src.aws.s3.LAST_FETCH_DATE_FOLDER', 'crm') + s3_client.put_object(Bucket=bucket_name, Key=f'crm/Object.json', Body=b'aaaaaaaaaaaaaaa') + config_bucket = ConfigBucket() + print('*' * 50, str(config_bucket), '*' * 50) + actual = config_bucket.get_last_fetch_datetime_file('Object.json') + print(actual) + assert actual == 'aaaaaaaaaaaaaaa' + + def test_put_last_fetch_datetime_file(self, s3_test, s3_client, bucket_name, monkeypatch): + monkeypatch.setattr('src.aws.s3.CRM_CONFIG_BUCKET', bucket_name) + monkeypatch.setattr('src.aws.s3.LAST_FETCH_DATE_FOLDER', 'crm') + config_bucket = ConfigBucket() + print('*' * 50, str(config_bucket), '*' * 50) + config_bucket.put_last_fetch_datetime_file('Object.json', 'aaaaaaaaaaaaaaa') + actual = s3_client.get_object(Bucket=bucket_name, Key=f'crm/Object.json') + assert actual['Body'].read().decode('utf-8') == 'aaaaaaaaaaaaaaa' + + def test_config_bucket_str(self, s3_test, s3_client, bucket_name, monkeypatch): + monkeypatch.setattr('src.aws.s3.CRM_CONFIG_BUCKET', bucket_name) + config_bucket = ConfigBucket() + assert str(config_bucket) == bucket_name