Changeset - 3dfe2669455b
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-04-07 19:31:58
brettcsmith@brettcsmith.org
meta_payable_documentation: Bugfix which metadata we're checking.

Checking approval/contract was in the original specification,
looking at invoice instead of approval was a pure brain fart.
2 files changed with 4 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/plugin/meta_payable_documentation.py
Show inline comments
 
"""meta_payable_documentation - Validate payables have supporting docs"""
 
# Copyright © 2020  Brett Smith
 
#
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU Affero General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU Affero General Public License for more details.
 
#
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 

	
 
from . import core
 
from .. import config as configmod
 
from .. import data
 
from .. import errors as errormod
 
from ..beancount_types import (
 
    Transaction,
 
)
 

	
 
class MetaPayableDocumentation(core._RequireLinksPostingMetadataHook):
 
    CHECKED_METADATA = ['invoice', 'contract']
 
    CHECKED_METADATA = ['approval', 'contract']
 

	
 
    def _run_on_post(self, txn: Transaction, post: data.Posting) -> bool:
 
        if post.account.is_under('Liabilities:Payable'):
 
            return not post.is_credit()
 
        else:
 
            return False
tests/test_meta_payable_documentation.py
Show inline comments
 
"""Test metadata for payables includes supporting documentation"""
 
# Copyright © 2020  Brett Smith
 
#
 
# This program is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU Affero General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU Affero General Public License for more details.
 
#
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 

	
 
import random
 

	
 
import pytest
 

	
 
from . import testutil
 

	
 
from conservancy_beancount import errors as errormod
 
from conservancy_beancount.plugin import meta_payable_documentation
 

	
 
ACCOUNTS = [
 
    'Liabilities:Payable:Accounts',
 
    'Liabilities:Payable:Vacation',
 
]
 

	
 
SUPPORTING_METADATA = [
 
    'approval',
 
    'contract',
 
    'invoice',
 
]
 

	
 
NON_SUPPORTING_METADATA = [
 
    'approval',
 
    'check',
 
    'invoice',
 
    'purchase-order',
 
    'receipt',
 
    'statement',
 
]
 

	
 
OTHER_ACCT = 'Expenses:Other'
 
MISSING_MSG = f"{{}} missing invoice/contract".format
 
MISSING_MSG = f"{{}} missing approval/contract".format
 

	
 
# for supporting links, use the lists from testutil
 

	
 
@pytest.fixture(scope='module')
 
def hook():
 
    config = testutil.TestConfig(rt_client=testutil.RTClient())
 
    return meta_payable_documentation.MetaPayableDocumentation(config)
 

	
 
def seed_meta(support_values=testutil.NON_LINK_METADATA_STRINGS, **kwargs):
 
    meta = dict(testutil.combine_values(
 
        SUPPORTING_METADATA,
 
        support_values,
 
    ))
 
    meta.update(kwargs)
 
    return meta
 

	
 
def wrong_type_message(acct, key, wrong_value):
 
    return  "{} has wrong type of {}: expected str but is a {}".format(
 
        acct,
 
        key,
 
        type(wrong_value).__name__,
 
    )
 

	
 
def check(hook, expected, test_acct, other_acct=OTHER_ACCT, *,
 
          txn_meta={}, post_meta={}, min_amt=10):
 
    amount = '{:.02f}'.format(min_amt + random.random() * 100)
 
    txn = testutil.Transaction(**txn_meta, postings=[
 
        (test_acct, f'-{amount}', post_meta),
 
        (other_acct, amount),
 
    ])
 
    actual = {error.message for error in hook.run(txn)}
 
    if expected is None:
0 comments (0 inline, 0 general)