diff --git a/tests/test_reports_accrual.py b/tests/test_reports_accrual.py index 2c5d3af9c5818816e1ade0cc3b1718d86b1609b2..6b7ab910cc2f1bffd3c2f9773fc096210b52f034 100644 --- a/tests/test_reports_accrual.py +++ b/tests/test_reports_accrual.py @@ -106,7 +106,8 @@ class AgingRow(NamedTuple): AGING_AP = [ AgingRow.make_simple('2010-03-06', 'EarlyBird', -125, 'rt:44/440'), AgingRow.make_simple('2010-03-30', 'EarlyBird', 75, 'rt:490/4900'), - AgingRow.make_simple('2010-04-30', 'Vendor', 200, 'FIXME'), + AgingRow.make_simple('2010-04-25', 'Vendor', 200, 'FIXME'), + AgingRow.make_simple('2010-04-30', 'Vendor', 220, 'rt:310/3120'), AgingRow.make_simple('2010-06-10', 'Lawyer', 280, 'rt:510/6100'), AgingRow.make_simple('2010-06-18', 'EuroGov', 1100, 'rt:520/5200', orig_amount=[testutil.Amount(1000, 'EUR')]), @@ -128,6 +129,10 @@ class RTClient(testutil.RTClient): '44': [ ('440', 'invoice feb.csv', 'text/csv', '40.4k'), ], + '310': [ + ('3100', 'VendorContract.pdf', 'application/pdf', '1.7m'), + ('3120', 'VendorInvoiceB.pdf', 'application/pdf', '1.8m'), + ], '490': [], '505': [], '510': [ @@ -417,14 +422,14 @@ def check_output(output, expect_patterns): output.seek(0) testutil.check_lines_match(iter(output), expect_patterns) -def run_outgoing(invoice, postings, rt_client=None): +def run_outgoing(rt_id, postings, rt_client=None): if rt_client is None: rt_client = RTClient() if not isinstance(postings, core.RelatedPostings): - postings = accruals_by_meta(postings, invoice, wrap_type=accrual.AccrualPostings) + postings = accruals_by_meta(postings, rt_id, 'rt-id', wrap_type=accrual.AccrualPostings) output = io.StringIO() report = accrual.OutgoingReport(rt_client, output) - report.run({invoice: postings}) + report.run({rt_id: postings}) return output @pytest.mark.parametrize('invoice,expected', [ @@ -442,8 +447,7 @@ def test_balance_report(accrual_postings, invoice, expected, caplog): check_output(output, [invoice, expected]) def test_outgoing_report(accrual_postings, caplog): - invoice = 'rt:510/6100' - output = run_outgoing(invoice, accrual_postings) + output = run_outgoing('rt:510', accrual_postings) rt_url = RTClient.DEFAULT_URL[:-9] rt_id_url = rf'\b{re.escape(f"{rt_url}Ticket/Display.html?id=510")}\b' contract_url = rf'\b{re.escape(f"{rt_url}Ticket/Attachment/4000/4000/contract.pdf")}\b' @@ -467,9 +471,8 @@ def test_outgoing_report(accrual_postings, caplog): ]) def test_outgoing_report_custom_field_fallbacks(accrual_postings, caplog): - invoice = 'rt:510/6100' rt_client = RTClient(want_cfs=False) - output = run_outgoing(invoice, accrual_postings, rt_client) + output = run_outgoing('rt:510', accrual_postings, rt_client) assert not caplog.records check_output(output, [ r'^PAYMENT FOR APPROVAL:$', @@ -479,8 +482,7 @@ def test_outgoing_report_custom_field_fallbacks(accrual_postings, caplog): ]) def test_outgoing_report_fx_amounts(accrual_postings, caplog): - invoice = 'rt:520/5200' - output = run_outgoing(invoice, accrual_postings) + output = run_outgoing('rt:520 rt:525', accrual_postings) assert not caplog.records check_output(output, [ r'^PAYMENT FOR APPROVAL:$', @@ -488,9 +490,21 @@ def test_outgoing_report_fx_amounts(accrual_postings, caplog): r'^TOTAL TO PAY: 1,000\.00 EUR \(\$1,100.00\)$', ]) +def test_outgoing_report_multi_invoice(accrual_postings, caplog): + output = run_outgoing('rt:310', accrual_postings) + assert not caplog.records + check_output(output, [ + r'^PAYMENT FOR APPROVAL:$', + r'^REQUESTOR: Mx\. 310 $', + r'^TOTAL TO PAY: \$420.00$', + ]) + def test_outgoing_report_without_rt_id(accrual_postings, caplog): invoice = 'rt://ticket/515/attachments/5150' - output = run_outgoing(invoice, accrual_postings) + related = accruals_by_meta( + accrual_postings, invoice, wrap_type=accrual.AccrualPostings, + ) + output = run_outgoing(None, related) assert caplog.records log = caplog.records[0] assert log.message.startswith( @@ -524,8 +538,8 @@ def test_aging_report(accrual_postings): # Both these dates are chosen for their off-by-one potential: # the first is exactly 30 days after the 2010-06-10 payable; # the second is exactly 60 days after the 2010-05-15 receivable. - (datetime.date(2010, 7, 10), 1, 4), - (datetime.date(2010, 7, 14), 2, 4), + (datetime.date(2010, 7, 10), 1, 5), + (datetime.date(2010, 7, 14), 2, 5), ]) def test_aging_report_date_cutoffs(accrual_postings, date, recv_end, pay_end): expect_recv = AGING_AR[:recv_end] @@ -606,23 +620,23 @@ def test_output_payments_when_only_match(arglist, expect_invoice): r' outstanding since ', ]) -@pytest.mark.parametrize('arglist', [ - ['510'], - ['510/6100'], - ['entity=Lawyer'], +@pytest.mark.parametrize('arglist,expect_amount', [ + (['310'], 420), + (['310/3120'], 220), + (['entity=Vendor'], 420), ]) -def test_main_outgoing_report(arglist): +def test_main_outgoing_report(arglist, expect_amount): retcode, output, errors = run_main(arglist) assert not errors.getvalue() assert retcode == 0 rt_url = RTClient.DEFAULT_URL[:-9] - rt_id_url = re.escape(f'<{rt_url}Ticket/Display.html?id=510>') - contract_url = re.escape(f'<{rt_url}Ticket/Attachment/4000/4000/contract.pdf>') + rt_id_url = re.escape(f'<{rt_url}Ticket/Display.html?id=310>') + contract_url = re.escape(f'<{rt_url}Ticket/Attachment/3120/3120/VendorContract.pdf>') check_output(output, [ - r'^REQUESTOR: Mx\. 510 $', - r'^TOTAL TO PAY: \$280\.00$', - r'^\s*2010-06-12\s', - r'^\s+Expenses:FilingFees\s+60\.00 USD$', + r'^REQUESTOR: Mx\. 310 $', + rf'^TOTAL TO PAY: \${expect_amount}\.00$', + r'^\s*2010-04-30\s', + r'^\s+Expenses:Travel\s+220 USD$', ]) @pytest.mark.parametrize('arglist', [