89 lines
2.7 KiB
Python
89 lines
2.7 KiB
Python
"""Simple non-regression tests for the Statement PDF parser.
|
|
|
|
It's possible to drop some PDF files in the test directory to run some
|
|
tests against them too.
|
|
"""
|
|
|
|
import datetime as dt
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from boursobank import Statement, CardStatement, AccountStatement
|
|
|
|
|
|
def test_parse_header_2012():
|
|
"""Test parsing an old format of headers where the date can have a
|
|
single digit.
|
|
"""
|
|
statement = Statement.from_string(
|
|
"""
|
|
...
|
|
1/02/2012 12345 12345 00000000000 99 EUR 31/12/2011\
|
|
31/01/2012 1.000,00 € 0,000000 % 1
|
|
...
|
|
"""
|
|
)
|
|
assert statement.headers["date"] == dt.date(2012, 1, 1)
|
|
assert isinstance(statement, AccountStatement)
|
|
|
|
|
|
def test_parse_header_cb():
|
|
"""Test parsing a Bank Card statement header (with a bank card number in it)."""
|
|
|
|
statement = Statement.from_string(
|
|
"""
|
|
...
|
|
28/02/2024 12345 12345 00000000000 99 4810********9999 \
|
|
du 30/01/2024 au 27/02/2024 1/2
|
|
...
|
|
"""
|
|
)
|
|
assert statement.headers["date"] == dt.date(2024, 2, 1)
|
|
assert isinstance(statement, CardStatement)
|
|
|
|
|
|
def test_parse_cb_line():
|
|
"""Test parsing a CB line which contains the label AFTER the value date."""
|
|
|
|
statement = Statement.from_string(
|
|
"""
|
|
28/02/2024 12345 12345 00000000000 99 4810********9999 du \
|
|
30/01/2024 au 27/02/2024 1/2
|
|
12/02/2024 CARTE 10/02/24 PHOTOMATON 8,00
|
|
...
|
|
"""
|
|
)
|
|
assert statement.lines
|
|
assert statement.lines[0].value == -8
|
|
|
|
|
|
@pytest.mark.parametrize("pdf", list(Path(__file__).parent.glob("*.pdf")))
|
|
def test_cb_consistency_from_files(pdf):
|
|
"""Test PDF files in the tests/ directory (place them yourself, there's not)."""
|
|
statement = Statement.from_pdf(pdf)
|
|
if not isinstance(statement, CardStatement):
|
|
return
|
|
found = statement.card_debit
|
|
computed = sum(line.value for line in statement.lines)
|
|
assert (
|
|
found == computed
|
|
), f"Inconsistent total, found: {found!r}, computed: {computed!r}"
|
|
|
|
|
|
def test_old_owner():
|
|
statement = Statement.from_string(
|
|
"""
|
|
EN CAS DE PERTE OU DE VOL
|
|
- Appelez le Centre d'opposition au 09 77 40 10 08
|
|
pour une Carte VISA Classic, au 04 42 60 53 44
|
|
pour une Carte VISA Premier.
|
|
- Faites une déclaration au Commissariat de Police
|
|
- Confirmez par courrier à Boursorama Banque, Service Client
|
|
44 rue Traversiere CS 80134 92772 Boulogne-Billancourt Cedex THE OWNER IS HERE
|
|
|
|
28/02/2024 12345 12345 00000000000 99 4810********9999 du \
|
|
30/01/2024 au 27/02/2024 1/2
|
|
"""
|
|
)
|
|
assert statement.headers["card_owner"] == "THE OWNER IS HERE"
|