tests: Generate configuration in accrual-report tests.

Usually reduces the amount of testing boilerplate.
This commit is contained in:
Brett Smith 2020-05-23 08:48:41 -04:00
parent 396173b55d
commit 13df0390a1

View file

@ -346,7 +346,12 @@ def test_outgoing_report_custom_field_fallbacks(accrual_postings):
r'^PAYMENT METHOD:\s*$', r'^PAYMENT METHOD:\s*$',
]) ])
def run_main(arglist, config): def run_main(arglist, config=None):
if config is None:
config = testutil.TestConfig(
books_path=testutil.test_path('books/accruals.beancount'),
rt_client=RTClient(),
)
output = io.StringIO() output = io.StringIO()
errors = io.StringIO() errors = io.StringIO()
retcode = accrual.main(arglist, output, errors, config) retcode = accrual.main(arglist, output, errors, config)
@ -366,15 +371,10 @@ def check_main_fails(arglist, config, error_flags, error_patterns):
['entity=Lawyer'], ['entity=Lawyer'],
]) ])
def test_main_outgoing_report(arglist): def test_main_outgoing_report(arglist):
rt_client = RTClient() retcode, output, errors = run_main(arglist)
config = testutil.TestConfig(
books_path=testutil.test_path('books/accruals.beancount'),
rt_client=rt_client,
)
retcode, output, errors = run_main(arglist, config)
assert not errors.getvalue() assert not errors.getvalue()
assert retcode == 0 assert retcode == 0
rt_url = rt_client.DEFAULT_URL[:-9] rt_url = RTClient.DEFAULT_URL[:-9]
rt_id_url = re.escape(f'<{rt_url}Ticket/Display.html?id=510>') 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>') contract_url = re.escape(f'<{rt_url}Ticket/Attachment/4000/4000/contract.pdf>')
check_output(output, [ check_output(output, [
@ -391,10 +391,7 @@ def test_main_outgoing_report(arglist):
['entity=DonorB'], ['entity=DonorB'],
]) ])
def test_main_balance_report(arglist): def test_main_balance_report(arglist):
config = testutil.TestConfig( retcode, output, errors = run_main(arglist)
books_path=testutil.test_path('books/accruals.beancount'),
)
retcode, output, errors = run_main(arglist, config)
assert not errors.getvalue() assert not errors.getvalue()
assert retcode == 0 assert retcode == 0
check_output(output, [ check_output(output, [
@ -413,10 +410,7 @@ def test_main_no_books():
['entity=NonExistent'], ['entity=NonExistent'],
]) ])
def test_main_no_matches(arglist): def test_main_no_matches(arglist):
config = testutil.TestConfig( check_main_fails(arglist, None, 8, [
books_path=testutil.test_path('books/accruals.beancount'),
)
check_main_fails(arglist, config, 8, [
r'^warning: no matching entries found to report$', r'^warning: no matching entries found to report$',
]) ])