expenseAllocation: Test setting at transaction level.
This commit is contained in:
parent
d436a388f7
commit
2ac434b616
1 changed files with 47 additions and 13 deletions
|
@ -20,24 +20,58 @@ from . import testutil
|
||||||
|
|
||||||
from conservancy_beancount.plugin import meta_expense_allocation
|
from conservancy_beancount.plugin import meta_expense_allocation
|
||||||
|
|
||||||
@pytest.mark.parametrize('value,value_ok', [
|
VALID_VALUES = {
|
||||||
('program', True),
|
'program': 'program',
|
||||||
('administration', True),
|
'administration': 'administration',
|
||||||
('fundraising', True),
|
'fundraising': 'fundraising',
|
||||||
('invalid', False),
|
}
|
||||||
('', False),
|
|
||||||
])
|
INVALID_VALUES = {
|
||||||
def test_validity_on_postings(value, value_ok):
|
'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=[
|
txn = testutil.Transaction(postings=[
|
||||||
('Assets:Cash', -25),
|
('Assets:Cash', -25),
|
||||||
('Expenses:General', 25, {'expenseAllocation': value}),
|
('Expenses:General', 25, {'expenseAllocation': src_value}),
|
||||||
])
|
])
|
||||||
checker = meta_expense_allocation.MetaExpenseAllocation()
|
checker = meta_expense_allocation.MetaExpenseAllocation()
|
||||||
errors = checker.check(txn, txn.postings[-1])
|
errors = checker.check(txn, txn.postings[-1])
|
||||||
if value_ok:
|
assert not errors
|
||||||
assert not errors
|
assert txn.postings[-1].meta.get('expenseAllocation') == set_value
|
||||||
else:
|
|
||||||
assert errors
|
@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', [
|
@pytest.mark.parametrize('account', [
|
||||||
'Accrued:AccountsReceivable',
|
'Accrued:AccountsReceivable',
|
||||||
|
|
Loading…
Reference in a new issue