From b2e0582458eea423a82fe68c8bdba7a6e6b3c31b Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Fri, 7 Apr 2023 12:25:33 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=BD=E5=8A=A0=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=AE=E3=83=AC=E3=82=B3=E3=83=BC=E3=83=89=E4=BB=B6?= =?UTF-8?q?=E6=95=B0=E3=82=92=E5=A2=97=E3=82=84=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../table_mapper/test_com_alma_mapper.py | 47 ++++++++++++++++--- .../tests/testing_utility.py | 6 ++- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/test_com_alma_mapper.py b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/test_com_alma_mapper.py index a46e9f03..3a800949 100644 --- a/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/test_com_alma_mapper.py +++ b/ecs/jskult-batch-daily/tests/batch/ultmarc/utmp_tables/table_mapper/test_com_alma_mapper.py @@ -37,7 +37,7 @@ class TestComAlmaMapper: self.db.rollback() self.db.disconnect() - def test_insert_record_one(self, expect_datetime: datetime, expect_date_str: str): + def test_insert_record(self, expect_datetime: datetime, expect_date_str: str): """ Cases: COM_出身校テーブルにレコードを1件登録する @@ -51,9 +51,24 @@ class TestComAlmaMapper: # Arrange # 処理日設定 self.batch_config.syor_date = datetime.strftime(datetime.now(), '%Y/%m/%d') - # テストデータ1件作成 + # テストデータ作成 + code_and_name = [ + ['001', '北大'], + ['002', '札幌医'], + ['003', '弘大'], + ['004', '岩手医'], + ['005', '東北大'], + ['006', '福島医'] + ] test_dat_file = create_ultmarc_test_csv( - '"004","001","A","20141113","20141114","北大","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"' + [ + f'"004","{code_and_name[0][0]}","A","20141113","20141114","{code_and_name[0][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[1][0]}","A","20141113","20141114","{code_and_name[1][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[2][0]}","A","20141113","20141114","{code_and_name[2][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[3][0]}","A","20141113","20141114","{code_and_name[3][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[4][0]}","A","20141113","20141114","{code_and_name[4][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[5][0]}","A","20141113","20141114","{code_and_name[5][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"' + ] ) # 一旦全データをDBから削除 delete_sql, delete_parameter = create_delete_sql_with_parameter('src05.com_alma', {'1': '1'}) @@ -71,8 +86,7 @@ class TestComAlmaMapper: # Assert # 期待値となるモジュール名 module_name = get_module_name(com_alma_mapper) - # 実行日時 - expect_row = ["001", "北大"] + create_ultmarc_common_column_values( + expect_row = [code_and_name[i - 1][0], code_and_name[i - 1][1]] + create_ultmarc_common_column_values( regist_ymd=expect_date_str, sys_regist_date=expect_datetime, regist_prgm_id=module_name, @@ -80,7 +94,7 @@ class TestComAlmaMapper: update_prgm_id=module_name ) expect_rows = [{c: r for c, r in zip(self.table_columns, expect_row)}] - actual_rows = self.db.execute_select("SELECT * FROM src05.com_alma WHERE alma_cd = '001'") + actual_rows = self.db.execute_select(f"SELECT * FROM src05.com_alma WHERE alma_cd = '{code_and_name[i - 1][0]}'") # 期待値検査 assert_table_results(actual_rows, expect_rows, line_number=i) @@ -99,7 +113,26 @@ class TestComAlmaMapper: # Arrange # 処理日設定 self.batch_config.syor_date = datetime.strftime(datetime.now(), '%Y/%m/%d') - # テストデータ1件作成 + # テストデータ作成 + code_and_name = [ + ['001', '北大'], + ['002', '札幌医'], + ['003', '弘大'], + ['004', '岩手医'], + ['005', '東北大'], + ['006', '福島医'] + ] + test_dat_file = create_ultmarc_test_csv( + [ + f'"004","{code_and_name[0][0]}","A","20141113","20141114","{code_and_name[0][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[1][0]}","A","20141113","20141114","{code_and_name[1][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[2][0]}","A","20141113","20141114","{code_and_name[2][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[3][0]}","A","20141113","20141114","{code_and_name[3][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[4][0]}","A","20141113","20141114","{code_and_name[4][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"', + f'"004","{code_and_name[5][0]}","A","20141113","20141114","{code_and_name[5][1]}","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"' + ] + ) + # テストデータ作成 test_dat_file = create_ultmarc_test_csv( '"004","001","B","20141113","20141114","テスト大","1","2014/11/21 22:53","VANLOAD",,,"2014/11/21 22:53"' ) diff --git a/ecs/jskult-batch-daily/tests/testing_utility.py b/ecs/jskult-batch-daily/tests/testing_utility.py index c483c9af..6f2c80f0 100644 --- a/ecs/jskult-batch-daily/tests/testing_utility.py +++ b/ecs/jskult-batch-daily/tests/testing_utility.py @@ -11,7 +11,7 @@ from src.batch.ultmarc.utmp_tables.ultmarc_table_mapper_factory import \ from src.db.database import Database -def create_ultmarc_test_csv(*csv_rows: str) -> DatFile: +def create_ultmarc_test_csv(csv_rows: list[str]) -> DatFile: """アルトマーク取込テストのCSVを作成 Args: csv_rows (tuple[str]): CSV文字列のリスト @@ -19,7 +19,9 @@ def create_ultmarc_test_csv(*csv_rows: str) -> DatFile: list[list[str]]: CSVデータ """ string_io = io.StringIO() - string_io.writelines(csv_rows) + for csv_row in csv_rows: + string_io.write(csv_row) + string_io.write('\n') string_io.seek(0) dat_file = DatFile(string_io)