comdirect ingest tests (tbc)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
Reference in New Issue
Block a user