fix: 指数表記の変換を行っていたことにより、他の少数項目が整数になってしまっていたのを修正
This commit is contained in:
parent
9a511af10b
commit
4d179f6be5
@ -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型を変換せずに返す処理"""
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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`にて補正
|
||||
|
||||
@ -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文字列が返却される'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user