Files
@ 5d45171ed7c4
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_meta_repo_links.py - annotation
5d45171ed7c4
4.7 KiB
text/x-python
reconcile: Add statement total and cleared total.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 5c6043311b8c 5c6043311b8c 1b7fdf4f3b00 5c6043311b8c 1b7fdf4f3b00 1b7fdf4f3b00 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 4a28596db267 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 4a28596db267 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c da056917bfa4 da056917bfa4 da056917bfa4 da056917bfa4 da056917bfa4 da056917bfa4 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 536b50b478d8 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 46cfc558ecbb 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c 5c6043311b8c | """Test link checker for repository documents"""
# Copyright © 2020 Brett Smith
# License: AGPLv3-or-later WITH Beancount-Plugin-Additional-Permission-1.0
#
# Full copyright and licensing details can be found at toplevel file
# LICENSE.txt in the repository.
import itertools
from pathlib import Path
import pytest
from . import testutil
from conservancy_beancount import errors as errormod
from conservancy_beancount.plugin import meta_repo_links
METADATA_KEYS = [
'approval',
'bank-statement',
'check',
'contract',
'invoice',
'purchase-order',
'receipt',
'statement',
'tax-statement',
]
GOOD_LINKS = [Path(s) for s in [
'Projects/project-data.yml',
'Projects/project-list.yml',
]]
BAD_LINKS = [Path(s) for s in [
'NonexistentDirectory/NonexistentFile1.txt',
'NonexistentDirectory/NonexistentFile2.txt',
'egproto:',
'egproto:123',
'egproto:123/456',
'egproto:foo'
'egproto:/foo/bar',
';egproto::',
]]
NOT_FOUND_MSG = '{} not found in repository: {}'.format
def build_meta(keys=None, *sources):
if keys is None:
keys = iter(METADATA_KEYS)
sources = (itertools.cycle(src) for src in sources)
return {key: ' '.join(str(x) for x in rest)
for key, *rest in zip(keys, *sources)}
@pytest.fixture(scope='module')
def hook():
config = testutil.TestConfig(repo_path='repository')
return meta_repo_links.MetaRepoLinks(config)
def test_error_with_no_repository():
config = testutil.TestConfig(repo_path=None)
with pytest.raises(errormod.ConfigurationError):
meta_repo_links.MetaRepoLinks(config)
def test_good_txn_links(hook):
meta = build_meta(None, GOOD_LINKS)
txn = testutil.Transaction(**meta, postings=[
('Income:Donations', -5),
('Assets:Cash', 5),
])
assert not list(hook.run(txn))
def test_good_post_links(hook):
meta = build_meta(None, GOOD_LINKS)
txn = testutil.Transaction(postings=[
('Income:Donations', -5, meta),
('Assets:Cash', 5),
])
assert not list(hook.run(txn))
def test_bad_txn_links(hook):
meta = build_meta(None, BAD_LINKS)
txn = testutil.Transaction(**meta, postings=[
('Income:Donations', -5),
('Assets:Cash', 5),
])
expected = {NOT_FOUND_MSG(key, value) for key, value in meta.items()}
actual = {error.message for error in hook.run(txn)}
assert expected == actual
def test_bad_post_links(hook):
meta = build_meta(None, BAD_LINKS)
txn = testutil.Transaction(postings=[
('Income:Donations', -5, meta.copy()),
('Assets:Cash', 5),
])
expected = {NOT_FOUND_MSG(key, value) for key, value in meta.items()}
actual = {error.message for error in hook.run(txn)}
assert expected == actual
def test_flagged_txn_not_checked(hook):
keys = iter(METADATA_KEYS)
txn_meta = build_meta(keys, BAD_LINKS)
txn_meta['flag'] = '!'
txn = testutil.Transaction(**txn_meta, postings=[
('Income:Donations', -5, build_meta(keys, BAD_LINKS)),
('Assets:Checking', 5, build_meta(keys, BAD_LINKS)),
])
assert not list(hook.run(txn))
@pytest.mark.parametrize('value', testutil.NON_STRING_METADATA_VALUES)
def test_bad_metadata_type(hook, value):
txn = testutil.Transaction(**{'check': value}, postings=[
('Income:Donations', -5),
('Assets:Cash', 5),
])
expected = {'transaction has wrong type of check: expected str but is a {}'.format(
type(value).__name__,
)}
actual = {error.message for error in hook.run(txn)}
assert expected == actual
@pytest.mark.parametrize('ext_doc', [
'rt:123',
'rt:456/789',
'rt://ticket/23',
'rt://ticket/34/attachments/567890',
])
def test_docs_outside_repository_not_checked(hook, ext_doc):
txn = testutil.Transaction(
receipt='{} {} {}'.format(GOOD_LINKS[0], ext_doc, BAD_LINKS[1]),
postings=[
('Income:Donations', -5),
('Assets:Cash', 5),
])
expected = {NOT_FOUND_MSG('receipt', BAD_LINKS[1])}
actual = {error.message for error in hook.run(txn)}
assert expected == actual
def test_mixed_results(hook):
txn = testutil.Transaction(
approval='{} {}'.format(*GOOD_LINKS),
contract='{} {}'.format(BAD_LINKS[0], GOOD_LINKS[1]),
postings=[
('Income:Donations', -5, {'invoice': '{} {}'.format(*BAD_LINKS)}),
('Assets:Cash', 5, {'statement': '{} {}'.format(GOOD_LINKS[0], BAD_LINKS[1])}),
])
expected = {
NOT_FOUND_MSG('contract', BAD_LINKS[0]),
NOT_FOUND_MSG('invoice', BAD_LINKS[0]),
NOT_FOUND_MSG('invoice', BAD_LINKS[1]),
NOT_FOUND_MSG('statement', BAD_LINKS[1]),
}
actual = {error.message for error in hook.run(txn)}
assert expected == actual
|