From 4d179f6be5aef52e113b24c963670643d13bdc55 Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Mon, 22 Aug 2022 11:35:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=87=E6=95=B0=E8=A1=A8=E8=A8=98?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=8F=9B=E3=82=92=E8=A1=8C=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=93=E3=81=A8=E3=81=AB=E3=82=88=E3=82=8A?= =?UTF-8?q?=E3=80=81=E4=BB=96=E3=81=AE=E5=B0=91=E6=95=B0=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E3=81=8C=E6=95=B4=E6=95=B0=E3=81=AB=E3=81=AA=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/converter/convert_strategy.py | 10 ----- .../tests/converter/test_convert_strategy.py | 44 +++++++++---------- .../tests/converter/test_converter.py | 10 ++--- .../test_convert_crm_csv_data_process.py | 10 ++--- 4 files changed, 31 insertions(+), 43 deletions(-) diff --git a/ecs/crm-datafetch/src/converter/convert_strategy.py b/ecs/crm-datafetch/src/converter/convert_strategy.py index 22fca8fc..ab1e0626 100644 --- a/ecs/crm-datafetch/src/converter/convert_strategy.py +++ b/ecs/crm-datafetch/src/converter/convert_strategy.py @@ -12,7 +12,6 @@ from src.system_var.environments import CONVERT_TZ class ConvertStrategyFactory: def __init__(self) -> None: self.__none_value_convert_strategy = NoneValueConvertStrategy() - self.__float_convert_strategy = FloatConvertStrategy() self.__boolean_convert_strategy = BooleanConvertStrategy() self.__datetime_convert_strategy = DatetimeConvertStrategy() self.__int_convert_strategy = IntConvertStrategy() @@ -23,9 +22,6 @@ class ConvertStrategyFactory: if value is None: convert_strategy = self.__none_value_convert_strategy - elif type(value) == float: - convert_strategy = self.__float_convert_strategy - elif type(value) == bool: convert_strategy = self.__boolean_convert_strategy @@ -60,12 +56,6 @@ class DatetimeConvertStrategy: return datetime.strptime(convert_value, CRM_DATETIME_FORMAT).astimezone(gettz(CONVERT_TZ)).strftime(YYYYMMDDHHMMSS) -class FloatConvertStrategy: - def convert_value(self, convert_value: str) -> int: - """float型をint型に変換する処理""" - return int(convert_value) - - class IntConvertStrategy: def convert_value(self, convert_value: int): """int型を変換せずに返す処理""" diff --git a/ecs/crm-datafetch/tests/converter/test_convert_strategy.py b/ecs/crm-datafetch/tests/converter/test_convert_strategy.py index 0e268fc4..4b4552a8 100644 --- a/ecs/crm-datafetch/tests/converter/test_convert_strategy.py +++ b/ecs/crm-datafetch/tests/converter/test_convert_strategy.py @@ -1,7 +1,6 @@ from src.converter.convert_strategy import (BooleanConvertStrategy, ConvertStrategyFactory, DatetimeConvertStrategy, - FloatConvertStrategy, IntConvertStrategy, NoneValueConvertStrategy, StringConvertStrategy) @@ -29,7 +28,7 @@ class TestConvertStrategyFactory: def test_create_float(self): """ Cases: - 引数に指数表記を指定した場合、FloatConvertStrategyインスタンスが返ってくること + 引数に指数表記を指定した場合、StringConvertStrategyインスタンスが返ってくること Arranges: - なし Expects: @@ -41,7 +40,26 @@ class TestConvertStrategyFactory: actual = sut.create(1.2345678E7) # Expects - assert type(actual) == FloatConvertStrategy + # 変換しない + assert type(actual) == StringConvertStrategy + + def test_create_float_scale(self): + """ + Cases: + 引数に少数を指定した場合、StringConvertStrategyインスタンスが返ってくること + Arranges: + - なし + Expects: + - 戻り値が、期待値と一致する + """ + + # Act + sut = ConvertStrategyFactory() + actual = sut.create(1.2345678E7) + + # Expects + # 変換しない + assert type(actual) == StringConvertStrategy def test_create_bool_true(self): """ @@ -206,26 +224,6 @@ class TestDatetimeConvertStrategy: assert actual == "2022-06-14 05:15:32" -class TestFloatConvertStrategy: - - def test_convert_value(self) -> int: - """ - Cases: - 引数に指数表記を指定した場合、整数で返ってくること - Arranges: - - なし - Expects: - - 戻り値が、期待値と一致する - """ - - # Act - sut = FloatConvertStrategy() - actual = sut.convert_value(1.2345678E7) - - # Expects - assert actual == 12345678 - - class TestIntConvertStrategy: def test_convert_value(self): diff --git a/ecs/crm-datafetch/tests/converter/test_converter.py b/ecs/crm-datafetch/tests/converter/test_converter.py index 0300381d..da80982b 100644 --- a/ecs/crm-datafetch/tests/converter/test_converter.py +++ b/ecs/crm-datafetch/tests/converter/test_converter.py @@ -71,7 +71,7 @@ class TestCSVStringConverter: ('ContactAccessLevel', 8), ('RowCause', 'テストのため2'), ('LastModifiedDate', '2022-06-02T16:30:30.000+0000'), - ('LastModifiedById', 2.234567E+6), + ('LastModifiedById', 2.23E+0), ('IsDeleted', True) ]), OrderedDict([ @@ -85,7 +85,7 @@ class TestCSVStringConverter: ('ContactAccessLevel', 12), ('RowCause', 'テストのため3'), ('LastModifiedDate', '2022-06-03T23:50:50.000+0000'), - ('LastModifiedById', 3.234567E+6), + ('LastModifiedById', 3.234567), ('IsDeleted', False) ]) ] @@ -100,9 +100,9 @@ class TestCSVStringConverter: # Expects expected_value = '''\ "Id","AccountId","UserOrGroupId","AccountAccessLevel","OpportunityAccessLevel","CaseAccessLevel","ContactAccessLevel","RowCause","LastModifiedDate","LastModifiedById","IsDeleted"\r\n\ - "TEST001","test001","","1","2","3","4","テストのため1","2022-06-01 09:00:00","1234567","0"\r\n\ - "TEST002","test002","","5","6","7","8","テストのため2","2022-06-03 01:30:30","2234567","1"\r\n\ - "TEST003","test003","","9","10","11","12","テストのため3","2022-06-04 08:50:50","3234567","0"\r\n\ + "TEST001","test001","","1","2","3","4","テストのため1","2022-06-01 09:00:00","1234567.0","0"\r\n\ + "TEST002","test002","","5","6","7","8","テストのため2","2022-06-03 01:30:30","2.23","1"\r\n\ + "TEST003","test003","","9","10","11","12","テストのため3","2022-06-04 08:50:50","3.234567","0"\r\n\ ''' # expected_valueのインデントが半角スペースと認識されてしまうため、`textwrap.dedent`にて補正 diff --git a/ecs/crm-datafetch/tests/test_convert_crm_csv_data_process.py b/ecs/crm-datafetch/tests/test_convert_crm_csv_data_process.py index 49d960c0..6d1b63f1 100644 --- a/ecs/crm-datafetch/tests/test_convert_crm_csv_data_process.py +++ b/ecs/crm-datafetch/tests/test_convert_crm_csv_data_process.py @@ -42,7 +42,7 @@ class TestConvertCrmCsvDataProcess: ('Id', 'TEST002'), ('AccountNumber', 'test002'), ('LastModifiedDate', '2022-06-01T00:00:00.000+0000'), - ('LastModifiedById', 1.234567E+6), + ('LastModifiedById', 1.23E+0), ('SystemModstamp', '2022-06-01T00:00:00.000+0000'), ('IsDeleted', False) ]), @@ -52,7 +52,7 @@ class TestConvertCrmCsvDataProcess: ('Id', 'TEST003'), ('AccountNumber', 'test003'), ('LastModifiedDate', '2022-06-01T00:00:00.000+0000'), - ('LastModifiedById', 1.234567E+6), + ('LastModifiedById', 1.234567), ('SystemModstamp', '2022-06-01T00:00:00.000+0000'), ('IsDeleted', False) ]), @@ -80,9 +80,9 @@ class TestConvertCrmCsvDataProcess: expect_csv_string = """\ "Id","AccountNumber","LastModifiedDate","LastModifiedById","SystemModstamp","IsDeleted"\r\n\ - "TEST001","test001","2022-06-01 09:00:00","1234567","2022-06-01 09:00:00","1"\r\n\ - "TEST002","test002","2022-06-01 09:00:00","1234567","2022-06-01 09:00:00","0"\r\n\ - "TEST003","test003","2022-06-01 09:00:00","1234567","2022-06-01 09:00:00","0"\r\n\ + "TEST001","test001","2022-06-01 09:00:00","1234567.0","2022-06-01 09:00:00","1"\r\n\ + "TEST002","test002","2022-06-01 09:00:00","1.23","2022-06-01 09:00:00","0"\r\n\ + "TEST003","test003","2022-06-01 09:00:00","1.234567","2022-06-01 09:00:00","0"\r\n\ """ # 返り値の期待値チェック assert isinstance(actual_csv_string, str), 'CSV文字列が返却される'