From 75a787aecebda18a00fa46f0c7d3f10bdfe2dd90 Mon Sep 17 00:00:00 2001 From: Mathias Schneider Date: Sun, 13 Sep 2026 20:46:40 +0200 Subject: [PATCH] comdirect ingest tests (tbc) --- src/ingest/comdirect.py | 16 ++++++++-------- tests/test_ingest_comdirect.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 tests/test_ingest_comdirect.py diff --git a/src/ingest/comdirect.py b/src/ingest/comdirect.py index 783593b..e9ea3a1 100644 --- a/src/ingest/comdirect.py +++ b/src/ingest/comdirect.py @@ -44,6 +44,7 @@ def reader_comdirect(path: Path) -> dict[str, list[ComdirectExportModel]]: result = {} raw = _reader_raw_comdirect(path) for account in ACCOUNTS: + assert account.name in raw data_raw: Csv2Dict = raw.pop(account.name) data: list = list(map(account.model.model_validate, data_raw)) result[account.name] = data @@ -53,7 +54,7 @@ def reader_comdirect(path: Path) -> dict[str, list[ComdirectExportModel]]: def _reader_raw_comdirect(path: Path) -> CsV2DictMulti: - with path.open(encoding="latin1") as fid: + with path.open("r", encoding="utf-8") as fid: lines = fid.readlines() expect_next = EXPECT_LINE.ACCOUNT_NAME @@ -122,7 +123,7 @@ def upsert_comdirect_giro( ) -def ingest_comdirect(path: Path, account_iban: str, account_currency: str): +def ingest_comdirect(session: Session, path: Path, account_iban: str, account_currency: str): assert SOURCE_COMDIRECT data_collection = reader_comdirect(path) for account_name, data in data_collection.items(): @@ -138,9 +139,8 @@ def ingest_comdirect(path: Path, account_iban: str, account_currency: str): ) else: continue - with get_session() as session: - for row in data: - data_validated = account.model.model_validate(row) - assert isinstance(data_validated, account.model) - db_load_function(session, row, account) - session.commit() + for row in data: + data_validated = account.model.model_validate(row) + assert isinstance(data_validated, account.model) + db_load_function(session, row, account) + session.commit() diff --git a/tests/test_ingest_comdirect.py b/tests/test_ingest_comdirect.py new file mode 100644 index 0000000..862dc25 --- /dev/null +++ b/tests/test_ingest_comdirect.py @@ -0,0 +1,33 @@ +from pathlib import Path + +import pytest +from faker import Faker +from sqlalchemy.orm import Session + +from src.constants import Currency +from src.ingest.comdirect import ( + _reader_raw_comdirect, + ingest_comdirect, + reader_comdirect, +) + +TEST_DATA_PATH = Path("tests/test_data/comdirect_export_dummy_01.txt") + + +def test_reader_comdirect_raw(): + result = _reader_raw_comdirect(TEST_DATA_PATH) + assert result + +def test_reader_comdirect(): + result = reader_comdirect(TEST_DATA_PATH) + assert result + assert isinstance(result, dict) + +@pytest.mark.skip +def test_ingest_comdirect(db_session: Session): + ingest_comdirect( + session=db_session, + path=TEST_DATA_PATH, + account_iban=Faker().iban(), + account_currency=Currency.EUR, + )