expenseAllocation: Test setting at transaction level.

This commit is contained in:
Brett Smith 2020-03-05 12:21:20 -05:00
parent d436a388f7
commit 2ac434b616

View file

@ -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',