Ingest comdirect #5
@@ -44,6 +44,7 @@ def reader_comdirect(path: Path) -> dict[str, list[ComdirectExportModel]]:
|
|||||||
result = {}
|
result = {}
|
||||||
raw = _reader_raw_comdirect(path)
|
raw = _reader_raw_comdirect(path)
|
||||||
for account in ACCOUNTS:
|
for account in ACCOUNTS:
|
||||||
|
assert account.name in raw
|
||||||
data_raw: Csv2Dict = raw.pop(account.name)
|
data_raw: Csv2Dict = raw.pop(account.name)
|
||||||
data: list = list(map(account.model.model_validate, data_raw))
|
data: list = list(map(account.model.model_validate, data_raw))
|
||||||
result[account.name] = data
|
result[account.name] = data
|
||||||
@@ -53,7 +54,7 @@ def reader_comdirect(path: Path) -> dict[str, list[ComdirectExportModel]]:
|
|||||||
|
|
||||||
def _reader_raw_comdirect(path: Path) -> CsV2DictMulti:
|
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()
|
lines = fid.readlines()
|
||||||
|
|
||||||
expect_next = EXPECT_LINE.ACCOUNT_NAME
|
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
|
assert SOURCE_COMDIRECT
|
||||||
data_collection = reader_comdirect(path)
|
data_collection = reader_comdirect(path)
|
||||||
for account_name, data in data_collection.items():
|
for account_name, data in data_collection.items():
|
||||||
@@ -138,7 +139,6 @@ def ingest_comdirect(path: Path, account_iban: str, account_currency: str):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
with get_session() as session:
|
|
||||||
for row in data:
|
for row in data:
|
||||||
data_validated = account.model.model_validate(row)
|
data_validated = account.model.model_validate(row)
|
||||||
assert isinstance(data_validated, account.model)
|
assert isinstance(data_validated, account.model)
|
||||||
|
|||||||
@@ -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