feat: convert_strategyのテストコード追加
This commit is contained in:
parent
ec74a8cf46
commit
a40bad2033
@ -59,5 +59,5 @@ class FloatConvertStrategy:
|
||||
|
||||
|
||||
class NonConvertStrategy:
|
||||
def convert_value(self, convert_value: str):
|
||||
def convert_value(self, convert_value):
|
||||
return convert_value
|
||||
|
||||
@ -71,8 +71,8 @@ UPD_JP_NAME = '前回取得日時ファイル更新'
|
||||
END_JP_NAME = '取得処理実施結果アップロード処理'
|
||||
|
||||
# CSVチェック
|
||||
CSV_TRUE_VALUE = '1'
|
||||
CSV_FALSE_VALUE = '0'
|
||||
CSV_TRUE_VALUE = 1
|
||||
CSV_FALSE_VALUE = 0
|
||||
|
||||
# オブジェクト変数
|
||||
OBJECTS_KEY = 'objects'
|
||||
|
||||
262
ecs/crm-datafetch/tests/converter/test_convert_strategy.py
Normal file
262
ecs/crm-datafetch/tests/converter/test_convert_strategy.py
Normal file
@ -0,0 +1,262 @@
|
||||
from src.converter.convert_strategy import (BooleanConvertStrategy,
|
||||
ConvertStrategyFactory,
|
||||
DatetimeConvertStrategy,
|
||||
FloatConvertStrategy,
|
||||
NonConvertStrategy,
|
||||
NoneValueConvertStrategy)
|
||||
|
||||
|
||||
class TestConvertStrategyFactory:
|
||||
|
||||
def test_create_none(self):
|
||||
"""
|
||||
Cases:
|
||||
引数にnull(None)を指定した場合、NoneValueConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create(None)
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "NoneValueConvertStrategy"
|
||||
|
||||
def test_create_float(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に指数表記を指定した場合、FloatConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create(1.2345678E7)
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "FloatConvertStrategy"
|
||||
|
||||
def test_create_bool_true(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に論理値(True)を指定した場合、BooleanConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create(True)
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "BooleanConvertStrategy"
|
||||
|
||||
def test_create_bool_false(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に論理値(False)を指定した場合、BooleanConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create(False)
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "BooleanConvertStrategy"
|
||||
|
||||
def test_create_datetime(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に文字列かつ日付文字列を指定した場合、DatetimeConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create('2022-06-13T10:15:32.000+0000')
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "DatetimeConvertStrategy"
|
||||
|
||||
def test_create_other_str(self):
|
||||
"""
|
||||
Cases:
|
||||
引数にSalesforce日付型以外の文字列を指定した場合、NonConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create('test_string')
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "NonConvertStrategy"
|
||||
|
||||
def test_create_other_int(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に整数を指定した場合、NonConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create(100)
|
||||
|
||||
# Expects
|
||||
assert type(actual).__name__ == "NonConvertStrategy"
|
||||
|
||||
|
||||
class TestNoneValueConvertStrategy:
|
||||
|
||||
def test_convert_value(self) -> str:
|
||||
"""
|
||||
Cases:
|
||||
引数にnull(None)を指定した場合、''(空文字)が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = NoneValueConvertStrategy()
|
||||
actual = sut.convert_value(None)
|
||||
|
||||
# Expects
|
||||
assert actual == ""
|
||||
|
||||
|
||||
class TestBooleanConvertStrategy:
|
||||
|
||||
def test_convert_value_true(self) -> bool:
|
||||
"""
|
||||
Cases:
|
||||
引数に論理値(True)を指定した場合、数値(1)が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = BooleanConvertStrategy()
|
||||
actual = sut.convert_value(True)
|
||||
|
||||
# Expects
|
||||
assert actual == 1
|
||||
|
||||
def test_convert_value_false(self) -> bool:
|
||||
"""
|
||||
Cases:
|
||||
引数に論理値(False)を指定した場合、数値(0)が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = BooleanConvertStrategy()
|
||||
actual = sut.convert_value(False)
|
||||
|
||||
# Expects
|
||||
assert actual == 0
|
||||
|
||||
|
||||
class TestDatetimeConvertStrategy:
|
||||
|
||||
def test_convert_value(self) -> str:
|
||||
"""
|
||||
Cases:
|
||||
引数に日付文字列を指定した場合、YYYY-MM-DD HH:MM:SSがJSTで返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = DatetimeConvertStrategy()
|
||||
actual = sut.convert_value('2022-06-13T20:15:32.000+0000')
|
||||
|
||||
# Expects
|
||||
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 TestNonConvertStrategy:
|
||||
|
||||
def test_convert_value_str(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に文字列を指定した場合、加工されず文字列が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = NonConvertStrategy()
|
||||
actual = sut.convert_value('テストデータ')
|
||||
|
||||
# Expects
|
||||
assert actual == 'テストデータ'
|
||||
|
||||
def test_convert_value_int(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に整数を指定した場合、加工されず整数が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = NonConvertStrategy()
|
||||
actual = sut.convert_value(100)
|
||||
|
||||
# Expects
|
||||
assert actual == 100
|
||||
Loading…
x
Reference in New Issue
Block a user