feat: 辞書型項目を文字列に変換する処理を追加
This commit is contained in:
parent
2e24ce85f2
commit
5e857aa9c6
@ -1,3 +1,4 @@
|
||||
import json
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime
|
||||
@ -85,6 +86,6 @@ class StringConvertStrategy:
|
||||
|
||||
|
||||
class DictConvertStrategy:
|
||||
def convert_value(self, convert_value: str):
|
||||
def convert_value(self, convert_value: dict):
|
||||
"""dict型の項目を文字列に変換して返す処理"""
|
||||
return convert_value
|
||||
return json.dumps(convert_value, ensure_ascii=False)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from typing import OrderedDict
|
||||
from collections import OrderedDict
|
||||
|
||||
from src.converter.convert_strategy import (BooleanConvertStrategy,
|
||||
ConvertStrategyFactory,
|
||||
@ -301,3 +301,59 @@ class TestStringConvertStrategy:
|
||||
|
||||
# Expects
|
||||
assert actual == 'テストデータ'
|
||||
|
||||
|
||||
class TestDictConvertStrategy:
|
||||
|
||||
def test_convert_value_dict(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に辞書型のデータを指定した場合、JSONの文字列が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = DictConvertStrategy()
|
||||
actual = sut.convert_value({'テストデータキー': 'テストデータバリュー'})
|
||||
|
||||
# Expects
|
||||
assert actual == '{"テストデータキー": "テストデータバリュー"}'
|
||||
|
||||
def test_convert_value_dict_in_line_break(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に辞書型のデータを指定した場合、JSONの文字列が返ってくること(バリューに改行を含む)
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = DictConvertStrategy()
|
||||
actual = sut.convert_value({'テストデータキー': 'テスト\nデータ\nバリュー'})
|
||||
|
||||
# Expects
|
||||
assert actual == '{"テストデータキー": "テスト\\nデータ\\nバリュー"}'
|
||||
|
||||
def test_convert_value_ordered_dict(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に整列された辞書型のデータを指定した場合、JSONの文字列が返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
- 戻り値が、期待値と一致する
|
||||
"""
|
||||
|
||||
# Act
|
||||
sut = DictConvertStrategy()
|
||||
actual = sut.convert_value(OrderedDict(
|
||||
[('テストデータキー', 'テストデータバリュー')]
|
||||
))
|
||||
|
||||
# Expects
|
||||
assert actual == '{"テストデータキー": "テストデータバリュー"}'
|
||||
|
||||
@ -507,6 +507,7 @@ class TestSalesforceApiClient:
|
||||
'Name',
|
||||
'SystemModstamp',
|
||||
'LastModifiedDate',
|
||||
'BillingAddress',
|
||||
'CustomItem1__c',
|
||||
'CustomItem2__c',
|
||||
'CustomItem3__c',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user