|
| 1 | +import pytest |
| 2 | +from beancount.core.amount import Amount |
| 3 | +from beancount.core.number import D |
| 4 | + |
| 5 | +from tariochbctools.importers.postfinance import importer as pfimp |
| 6 | + |
| 7 | +TEST_CSV = """ |
| 8 | +Booking date;Notification text;Credit in CHF;Debit in CHF;Value;Balance in CHF |
| 9 | +31.12.2022;"Preis für Bankpaket Smart";;-5;31.12.2022;7881.98 |
| 10 | +""" |
| 11 | + |
| 12 | +TEST_CSV_2021 = """ |
| 13 | +Booking date;Notification text;Credit in CHF;Debit in CHF;Value;Balance in CHF |
| 14 | +2022-12-31;"Preis für Bankpaket Smart";;-5;2022-12-31;7881.98 |
| 15 | +""" |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture(name="importer") |
| 19 | +def importer_fixture(): |
| 20 | + importer = pfimp.Importer(".*.csv", "Assets:PostFinance:CHF") |
| 21 | + yield importer |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def tmp_csv(tmp_path, request): |
| 26 | + csv = tmp_path / "test.csv" |
| 27 | + csv.write_text(request.param) |
| 28 | + yield csv |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.parametrize("tmp_csv", [TEST_CSV], indirect=True) |
| 32 | +def test_identify(importer, tmp_csv): |
| 33 | + assert importer.identify(str(tmp_csv)) |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.parametrize( |
| 37 | + "tmp_csv", |
| 38 | + (TEST_CSV, TEST_CSV_2021), |
| 39 | + ids=("dd.mm.yyyy", "yyyy-mm-dd"), |
| 40 | + indirect=True, |
| 41 | +) |
| 42 | +def test_extract(importer, tmp_csv): |
| 43 | + entries = importer.extract(str(tmp_csv), []) |
| 44 | + assert entries |
| 45 | + assert entries[0].postings[-1].units == Amount(D(-5), "CHF") |
| 46 | + assert entries[0].date.year == 2022 |
0 commit comments