Merge pull request #84 feature-NEWDWH2021-666 into develop-6crm
This commit is contained in:
commit
5b017f4d1f
@ -14,7 +14,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()
|
||||
@ -26,9 +25,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
|
||||
|
||||
@ -65,12 +61,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型を変換せずに返す処理"""
|
||||
|
||||
@ -4,7 +4,6 @@ from src.converter.convert_strategy import (BooleanConvertStrategy,
|
||||
ConvertStrategyFactory,
|
||||
DatetimeConvertStrategy,
|
||||
DictConvertStrategy,
|
||||
FloatConvertStrategy,
|
||||
IntConvertStrategy,
|
||||
NoneValueConvertStrategy,
|
||||
StringConvertStrategy)
|
||||
@ -32,7 +31,7 @@ class TestConvertStrategyFactory:
|
||||
def test_create_float(self):
|
||||
"""
|
||||
Cases:
|
||||
引数に指数表記を指定した場合、FloatConvertStrategyインスタンスが返ってくること
|
||||
引数に指数表記を指定した場合、StringConvertStrategyインスタンスが返ってくること
|
||||
Arranges:
|
||||
- なし
|
||||
Expects:
|
||||
@ -44,7 +43,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.2345678)
|
||||
|
||||
# Expects
|
||||
# 変換しない
|
||||
assert type(actual) == StringConvertStrategy
|
||||
|
||||
def test_create_bool_true(self):
|
||||
"""
|
||||
@ -243,26 +261,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`にて補正
|
||||
|
||||
@ -52,7 +52,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),
|
||||
('PersonMailingAddress', OrderedDict([
|
||||
@ -72,7 +72,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),
|
||||
('PersonMailingAddress', OrderedDict([
|
||||
@ -111,9 +111,9 @@ class TestConvertCrmCsvDataProcess:
|
||||
|
||||
expect_csv_string = """\
|
||||
"Id","AccountNumber","LastModifiedDate","LastModifiedById","SystemModstamp","IsDeleted","PersonMailingAddress"\r\n\
|
||||
"TEST001","test001","2022-06-01 09:00:00","1234567","2022-06-01 09:00:00","1","{""PersonMailingStreet"": ""Lorem ipsum dolor sit amet, \\nconsectetur adipiscing elit, \\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua."", ""PersonMailingCity"": ""New york city"", ""PersonMailingState"": ""Ohaio"", ""PersonMailingPostalCode"": ""999-9999"", ""PersonMailingCountry"": ""US"", ""PersonMailingLatitude"": 50.1234567, ""PersonMailingLongitude"": 103.1234567, ""PersonMailingGeocodeAccuracy"": ""Address""}"\r\n\
|
||||
"TEST002","test002","2022-06-01 09:00:00","1234567","2022-06-01 09:00:00","0","{""PersonMailingStreet"": ""Lorem ipsum dolor sit amet, \\nconsectetur adipiscing elit, \\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua."", ""PersonMailingCity"": ""New york city"", ""PersonMailingState"": ""Ohaio"", ""PersonMailingPostalCode"": ""999-9999"", ""PersonMailingCountry"": ""US"", ""PersonMailingLatitude"": 50.1234567, ""PersonMailingLongitude"": 103.1234567, ""PersonMailingGeocodeAccuracy"": ""Address""}"\r\n\
|
||||
"TEST003","test003","2022-06-01 09:00:00","1234567","2022-06-01 09:00:00","0","{""PersonMailingStreet"": ""Lorem ipsum dolor sit amet, \\nconsectetur adipiscing elit, \\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua."", ""PersonMailingCity"": ""New york city"", ""PersonMailingState"": ""Ohaio"", ""PersonMailingPostalCode"": ""999-9999"", ""PersonMailingCountry"": ""US"", ""PersonMailingLatitude"": 50.1234567, ""PersonMailingLongitude"": 103.1234567, ""PersonMailingGeocodeAccuracy"": ""Address""}"\r\n\
|
||||
"TEST001","test001","2022-06-01 09:00:00","1234567.0","2022-06-01 09:00:00","1","{""PersonMailingStreet"": ""Lorem ipsum dolor sit amet, \\nconsectetur adipiscing elit, \\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua."", ""PersonMailingCity"": ""New york city"", ""PersonMailingState"": ""Ohaio"", ""PersonMailingPostalCode"": ""999-9999"", ""PersonMailingCountry"": ""US"", ""PersonMailingLatitude"": 50.1234567, ""PersonMailingLongitude"": 103.1234567, ""PersonMailingGeocodeAccuracy"": ""Address""}"\r\n\
|
||||
"TEST002","test002","2022-06-01 09:00:00","1.23","2022-06-01 09:00:00","0","{""PersonMailingStreet"": ""Lorem ipsum dolor sit amet, \\nconsectetur adipiscing elit, \\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua."", ""PersonMailingCity"": ""New york city"", ""PersonMailingState"": ""Ohaio"", ""PersonMailingPostalCode"": ""999-9999"", ""PersonMailingCountry"": ""US"", ""PersonMailingLatitude"": 50.1234567, ""PersonMailingLongitude"": 103.1234567, ""PersonMailingGeocodeAccuracy"": ""Address""}"\r\n\
|
||||
"TEST003","test003","2022-06-01 09:00:00","1.234567","2022-06-01 09:00:00","0","{""PersonMailingStreet"": ""Lorem ipsum dolor sit amet, \\nconsectetur adipiscing elit, \\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua."", ""PersonMailingCity"": ""New york city"", ""PersonMailingState"": ""Ohaio"", ""PersonMailingPostalCode"": ""999-9999"", ""PersonMailingCountry"": ""US"", ""PersonMailingLatitude"": 50.1234567, ""PersonMailingLongitude"": 103.1234567, ""PersonMailingGeocodeAccuracy"": ""Address""}"\r\n\
|
||||
"""
|
||||
# 返り値の期待値チェック
|
||||
assert isinstance(actual_csv_string, str), 'CSV文字列が返却される'
|
||||
|
||||
@ -73,7 +73,6 @@ def test_walk_through(s3_test, s3_client, monkeypatch, caplog):
|
||||
object_info_list = get_object_config_list('object_info')
|
||||
for object_info in object_info_list:
|
||||
json_file = read_json(object_info)
|
||||
json_file = to_upload_json(json_file)
|
||||
upload_json(json_file, s3_client, CONFIG_BUCKET, f'{OBJECT_INFO_FOLDER}/{path.basename(object_info)}')
|
||||
object_info_files.append(json_file)
|
||||
last_fetch_datetime_list = get_object_config_list('last_fetch_datetime')
|
||||
@ -295,21 +294,6 @@ def upload_json(json_file, s3_client, bucket, folder):
|
||||
s3_client.put_object(Bucket=bucket, Key=folder, Body=json_str)
|
||||
|
||||
|
||||
def to_upload_json(json_file):
|
||||
"""Userオブジェクトの取得できないプロパティを取り除く
|
||||
TODO: Userオブジェクトの恒久対応が確定したらこのメソッドは消す
|
||||
"""
|
||||
for object_info in json_file['objects']:
|
||||
if object_info['object_name'] != 'User':
|
||||
continue
|
||||
columns: list = object_info['columns']
|
||||
columns.remove('LastPasswordChangeDate')
|
||||
columns.remove('NumberOfFailedLogins')
|
||||
columns.remove('UserPreferencesNativeEmailClient')
|
||||
|
||||
return json_file
|
||||
|
||||
|
||||
def set_environment(monkeypatch):
|
||||
# 環境変数を設定(CRMの認証情報は別途設定しておくこと)
|
||||
monkeypatch.setattr('src.aws.s3.IMPORT_DATA_BUCKET', DATA_BUCKET)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user