diff --git a/tests/test_reconcile.py b/tests/test_reconcile.py index aa368a882426e20bddfeb7784b13faf8650edfd9..9d58eb77b0cc60b95ca147939bdfcfc192d0c661 100644 --- a/tests/test_reconcile.py +++ b/tests/test_reconcile.py @@ -1,5 +1,6 @@ import datetime import decimal +import io import os import tempfile import textwrap @@ -9,10 +10,10 @@ from conservancy_beancount.reconcile.statement_reconciler import ( match_statement_and_books, metadata_for_match, payee_match, + read_amex_csv, + read_fr_csv, remove_duplicate_words, remove_payee_junk, - standardize_amex_record, - standardize_fr_record, subset_match, totals, write_metadata_to_books, @@ -345,40 +346,36 @@ def test_subset_passes_through_all_non_matches(): ) -def test_handles_fr_record_with_comma_separators(): - # CSV would look something like: - # - # "Date","ABA Num","Currency","Account Num","Account Name","Description","BAI Code","Amount","Serial Num","Ref Num","Detail" - # "02/07/2022",,,,,,,"10,000.00",,,"XXXX" - input_row = { - 'Date': '02/07/2022', - 'Amount': '10,000.00', - 'Detail': 'XXXX', - 'Serial Num': '', - } - expected = { - 'date': datetime.date(2022, 2, 7), - 'amount': decimal.Decimal('10000'), - 'payee': 'XXXX', - 'check_id': '', - 'line': 1, - } - assert standardize_fr_record(input_row, line=1) == expected - - -def test_handles_amex_record_with_comma_separators(): - # This insn't typically a problem with AMEX, but adding for completeness. - input_row = { - 'Date': '02/07/2022', - 'Amount': '-10,000.00', # Amounts are from Bank's perspective/negated. - 'Description': 'XXXX', - 'Serial Num': '', - } - expected = { - 'date': datetime.date(2022, 2, 7), - 'amount': decimal.Decimal('10000'), - 'payee': 'XXXX', - 'check_id': '', - 'line': 1, - } - assert standardize_amex_record(input_row, line=1) == expected +def test_handles_amex_csv(): + CSV = """Date,Receipt,Description,Card Member,Account #,Amount,Extended Details,Appears On Your Statement As,Address,City/State,Zip Code,Country,Reference,Category\n08/19/2021,,Gandi.net San Francisco,RODNEY R BROWN,-99999,28.15,"00000009999 00000009999999999999\nGandi.net\nSan Francisco\n00000009999999999999",Gandi.net San Francisco,"NEPTUNUSSTRAAT 41-63\nHOOFDDORP",,2132 JA,NETHERLANDS (THE),'999999999999999999',Merchandise & Supplies-Internet Purchase\n""" + expected = [ + { + 'date': datetime.date(2021, 8, 19), + 'amount': decimal.Decimal('-28.15'), + 'payee': 'Gandi San Francisco', + 'check_id': '', + 'line': 2, + }, + ] + assert read_amex_csv(io.StringIO(CSV)) == expected + + +def test_handles_fr_csv(): + CSV = """"DD99999999999","03/31/2022","LAST STATEMENT","","","$1,000.00"\n"9999999999999","04/01/2022","INCOMING WIRE","GONDOR S.S. A111111111BCDE0F","$6.50","$1,006.50"\n"DD99999999999","04/18/2022","CHECK 3741","","$-4.50","$1,002.00"\n"DD99999999999","04/30/2022","THIS STATEMENT","","","$102.00"\n""" + expected = [ + { + 'date': datetime.date(2022, 4, 1), + 'amount': decimal.Decimal('6.50'), + 'payee': 'GONDOR S.S. A1111111', + 'check_id': '', + 'line': 2, + }, + { + 'date': datetime.date(2022, 4, 18), + 'amount': decimal.Decimal('-4.50'), + 'payee': '', + 'check_id': '3741', + 'line': 3, + }, + ] + assert read_fr_csv(io.StringIO(CSV)) == expected