diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 4854363e21399218f6cc2346c937f9307242cd4d..8ecac99fce758fd1f82237cc6bd000f284a65568 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -263,82 +263,6 @@ def test_report_type_by_unknown_name(arg): with pytest.raises(ValueError): accrual.ReportType.by_name(arg) -@pytest.mark.parametrize('acct_name', ACCOUNTS) -def test_accrual_postings_consistent_account(acct_name): - meta = {'invoice': '{acct_name} invoice.pdf'} - txn = testutil.Transaction(postings=[ - (acct_name, 50, meta), - (acct_name, 25, meta), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - assert related.account == acct_name - -def test_accrual_postings_entity(): - txn = testutil.Transaction(postings=[ - (ACCOUNTS[0], 25, {'entity': 'Accruee'}), - (ACCOUNTS[0], -15, {'entity': 'Payee15'}), - (ACCOUNTS[0], -10, {'entity': 'Payee10'}), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - assert related.entity == 'Accruee' - assert set(related.entities()) == {'Accruee', 'Payee10', 'Payee15'} - -def test_accrual_postings_entities(): - txn = testutil.Transaction(postings=[ - (ACCOUNTS[0], 25, {'entity': 'Accruee'}), - (ACCOUNTS[0], -15, {'entity': 'Payee15'}), - (ACCOUNTS[0], -10, {'entity': 'Payee10'}), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - actual = related.entities() - assert next(actual, None) == 'Accruee' - assert set(actual) == {'Payee10', 'Payee15'} - -def test_accrual_postings_entities_no_duplicates(): - txn = testutil.Transaction(postings=[ - (ACCOUNTS[0], 25, {'entity': 'Accruee'}), - (ACCOUNTS[0], -15, {'entity': 'Accruee'}), - (ACCOUNTS[0], -10, {'entity': 'Other'}), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - actual = related.entities() - assert next(actual, None) == 'Accruee' - assert next(actual, None) == 'Other' - assert next(actual, None) is None - -def test_accrual_postings_inconsistent_account(): - meta = {'invoice': 'invoice.pdf'} - txn = testutil.Transaction(postings=[ - (acct_name, index, meta) - for index, acct_name in enumerate(ACCOUNTS) - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - assert related.account is related.INCONSISTENT - -def test_accrual_postings_rt_id(): - txn = testutil.Transaction(postings=[ - (ACCOUNTS[0], 10, {'rt-id': 'rt:90'}), - (ACCOUNTS[0], 10, {'rt-id': 'rt:90 rt:92'}), - (ACCOUNTS[0], 10, {'rt-id': 'rt:90 rt:94 rt:92'}), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - assert related.rt_id == 'rt:90' - -def test_accrual_postings_rt_id_inconsistent(): - txn = testutil.Transaction(postings=[ - (ACCOUNTS[0], 10, {'rt-id': 'rt:96'}), - (ACCOUNTS[0], 10, {'rt-id': 'rt:98 rt:96'}), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - assert related.rt_id is related.INCONSISTENT - -def test_accrual_postings_rt_id_none(): - txn = testutil.Transaction(postings=[ - (ACCOUNTS[0], 10), - ]) - related = accrual.AccrualPostings(data.Posting.from_txn(txn)) - assert related.rt_id is None - @pytest.mark.parametrize('acct_name,invoice,day', testutil.combine_values( ACCOUNTS, ['FIXME', '', None, *testutil.NON_STRING_METADATA_VALUES], @@ -353,18 +277,13 @@ def test_make_consistent_bad_invoice(acct_name, invoice, day): (acct_name, index * mult, {'invoice': invoice, 'entity': f'BadInvoice{day}'}) for index in range(1, 4) ]) - consistent = dict(accrual.AccrualPostings.make_consistent(data.Posting.from_txn(txn))) + postings = data.Posting.from_txn(txn) + consistent = dict(accrual.AccrualPostings.make_consistent(iter(postings))) assert len(consistent) == 1 - key = next(iter(consistent)) - assert acct_name in key - if invoice: - assert str(invoice) in key - actual = consistent[key] - assert actual + _, actual = consistent.popitem() assert len(actual) == 3 - for act_post, exp_post in zip(actual, txn.postings): - assert act_post.units == exp_post.units - assert act_post.meta.get('invoice') == invoice + for act_post, exp_post in zip(actual, postings): + assert act_post == exp_post def test_make_consistent_across_accounts(): invoice = 'Invoices/CrossAccount.pdf' @@ -376,7 +295,6 @@ def test_make_consistent_across_accounts(): assert len(consistent) == len(ACCOUNTS) for key, posts in consistent.items(): assert len(posts) == 1 - assert posts.account in key def test_make_consistent_both_invoice_and_account(): txn = testutil.Transaction(date=datetime.date(2019, 2, 2), postings=[ @@ -386,7 +304,6 @@ def test_make_consistent_both_invoice_and_account(): assert len(consistent) == len(ACCOUNTS) for key, posts in consistent.items(): assert len(posts) == 1 - assert posts.account in key @pytest.mark.parametrize('acct_name', ACCOUNTS) def test_make_consistent_across_entity(acct_name): @@ -399,10 +316,6 @@ def test_make_consistent_across_entity(acct_name): assert len(consistent) == 3 for key, posts in consistent.items(): assert len(posts) == 1 - entities = posts.entities() - assert next(entities, None) == posts.entity - assert next(entities, None) is None - assert posts.entity in key @pytest.mark.parametrize('acct_name', ACCOUNTS) def test_make_consistent_entity_differs_accrual_payment(acct_name): @@ -440,7 +353,7 @@ def test_make_consistent_by_date_with_exact_payment(): actual = [group for _, group in accrual.AccrualPostings.make_consistent(data.Posting.from_entries(entries))] assert len(actual) == 2 - assert actual[0].is_zero() + assert sum(post.units.number for post in actual[0]) == 0 assert len(actual[1]) == 1 assert actual[1][0].meta.date.day == 3 @@ -470,7 +383,7 @@ def test_make_consistent_by_date_with_overpayment(): actual = [group for _, group in accrual.AccrualPostings.make_consistent(data.Posting.from_entries(entries))] assert len(actual) == 2 - assert actual[0].is_zero() + assert sum(post.units.number for post in actual[0]) == 0 assert len(actual[1]) == 2 assert actual[1][0].meta.date.day == 2 assert actual[1][0].units.number == -25 @@ -658,7 +571,8 @@ def test_outgoing_report_without_rt_id(accrual_postings, caplog): assert caplog.records log = caplog.records[0] assert log.message.startswith( - f"can't generate outgoings report for {invoice} because no RT ticket available:", + f"can't generate outgoings report for 2010-05-15 MatchingProgram {invoice}" + " because no RT ticket available:", ) assert not output.getvalue() @@ -761,7 +675,7 @@ def test_output_payments_when_only_match(arglist, expect_invoice): assert not errors.getvalue() assert retcode == 0 check_output(output, [ - rf'^{re.escape(expect_invoice)}:$', + rf'^EarlyBird {re.escape(expect_invoice)}:$', r' outstanding since ', ])