meta_payable_documentation: Don't check Liabilites:Payable:Vacation.
This commit is contained in:
parent
3dfe266945
commit
ce34554bd4
2 changed files with 32 additions and 49 deletions
|
@ -26,7 +26,7 @@ class MetaPayableDocumentation(core._RequireLinksPostingMetadataHook):
|
||||||
CHECKED_METADATA = ['approval', 'contract']
|
CHECKED_METADATA = ['approval', 'contract']
|
||||||
|
|
||||||
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
|
def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
|
||||||
if post.account.is_under('Liabilities:Payable'):
|
if post.account.is_under('Liabilities:Payable:Accounts'):
|
||||||
return not post.is_credit()
|
return not post.is_credit()
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -23,11 +23,6 @@ from . import testutil
|
||||||
from conservancy_beancount import errors as errormod
|
from conservancy_beancount import errors as errormod
|
||||||
from conservancy_beancount.plugin import meta_payable_documentation
|
from conservancy_beancount.plugin import meta_payable_documentation
|
||||||
|
|
||||||
ACCOUNTS = [
|
|
||||||
'Liabilities:Payable:Accounts',
|
|
||||||
'Liabilities:Payable:Vacation',
|
|
||||||
]
|
|
||||||
|
|
||||||
SUPPORTING_METADATA = [
|
SUPPORTING_METADATA = [
|
||||||
'approval',
|
'approval',
|
||||||
'contract',
|
'contract',
|
||||||
|
@ -41,8 +36,9 @@ NON_SUPPORTING_METADATA = [
|
||||||
'statement',
|
'statement',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
TEST_ACCT = 'Liabilities:Payable:Accounts'
|
||||||
OTHER_ACCT = 'Expenses:Other'
|
OTHER_ACCT = 'Expenses:Other'
|
||||||
MISSING_MSG = f"{{}} missing approval/contract".format
|
MISSING_MSG = f"{TEST_ACCT} missing approval/contract"
|
||||||
|
|
||||||
# for supporting links, use the lists from testutil
|
# for supporting links, use the lists from testutil
|
||||||
|
|
||||||
|
@ -59,14 +55,14 @@ def seed_meta(support_values=testutil.NON_LINK_METADATA_STRINGS, **kwargs):
|
||||||
meta.update(kwargs)
|
meta.update(kwargs)
|
||||||
return meta
|
return meta
|
||||||
|
|
||||||
def wrong_type_message(acct, key, wrong_value):
|
def wrong_type_message(key, wrong_value):
|
||||||
return "{} has wrong type of {}: expected str but is a {}".format(
|
return "{} has wrong type of {}: expected str but is a {}".format(
|
||||||
acct,
|
TEST_ACCT,
|
||||||
key,
|
key,
|
||||||
type(wrong_value).__name__,
|
type(wrong_value).__name__,
|
||||||
)
|
)
|
||||||
|
|
||||||
def check(hook, expected, test_acct, other_acct=OTHER_ACCT, *,
|
def check(hook, expected, test_acct=TEST_ACCT, other_acct=OTHER_ACCT, *,
|
||||||
txn_meta={}, post_meta={}, min_amt=10):
|
txn_meta={}, post_meta={}, min_amt=10):
|
||||||
amount = '{:.02f}'.format(min_amt + random.random() * 100)
|
amount = '{:.02f}'.format(min_amt + random.random() * 100)
|
||||||
txn = testutil.Transaction(**txn_meta, postings=[
|
txn = testutil.Transaction(**txn_meta, postings=[
|
||||||
|
@ -81,89 +77,75 @@ def check(hook, expected, test_acct, other_acct=OTHER_ACCT, *,
|
||||||
else:
|
else:
|
||||||
assert actual == expected
|
assert actual == expected
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
|
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
|
||||||
ACCOUNTS,
|
|
||||||
SUPPORTING_METADATA,
|
SUPPORTING_METADATA,
|
||||||
testutil.LINK_METADATA_STRINGS,
|
testutil.LINK_METADATA_STRINGS,
|
||||||
))
|
))
|
||||||
def test_valid_docs_in_post(hook, acct, support_key, support_value):
|
def test_valid_docs_in_post(hook, support_key, support_value):
|
||||||
meta = seed_meta()
|
meta = seed_meta()
|
||||||
meta[support_key] = support_value
|
meta[support_key] = support_value
|
||||||
check(hook, None, acct, post_meta=meta)
|
check(hook, None, post_meta=meta)
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
|
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
|
||||||
ACCOUNTS,
|
|
||||||
SUPPORTING_METADATA,
|
SUPPORTING_METADATA,
|
||||||
testutil.LINK_METADATA_STRINGS,
|
testutil.LINK_METADATA_STRINGS,
|
||||||
))
|
))
|
||||||
def test_valid_docs_in_txn(hook, acct, support_key, support_value):
|
def test_valid_docs_in_txn(hook, support_key, support_value):
|
||||||
meta = seed_meta()
|
meta = seed_meta()
|
||||||
meta[support_key] = support_value
|
meta[support_key] = support_value
|
||||||
check(hook, None, acct, txn_meta=meta)
|
check(hook, None, txn_meta=meta)
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,meta_type', testutil.combine_values(
|
@pytest.mark.parametrize('meta_type', ['post_meta', 'txn_meta'])
|
||||||
ACCOUNTS,
|
def test_no_valid_docs(hook, meta_type):
|
||||||
['post_meta', 'txn_meta'],
|
|
||||||
))
|
|
||||||
def test_no_valid_docs(hook, acct, meta_type):
|
|
||||||
meta = seed_meta()
|
meta = seed_meta()
|
||||||
meta.update((key, value) for key, value in testutil.combine_values(
|
meta.update((key, value) for key, value in testutil.combine_values(
|
||||||
NON_SUPPORTING_METADATA,
|
NON_SUPPORTING_METADATA,
|
||||||
testutil.LINK_METADATA_STRINGS,
|
testutil.LINK_METADATA_STRINGS,
|
||||||
))
|
))
|
||||||
check(hook, {MISSING_MSG(acct)}, acct, **{meta_type: meta})
|
check(hook, {MISSING_MSG}, **{meta_type: meta})
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,meta_type', testutil.combine_values(
|
@pytest.mark.parametrize('meta_type', ['post_meta', 'txn_meta'])
|
||||||
ACCOUNTS,
|
def test_docs_all_bad_type(hook, meta_type):
|
||||||
['post_meta', 'txn_meta'],
|
|
||||||
))
|
|
||||||
def test_docs_all_bad_type(hook, acct, meta_type):
|
|
||||||
meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
|
meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
|
||||||
expected = {
|
expected = {
|
||||||
wrong_type_message(acct, key, value)
|
wrong_type_message(key, value)
|
||||||
for key, value in meta.items()
|
for key, value in meta.items()
|
||||||
}
|
}
|
||||||
expected.add(MISSING_MSG(acct))
|
expected.add(MISSING_MSG)
|
||||||
check(hook, expected, acct, **{meta_type: meta})
|
check(hook, expected, **{meta_type: meta})
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
|
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
|
||||||
ACCOUNTS,
|
|
||||||
SUPPORTING_METADATA,
|
SUPPORTING_METADATA,
|
||||||
testutil.LINK_METADATA_STRINGS,
|
testutil.LINK_METADATA_STRINGS,
|
||||||
))
|
))
|
||||||
def test_type_errors_reported_with_valid_post_docs(hook, acct, support_key, support_value):
|
def test_type_errors_reported_with_valid_post_docs(hook, support_key, support_value):
|
||||||
meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
|
meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
|
||||||
meta[support_key] = support_value
|
meta[support_key] = support_value
|
||||||
expected = {
|
expected = {
|
||||||
wrong_type_message(acct, key, value)
|
wrong_type_message(key, value)
|
||||||
for key, value in meta.items()
|
for key, value in meta.items()
|
||||||
if key != support_key
|
if key != support_key
|
||||||
}
|
}
|
||||||
check(hook, expected, acct, post_meta=meta)
|
check(hook, expected, post_meta=meta)
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,support_key,support_value', testutil.combine_values(
|
@pytest.mark.parametrize('support_key,support_value', testutil.combine_values(
|
||||||
ACCOUNTS,
|
|
||||||
SUPPORTING_METADATA,
|
SUPPORTING_METADATA,
|
||||||
testutil.LINK_METADATA_STRINGS,
|
testutil.LINK_METADATA_STRINGS,
|
||||||
))
|
))
|
||||||
def test_type_errors_reported_with_valid_txn_docs(hook, acct, support_key, support_value):
|
def test_type_errors_reported_with_valid_txn_docs(hook, support_key, support_value):
|
||||||
meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
|
meta = seed_meta(testutil.NON_STRING_METADATA_VALUES)
|
||||||
meta[support_key] = support_value
|
meta[support_key] = support_value
|
||||||
expected = {
|
expected = {
|
||||||
wrong_type_message(acct, key, value)
|
wrong_type_message(key, value)
|
||||||
for key, value in meta.items()
|
for key, value in meta.items()
|
||||||
if key != support_key
|
if key != support_key
|
||||||
}
|
}
|
||||||
check(hook, expected, acct, txn_meta=meta)
|
check(hook, expected, txn_meta=meta)
|
||||||
|
|
||||||
@pytest.mark.parametrize('acct,other_acct', testutil.combine_values(
|
def test_paid_accts_not_checked(hook):
|
||||||
ACCOUNTS,
|
|
||||||
['Assets:Checking', 'Liabilities:CreditCard'],
|
|
||||||
))
|
|
||||||
def test_paid_accts_not_checked(hook, acct, other_acct):
|
|
||||||
txn = testutil.Transaction(postings=[
|
txn = testutil.Transaction(postings=[
|
||||||
(acct, 250),
|
(TEST_ACCT, 250),
|
||||||
(other_acct, -250),
|
(OTHER_ACCT, -250),
|
||||||
])
|
])
|
||||||
assert not list(hook.run(txn))
|
assert not list(hook.run(txn))
|
||||||
|
|
||||||
|
@ -175,6 +157,7 @@ def test_paid_accts_not_checked(hook, acct, other_acct):
|
||||||
'Expenses:BankingFees',
|
'Expenses:BankingFees',
|
||||||
'Income:Donations',
|
'Income:Donations',
|
||||||
'Liabilities:CreditCard',
|
'Liabilities:CreditCard',
|
||||||
|
'Liabilities:Payable:Vacation',
|
||||||
'Liabilities:UnearnedIncome:Donations',
|
'Liabilities:UnearnedIncome:Donations',
|
||||||
])
|
])
|
||||||
def test_does_not_apply_to_other_accounts(hook, account):
|
def test_does_not_apply_to_other_accounts(hook, account):
|
||||||
|
|
Loading…
Reference in a new issue