feat: 追加テストのレコード件数を増やした

This commit is contained in:
shimoda.m@nds-tyo.co.jp 2023-04-07 12:25:33 +09:00
parent d5f305c561
commit b2e0582458
2 changed files with 44 additions and 9 deletions

View File

@ -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"'
)

View File

@ -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)