feat: dict型の変換器生成処理を追加
This commit is contained in:
parent
d77fafa2de
commit
35730fc45f
@ -1,4 +1,5 @@
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
|
||||
from dateutil.tz import gettz
|
||||
@ -17,6 +18,7 @@ class ConvertStrategyFactory:
|
||||
self.__datetime_convert_strategy = DatetimeConvertStrategy()
|
||||
self.__int_convert_strategy = IntConvertStrategy()
|
||||
self.__string_convert_strategy = StringConvertStrategy()
|
||||
self.__dict_convert_strategy = DictConvertStrategy()
|
||||
|
||||
def create(self, value):
|
||||
|
||||
@ -35,6 +37,8 @@ class ConvertStrategyFactory:
|
||||
elif type(value) == int:
|
||||
convert_strategy = self.__int_convert_strategy
|
||||
|
||||
elif type(value) == dict or type(value) == OrderedDict:
|
||||
convert_strategy = self.__dict_convert_strategy
|
||||
else:
|
||||
convert_strategy = self.__string_convert_strategy
|
||||
|
||||
@ -78,3 +82,9 @@ class StringConvertStrategy:
|
||||
"""string型を変換せずに返す処理"""
|
||||
# ConvertStrategyFactoryにて型チェックを行っているため値を変換せずに返す
|
||||
return convert_value
|
||||
|
||||
|
||||
class DictConvertStrategy:
|
||||
def convert_value(self, convert_value: str):
|
||||
"""dict型の項目を文字列に変換して返す処理"""
|
||||
return convert_value
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
from typing import OrderedDict
|
||||
|
||||
from src.converter.convert_strategy import (BooleanConvertStrategy,
|
||||
ConvertStrategyFactory,
|
||||
DatetimeConvertStrategy,
|
||||
DictConvertStrategy,
|
||||
FloatConvertStrategy,
|
||||
IntConvertStrategy,
|
||||
NoneValueConvertStrategy,
|
||||
@ -94,10 +97,10 @@ class TestConvertStrategyFactory:
|
||||
# Expects
|
||||
assert type(actual) == DatetimeConvertStrategy
|
||||
|
||||
def test_create_other_str(self):
|
||||
def test_create_str(self):
|
||||
"""
|
||||
Cases:
|
||||
引数にSalesforce日付型以外の文字列を指定した場合、NonConvertStrategyインスタンスが返ってくること
|
||||
引数にSalesforce日付型以外の文字列を指定した場合、StringConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
@ -111,10 +114,10 @@ class TestConvertStrategyFactory:
|
||||
# Expects
|
||||
assert type(actual) == StringConvertStrategy
|
||||
|
||||
def test_create_other_int(self):
|
||||
def test_create_int(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に整数を指定した場合、NonConvertStrategyインスタンスが返ってくること
|
||||
引数に整数を指定した場合、IntConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
@ -128,6 +131,40 @@ class TestConvertStrategyFactory:
|
||||
# Expects
|
||||
assert type(actual) == IntConvertStrategy
|
||||
|
||||
def test_create_dict(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に辞書型の値を指定した場合、IntConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create({'key': 'value'})
|
||||
|
||||
# Expects
|
||||
assert type(actual) == DictConvertStrategy
|
||||
|
||||
def test_create_ordered_dict_dict(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に辞書型の値を指定した場合、IntConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = ConvertStrategyFactory()
|
||||
actual = sut.create(OrderedDict([('key', 'value')]))
|
||||
|
||||
# Expects
|
||||
assert type(actual) == DictConvertStrategy
|
||||
|
||||
|
||||
class TestNoneValueConvertStrategy:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user