From 977c5bf7ef35bb30a2f005bd9ae4d701de72fe9e Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Tue, 23 Aug 2022 11:51:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BE=9E=E6=9B=B8=E5=9E=8B=E9=A0=85?= =?UTF-8?q?=E7=9B=AE=E3=82=92=E6=96=87=E5=AD=97=E5=88=97=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=8F=9B=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/converter/convert_strategy.py | 5 +- .../tests/converter/test_convert_strategy.py | 58 ++++++++++++++++++- .../tests/salesforce/test_salesforce.py | 1 + 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/ecs/crm-datafetch/src/converter/convert_strategy.py b/ecs/crm-datafetch/src/converter/convert_strategy.py index 3e092315..5f3daf9d 100644 --- a/ecs/crm-datafetch/src/converter/convert_strategy.py +++ b/ecs/crm-datafetch/src/converter/convert_strategy.py @@ -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) diff --git a/ecs/crm-datafetch/tests/converter/test_convert_strategy.py b/ecs/crm-datafetch/tests/converter/test_convert_strategy.py index 77ecfea2..20d5f655 100644 --- a/ecs/crm-datafetch/tests/converter/test_convert_strategy.py +++ b/ecs/crm-datafetch/tests/converter/test_convert_strategy.py @@ -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 == '{"テストデータキー": "テストデータバリュー"}' diff --git a/ecs/crm-datafetch/tests/salesforce/test_salesforce.py b/ecs/crm-datafetch/tests/salesforce/test_salesforce.py index 2b02a5cb..9547b97d 100644 --- a/ecs/crm-datafetch/tests/salesforce/test_salesforce.py +++ b/ecs/crm-datafetch/tests/salesforce/test_salesforce.py @@ -507,6 +507,7 @@ class TestSalesforceApiClient: 'Name', 'SystemModstamp', 'LastModifiedDate', + 'BillingAddress', 'CustomItem1__c', 'CustomItem2__c', 'CustomItem3__c',