diff --git a/tests/test_meta_expenseAllocation.py b/tests/test_meta_expenseAllocation.py index d1985d5..2f56438 100644 --- a/tests/test_meta_expenseAllocation.py +++ b/tests/test_meta_expenseAllocation.py @@ -20,24 +20,58 @@ from . import testutil from conservancy_beancount.plugin import meta_expense_allocation -@pytest.mark.parametrize('value,value_ok', [ - ('program', True), - ('administration', True), - ('fundraising', True), - ('invalid', False), - ('', False), -]) -def test_validity_on_postings(value, value_ok): +VALID_VALUES = { + 'program': 'program', + 'administration': 'administration', + 'fundraising': 'fundraising', +} + +INVALID_VALUES = { + 'invalid', + '', +} + +@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) +def test_valid_values_on_postings(src_value, set_value): txn = testutil.Transaction(postings=[ ('Assets:Cash', -25), - ('Expenses:General', 25, {'expenseAllocation': value}), + ('Expenses:General', 25, {'expenseAllocation': src_value}), ]) checker = meta_expense_allocation.MetaExpenseAllocation() errors = checker.check(txn, txn.postings[-1]) - if value_ok: - assert not errors - else: - assert errors + assert not errors + assert txn.postings[-1].meta.get('expenseAllocation') == set_value + +@pytest.mark.parametrize('src_value', INVALID_VALUES) +def test_invalid_values_on_postings(src_value): + txn = testutil.Transaction(postings=[ + ('Assets:Cash', -25), + ('Expenses:General', 25, {'expenseAllocation': src_value}), + ]) + checker = meta_expense_allocation.MetaExpenseAllocation() + errors = checker.check(txn, txn.postings[-1]) + assert errors + +@pytest.mark.parametrize('src_value,set_value', VALID_VALUES.items()) +def test_valid_values_on_transactions(src_value, set_value): + txn = testutil.Transaction(expenseAllocation=src_value, postings=[ + ('Assets:Cash', -25), + ('Expenses:General', 25), + ]) + checker = meta_expense_allocation.MetaExpenseAllocation() + errors = checker.check(txn, txn.postings[-1]) + assert not errors + assert txn.postings[-1].meta.get('expenseAllocation') == set_value + +@pytest.mark.parametrize('src_value', INVALID_VALUES) +def test_invalid_values_on_transactions(src_value): + txn = testutil.Transaction(expenseAllocation=src_value, postings=[ + ('Assets:Cash', -25), + ('Expenses:General', 25), + ]) + checker = meta_expense_allocation.MetaExpenseAllocation() + errors = checker.check(txn, txn.postings[-1]) + assert errors @pytest.mark.parametrize('account', [ 'Accrued:AccountsReceivable',