feat: write_to_stringメソッドのテストを追加
This commit is contained in:
parent
cade77d14b
commit
cede4e0e12
@ -72,4 +72,4 @@ class CSVStringConverter:
|
||||
return csv_value
|
||||
|
||||
except Exception as e:
|
||||
raise Exception('CSVデータの取得に失敗しました', e)
|
||||
raise Exception('CSVデータの出力に失敗しました', e)
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import textwrap
|
||||
from collections import OrderedDict
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from src.config.objects import TargetObject
|
||||
@ -106,6 +105,7 @@ class TestCSVStringConverter:
|
||||
"TEST003","test003","","9","10","11","12","テストのため3","2022-06-04 08:50:50","3234567","0"\r\n\
|
||||
'''
|
||||
|
||||
# expected_valueのインデントが半角スペースと認識されてしまうため、`textwrap.dedent`にて補正
|
||||
assert actual == textwrap.dedent(expected_value)
|
||||
|
||||
def test_raise_convert_extract_jsons(self) -> str:
|
||||
@ -200,7 +200,7 @@ class TestCSVStringConverter:
|
||||
# Expects
|
||||
assert '必要なjsonのデータ成形に失敗しました' in str(e.value)
|
||||
|
||||
def test_raise_convert_convert_csv(self) -> str:
|
||||
def test_raise_convert_convert_to_csv(self) -> str:
|
||||
"""
|
||||
Cases:
|
||||
一部データのカラム(Id)の不足により、CSV変換で例外が発生すること
|
||||
@ -292,16 +292,16 @@ class TestCSVStringConverter:
|
||||
# Expects
|
||||
assert 'CSV変換に失敗しました カラム名:[Id] 行番号: [1]' in str(e.value)
|
||||
|
||||
@mock.patch('src.converter.converter.CSVStringConverter.create')
|
||||
def test_raise_convert_csv_string(self, execute_mock) -> str:
|
||||
def test_raise_convert_write_csv_string(self, monkeypatch) -> str:
|
||||
"""
|
||||
Cases:
|
||||
一部データのカラム(Id)の不足により、CSV変換で例外が発生すること
|
||||
csvデータ出力の、CSVデータ取得で例外が発生すること
|
||||
Arranges:
|
||||
- オブジェクト情報の作成
|
||||
- データの作成
|
||||
- 実行日時取得インスタンスの生成
|
||||
- オブジェクト情報インスタンスの生成
|
||||
- csvデータ出力のエラーを発生させるためのモックを準備
|
||||
Expects:
|
||||
例外が期待値と一致すること
|
||||
"""
|
||||
@ -377,15 +377,17 @@ class TestCSVStringConverter:
|
||||
execute_datetime = ExecuteDateTime()
|
||||
target_object = TargetObject(object_info, execute_datetime)
|
||||
|
||||
def dummy_method(arg):
|
||||
raise Exception(e)
|
||||
|
||||
# データ加工のみだと事前の処理によりエラーとなるため、csv出力モジュールをモック化する
|
||||
monkeypatch.setattr("csv.writer", dummy_method)
|
||||
|
||||
# Act
|
||||
csv_string_converter = CSVStringConverter(target_object, data)
|
||||
|
||||
execute_mock.side_effect = Exception
|
||||
with pytest.raises(Exception) as e:
|
||||
csv_string_converter.convert()
|
||||
|
||||
# actual = csv_string_converter.convert()
|
||||
|
||||
# Expects
|
||||
assert 'CSVデータの取得に失敗しました' in str(e.value)
|
||||
# assert actual == 'CSVデータの取得に失敗しました'
|
||||
assert 'CSVデータの出力に失敗しました' in str(e.value)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user