tests: Refactor accrual tests.
Preparation for adding the aging report.
This commit is contained in:
parent
eaae2b4a44
commit
9223940213
1 changed files with 23 additions and 36 deletions
|
@ -93,6 +93,13 @@ def check_link_regexp(regexp, match_s, first_link_only=False):
|
||||||
else:
|
else:
|
||||||
assert end_match
|
assert end_match
|
||||||
|
|
||||||
|
def relate_accruals_by_meta(postings, value, key='invoice'):
|
||||||
|
return core.RelatedPostings(
|
||||||
|
post for post in postings
|
||||||
|
if post.meta.get(key) == value
|
||||||
|
and post.account.is_under('Assets:Receivable', 'Liabilities:Payable')
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.mark.parametrize('link_fmt', [
|
@pytest.mark.parametrize('link_fmt', [
|
||||||
'{}',
|
'{}',
|
||||||
'rt:{}',
|
'rt:{}',
|
||||||
|
@ -246,6 +253,17 @@ def check_output(output, expect_patterns):
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
testutil.check_lines_match(iter(output), expect_patterns)
|
testutil.check_lines_match(iter(output), expect_patterns)
|
||||||
|
|
||||||
|
def run_outgoing(invoice, postings, rt_client=None):
|
||||||
|
if rt_client is None:
|
||||||
|
rt_client = RTClient()
|
||||||
|
if not isinstance(postings, core.RelatedPostings):
|
||||||
|
postings = relate_accruals_by_meta(postings, invoice)
|
||||||
|
output = io.StringIO()
|
||||||
|
errors = io.StringIO()
|
||||||
|
rt_cache = rtutil.RT(rt_client)
|
||||||
|
accrual.outgoing_report({invoice: postings}, output, errors, rt_client, rt_cache)
|
||||||
|
return output, errors
|
||||||
|
|
||||||
@pytest.mark.parametrize('invoice,expected', [
|
@pytest.mark.parametrize('invoice,expected', [
|
||||||
('rt:505/5050', "Zero balance outstanding since 2020-05-05"),
|
('rt:505/5050', "Zero balance outstanding since 2020-05-05"),
|
||||||
('rt:510/5100', "Zero balance outstanding since 2020-05-10"),
|
('rt:510/5100', "Zero balance outstanding since 2020-05-10"),
|
||||||
|
@ -253,29 +271,15 @@ def check_output(output, expect_patterns):
|
||||||
('rt://ticket/515/attachments/5150', "1,500.00 USD outstanding since 2020-05-15",),
|
('rt://ticket/515/attachments/5150', "1,500.00 USD outstanding since 2020-05-15",),
|
||||||
])
|
])
|
||||||
def test_balance_report(accrual_postings, invoice, expected):
|
def test_balance_report(accrual_postings, invoice, expected):
|
||||||
related = core.RelatedPostings(
|
related = relate_accruals_by_meta(accrual_postings, invoice)
|
||||||
post for post in accrual_postings
|
|
||||||
if post.meta.get('invoice') == invoice
|
|
||||||
and post.account.is_under('Assets:Receivable', 'Liabilities:Payable')
|
|
||||||
)
|
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
accrual.balance_report({invoice: related}, output)
|
accrual.balance_report({invoice: related}, output)
|
||||||
check_output(output, [invoice, expected])
|
check_output(output, [invoice, expected])
|
||||||
|
|
||||||
def test_outgoing_report(accrual_postings):
|
def test_outgoing_report(accrual_postings):
|
||||||
invoice = 'rt:510/6100'
|
invoice = 'rt:510/6100'
|
||||||
related = core.RelatedPostings(
|
output, errors = run_outgoing(invoice, accrual_postings)
|
||||||
post for post in accrual_postings
|
rt_url = RTClient.DEFAULT_URL[:-9]
|
||||||
if post.meta.get('invoice') == invoice
|
|
||||||
and post.account.is_under('Assets:Receivable', 'Liabilities:Payable')
|
|
||||||
)
|
|
||||||
output = io.StringIO()
|
|
||||||
errors = io.StringIO()
|
|
||||||
rt_client = RTClient()
|
|
||||||
rt_cache = rtutil.RT(rt_client)
|
|
||||||
accrual.outgoing_report({invoice: related}, output, errors, rt_client, rt_cache)
|
|
||||||
assert not errors.getvalue()
|
|
||||||
rt_url = rt_client.DEFAULT_URL[:-9]
|
|
||||||
rt_id_url = rf'\b{re.escape(f"{rt_url}Ticket/Display.html?id=510")}\b'
|
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'
|
contract_url = rf'\b{re.escape(f"{rt_url}Ticket/Attachment/4000/4000/contract.pdf")}\b'
|
||||||
print(output.getvalue())
|
print(output.getvalue())
|
||||||
|
@ -299,16 +303,8 @@ def test_outgoing_report(accrual_postings):
|
||||||
|
|
||||||
def test_outgoing_report_custom_field_fallbacks(accrual_postings):
|
def test_outgoing_report_custom_field_fallbacks(accrual_postings):
|
||||||
invoice = 'rt:510/6100'
|
invoice = 'rt:510/6100'
|
||||||
related = core.RelatedPostings(
|
|
||||||
post for post in accrual_postings
|
|
||||||
if post.meta.get('invoice') == invoice
|
|
||||||
and post.account.is_under('Assets:Receivable', 'Liabilities:Payable')
|
|
||||||
)
|
|
||||||
output = io.StringIO()
|
|
||||||
errors = io.StringIO()
|
|
||||||
rt_client = RTClient(want_cfs=False)
|
rt_client = RTClient(want_cfs=False)
|
||||||
rt_cache = rtutil.RT(rt_client)
|
output, errors = run_outgoing(invoice, accrual_postings, rt_client)
|
||||||
accrual.outgoing_report({invoice: related}, output, errors, rt_client, rt_cache)
|
|
||||||
assert not errors.getvalue()
|
assert not errors.getvalue()
|
||||||
check_output(output, [
|
check_output(output, [
|
||||||
r'^PAYMENT FOR APPROVAL:$',
|
r'^PAYMENT FOR APPROVAL:$',
|
||||||
|
@ -319,16 +315,7 @@ def test_outgoing_report_custom_field_fallbacks(accrual_postings):
|
||||||
|
|
||||||
def test_outgoing_report_fx_amounts(accrual_postings):
|
def test_outgoing_report_fx_amounts(accrual_postings):
|
||||||
invoice = 'rt:520/5200'
|
invoice = 'rt:520/5200'
|
||||||
related = core.RelatedPostings(
|
output, errors = run_outgoing(invoice, accrual_postings)
|
||||||
post for post in accrual_postings
|
|
||||||
if post.meta.get('invoice') == invoice
|
|
||||||
and post.account.is_under('Assets:Receivable', 'Liabilities:Payable')
|
|
||||||
)
|
|
||||||
output = io.StringIO()
|
|
||||||
errors = io.StringIO()
|
|
||||||
rt_client = RTClient()
|
|
||||||
rt_cache = rtutil.RT(rt_client)
|
|
||||||
accrual.outgoing_report({invoice: related}, output, errors, rt_client, rt_cache)
|
|
||||||
assert not errors.getvalue()
|
assert not errors.getvalue()
|
||||||
check_output(output, [
|
check_output(output, [
|
||||||
r'^PAYMENT FOR APPROVAL:$',
|
r'^PAYMENT FOR APPROVAL:$',
|
||||||
|
|
Loading…
Reference in a new issue