Files
@ 8a4fb5758cb8
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_meta_payroll_type.py - annotation
8a4fb5758cb8
4.9 KiB
text/x-python
statement_reconciler: Fix TypeError in Chase reconciler
There was an incorrect call to replace().
There was an incorrect call to replace().
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 | 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 83e6e80bb89c 83e6e80bb89c 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb 250b14954ffb | """test_meta_payroll_type.py - Unit tests for payroll-type validation hook"""
# Copyright © 2021 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 typing
import pytest
from . import testutil
from conservancy_beancount.plugin import meta_payroll_type
class HookData(typing.NamedTuple):
account: str
hook_type: typing.Type
valid_values: typing.Set[str]
invalid_values: typing.Set[str]
@classmethod
def from_hook(cls, hook, *valid_values):
return cls(hook.ACCOUNT, hook, set(valid_values), set())
@classmethod
def set_invalid_values(cls, datas):
all_values = frozenset(v for d in datas for v in d.valid_values)
for data in datas:
data.invalid_values.update(all_values.difference(data.valid_values))
TEST_KEY = 'payroll-type'
HOOK_DATA = [
HookData.from_hook(meta_payroll_type.HealthInsuranceHook,
'US:HRA:Fees', 'US:HRA:Usage', 'US:Premium:Main'),
HookData.from_hook(meta_payroll_type.OtherBenefitsHook,
'US:403b:Fees', 'US:Education', 'US:ProfessionalMembership'),
HookData.from_hook(
meta_payroll_type.SalaryHook,
'CA:Tax:EI',
'US:NY:Tax:NYC',
'US:Taxes:Medicare',
'CA:General',
'US:403b:Match',
'US:PTO:Earned',
'US:PTO:Taken',
),
HookData.from_hook(meta_payroll_type.TaxHook,
'CA:PP', 'US:IL:Unemployment', 'US:SocialSecurity'),
]
HookData.set_invalid_values(HOOK_DATA)
@pytest.fixture(scope='module')
def config():
return testutil.TestConfig()
def norm_value(value):
return value.replace(':Taxes:', ':Tax:', 1)
@pytest.mark.parametrize('hook_type,account,value', (
(data.hook_type, data.account, value)
for data in HOOK_DATA
for value in data.valid_values
))
def test_valid_value_on_post(config, hook_type, account, value):
txn = testutil.Transaction(postings=[
(account, 55, {TEST_KEY: value}),
('Assets:Checking', -55),
])
errors = list(hook_type(config).run(txn))
assert not errors
testutil.check_post_meta(txn, {TEST_KEY: norm_value(value)}, None)
@pytest.mark.parametrize('hook_type,account,value', (
(data.hook_type, data.account, value)
for data in HOOK_DATA
for value in data.valid_values
))
def test_valid_value_on_txn(config, hook_type, account, value):
txn = testutil.Transaction(**{TEST_KEY: value}, postings=[
(account, 80, {TEST_KEY: value}),
('Assets:Checking', -80),
])
errors = list(hook_type(config).run(txn))
assert not errors
testutil.check_post_meta(txn, {TEST_KEY: norm_value(value)}, None)
@pytest.mark.parametrize('hook_type,account,value', (
(data.hook_type, data.account, value)
for data in HOOK_DATA
for value in data.invalid_values
))
def test_invalid_value_on_post(config, hook_type, account, value):
txn = testutil.Transaction(flag='!', postings=[
(account, 90, {TEST_KEY: value}),
('Assets:Checking', -90),
])
errors = list(hook_type(config).run(txn))
assert errors
testutil.check_post_meta(txn, {TEST_KEY: value}, None)
@pytest.mark.parametrize('hook_type,account,value', (
(data.hook_type, data.account, value)
for data in HOOK_DATA
for value in data.invalid_values
))
def test_invalid_value_on_txn(config, hook_type, account, value):
txn = testutil.Transaction(flag='!', **{TEST_KEY: value}, postings=[
(account, 105),
('Assets:Checking', -105),
])
errors = list(hook_type(config).run(txn))
assert errors
testutil.check_post_meta(txn, None, None)
@pytest.mark.parametrize('hook_type,account', (
(data.hook_type, data.account)
for data in HOOK_DATA
))
def test_missing_value(config, hook_type, account):
txn = testutil.Transaction(flag='!', postings=[
(account, 115),
('Assets:Checking', -115),
])
errors = list(hook_type(config).run(txn))
assert errors
@pytest.mark.parametrize('hook_type,account', (
(hook_data.hook_type, other_data.account)
for hook_data in HOOK_DATA
for other_data in HOOK_DATA
if other_data is not hook_data
))
def test_no_overlapping_account_checks(config, hook_type, account):
txn = testutil.Transaction(postings=[
(account, 120, {TEST_KEY: 'Test:Overlap'}),
('Assets:Checking', -120),
])
errors = list(hook_type(config).run(txn))
assert not errors
@pytest.mark.parametrize('hook_data,value', testutil.combine_values(
HOOK_DATA,
testutil.FIXME_VALUES,
))
def test_flagged_fixme_ok(config, hook_data, value):
txn = testutil.Transaction(flag='!', postings=[
(hook_data.account, 120, {TEST_KEY: value}),
('Assets:Checking', -120),
])
errors = list(hook_data.hook_type(config).run(txn))
assert not errors
testutil.check_post_meta(txn, {TEST_KEY: value}, None)
|