From 3a0b85c8f0d2940e5d71128646b796d5500a4e44 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 28 May 2020 17:03:04 -0400 Subject: [PATCH] tests: Add test for trying to make outgoing report without rt-id. Changes to other test cases are to make them *not* trip up this error after adding it to the books. --- tests/books/accruals.beancount | 3 +-- tests/test_reports_accrual.py | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/books/accruals.beancount b/tests/books/accruals.beancount index 01f8ee2..5be8a02 100644 --- a/tests/books/accruals.beancount +++ b/tests/books/accruals.beancount @@ -38,8 +38,7 @@ Expenses:Services:Legal 200.00 USD Liabilities:Payable:Accounts -200.00 USD -2020-05-15 * "DonorB" "Donation pledge" - rt-id: "rt://ticket/515" +2020-05-15 * "MatchingProgram" "May matched donations" invoice: "rt://ticket/515/attachments/5150" approval: "rt://ticket/515/attachments/5140" Income:Donations -1500.00 USD diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 2406058..0a2d6dd 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -18,6 +18,7 @@ import collections import copy import io import itertools +import logging import re import pytest @@ -161,8 +162,8 @@ def test_search_term_parse_regexp_escaping(search, unmatched): ([], ACCRUALS_COUNT, lambda post: post.account.is_under( 'Assets:Receivable:', 'Liabilities:Payable:', )), - ([('invoice', '^rt:505/5050$')], 2, lambda post: post.meta['entity'] == 'DonorA'), - ([('rt-id', r'^rt:\D+515$')], 1, lambda post: post.meta['entity'] == 'DonorB'), + ([('rt-id', '^rt:505$')], 2, lambda post: post.meta['entity'] == 'DonorA'), + ([('invoice', r'^rt:\D+515/')], 1, lambda post: post.meta['entity'] == 'MatchingProgram'), ([('entity', '^Lawyer$')], 3, lambda post: post.meta['rt-id'] == 'rt:510'), ([('entity', '^Lawyer$'), ('contract', '^rt:510/')], 2, lambda post: post.meta['invoice'].startswith('rt:510/')), @@ -324,6 +325,16 @@ def test_outgoing_report_fx_amounts(accrual_postings, caplog): r'^TOTAL TO PAY: 1,000\.00 EUR \(\$1,100.00\)$', ]) +def test_outgoing_report_without_rt_id(accrual_postings, caplog): + invoice = 'rt://ticket/515/attachments/5150' + output = run_outgoing(invoice, accrual_postings) + assert caplog.records + log = caplog.records[0] + assert log.message.startswith( + f"can't generate outgoings report for {invoice} because no RT ticket available:", + ) + assert not output.getvalue() + def run_main(arglist, config=None): if config is None: config = testutil.TestConfig( @@ -343,9 +354,8 @@ def check_main_fails(arglist, config, error_flags, error_patterns): assert not output.getvalue() @pytest.mark.parametrize('arglist', [ - ['--report-type=balance'], - ['--report-type=outgoing'], - ['entity=EarlyBird'], + ['--report-type=balance', 'entity=EarlyBird'], + ['--report-type=outgoing', 'entity=EarlyBird'], ]) def test_output_excludes_payments(arglist): retcode, output, errors = run_main(arglist) @@ -369,7 +379,6 @@ def test_output_payments_when_only_match(arglist, expect_invoice): ]) @pytest.mark.parametrize('arglist', [ - ['--report-type=outgoing'], ['510'], ['510/6100'], ['entity=Lawyer'], @@ -390,9 +399,8 @@ def test_main_outgoing_report(arglist): @pytest.mark.parametrize('arglist', [ ['-t', 'balance'], - ['515'], ['515/5150'], - ['entity=DonorB'], + ['entity=MatchingProgram'], ]) def test_main_balance_report(arglist): retcode, output, errors = run_main(arglist)