2020-03-06 14:22:55 +00:00
|
|
|
"""Test main plugin's HookRegistry"""
|
|
|
|
# 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 pytest
|
|
|
|
|
|
|
|
from . import testutil
|
|
|
|
|
|
|
|
from conservancy_beancount import plugin
|
|
|
|
|
|
|
|
def hook_names(hooks, key):
|
|
|
|
return {type(hook).__name__ for hook in hooks[key]}
|
|
|
|
|
|
|
|
def test_default_registrations():
|
|
|
|
hooks = plugin.HOOK_REGISTRY.group_by_directive()
|
2020-03-15 19:50:14 +00:00
|
|
|
txn_hook_names = hook_names(hooks, 'Transaction')
|
|
|
|
assert len(txn_hook_names) >= 2
|
|
|
|
assert 'MetaExpenseAllocation' in txn_hook_names
|
|
|
|
assert 'MetaTaxImplication' in txn_hook_names
|
2020-03-06 14:22:55 +00:00
|
|
|
|
|
|
|
def test_exclude_single():
|
2020-03-15 14:36:49 +00:00
|
|
|
hooks = plugin.HOOK_REGISTRY.group_by_directive('-expense-allocation')
|
2020-03-15 19:50:14 +00:00
|
|
|
txn_hook_names = hook_names(hooks, 'Transaction')
|
|
|
|
assert txn_hook_names
|
|
|
|
assert 'MetaExpenseAllocation' not in txn_hook_names
|
2020-03-06 14:22:55 +00:00
|
|
|
|
|
|
|
def test_exclude_group_then_include_single():
|
2020-03-15 14:36:49 +00:00
|
|
|
hooks = plugin.HOOK_REGISTRY.group_by_directive('-metadata expense-allocation')
|
2020-03-15 19:50:14 +00:00
|
|
|
txn_hook_names = hook_names(hooks, 'Transaction')
|
|
|
|
assert 'MetaExpenseAllocation' in txn_hook_names
|
|
|
|
assert 'MetaTaxImplication' not in txn_hook_names
|
2020-03-06 14:22:55 +00:00
|
|
|
|
|
|
|
def test_include_group_then_exclude_single():
|
2020-03-15 14:36:49 +00:00
|
|
|
hooks = plugin.HOOK_REGISTRY.group_by_directive('metadata -tax-implication')
|
2020-03-15 19:50:14 +00:00
|
|
|
txn_hook_names = hook_names(hooks, 'Transaction')
|
|
|
|
assert 'MetaExpenseAllocation' in txn_hook_names
|
|
|
|
assert 'MetaTaxImplication' not in txn_hook_names
|
2020-03-06 14:22:55 +00:00
|
|
|
|
|
|
|
def test_unknown_group_name():
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
plugin.HOOK_REGISTRY.group_by_directive('UnKnownTestGroup')
|