Files
@ ccbc447a353d
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_data_metadata.py - annotation
ccbc447a353d
3.5 KiB
text/x-python
query: Start new reporting tool.
Ultimately this is going to be a tool that can generate nicely-formatted
spreadsheets from arbitrary bean-queries. This initial version doesn't
generate spreadsheets yet, but it does integrate our usual books-loading
tools and rewrite rules into existing bean-query functionality, so it's a
start. It also has some of the query building and parsing that higher-level
spreadsheets will need.
Ultimately this is going to be a tool that can generate nicely-formatted
spreadsheets from arbitrary bean-queries. This initial version doesn't
generate spreadsheets yet, but it does integrate our usual books-loading
tools and rewrite rules into existing bean-query functionality, so it's a
start. It also has some of the query building and parsing that higher-level
spreadsheets will need.
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 | 9b63d898af70 9b63d898af70 1b7fdf4f3b00 9b63d898af70 1b7fdf4f3b00 1b7fdf4f3b00 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 582316ae8564 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9b63d898af70 9c335175835c 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 582316ae8564 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 9c335175835c 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad 71d671e493ad | """Test Metadata class"""
# 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 pytest
from . import testutil
from conservancy_beancount import data
@pytest.fixture
def simple_txn(index=None, key=None):
return testutil.Transaction(note='txn note', postings=[
('Assets:Cash', 5),
('Income:Donations', -5, {'note': 'donation love', 'extra': 'Extra'}),
])
SIMPLE_TXN_METAKEYS = frozenset(['filename', 'lineno', 'note'])
LINK_STRINGS = [
'',
'link',
' link',
'link ',
'link1 link2',
' link1 link2 link3 ',
]
def test_metadata_transforms_source():
source = {'1': 'one'}
meta = data.Metadata(source)
meta['2'] = 'two'
assert source['2'] == 'two'
del meta['1']
assert set(source) == {'2'}
@pytest.mark.parametrize('value', LINK_STRINGS)
def test_get_links(value):
meta = data.Metadata({'key': value})
assert list(meta.get_links('key')) == value.split()
def test_get_links_missing():
meta = data.Metadata({})
assert not meta.get_links('key')
@pytest.mark.parametrize('value', testutil.NON_STRING_METADATA_VALUES)
def test_get_links_bad_type(value):
meta = data.Metadata({'key': value})
with pytest.raises(TypeError):
meta.get_links('key')
@pytest.mark.parametrize('value', LINK_STRINGS)
def test_report_links(value):
meta = data.Metadata({'key': value})
assert list(meta.report_links('key')) == value.split()
def test_report_links_missing():
meta = data.Metadata({})
assert not meta.report_links('key')
@pytest.mark.parametrize('value', testutil.NON_STRING_METADATA_VALUES)
def test_report_links_bad_type(value):
meta = data.Metadata({'key': value})
assert not meta.report_links('key')
def test_first_link_from_txn(simple_txn):
meta = data.PostingMeta(simple_txn, 0)
assert meta.first_link('note') == 'txn'
def test_first_link_from_post_override(simple_txn):
meta = data.PostingMeta(simple_txn, 1)
assert meta.first_link('note') == 'donation'
def test_first_link_is_only_link(simple_txn):
meta = data.PostingMeta(simple_txn, 1)
assert meta.first_link('extra') == 'Extra'
def test_first_link_nonexistent_metadata(simple_txn):
meta = data.PostingMeta(simple_txn, 1)
assert meta.first_link('Nonexistent') is None
def test_first_link_nonexistent_default(simple_txn):
meta = data.PostingMeta(simple_txn, 1)
assert meta.first_link('Nonexistent', 'missing') == 'missing'
@pytest.mark.parametrize('meta_value', testutil.NON_STRING_METADATA_VALUES)
def test_first_link_bad_type_metadata(simple_txn, meta_value):
simple_txn.meta['badmeta'] = meta_value
meta = data.PostingMeta(simple_txn, 1)
assert meta.first_link('badmeta') is None
@pytest.mark.parametrize('meta_value', testutil.NON_STRING_METADATA_VALUES)
def test_first_link_bad_type_default(simple_txn, meta_value):
simple_txn.meta['badmeta'] = meta_value
meta = data.PostingMeta(simple_txn, 1)
assert meta.first_link('badmeta', '_') == '_'
@pytest.mark.parametrize('meta_name,expected', [
('approval', 'Approval'),
('bank-id', 'Bank ID'),
('bank-statement', 'Bank Statement'),
('check-id', 'Check Number'),
('paypal-id', 'PayPal ID'),
('purchase-order', 'Purchase Order'),
('receipt', 'Receipt'),
('rt-id', 'Ticket'),
('tax-statement', 'Tax Statement'),
])
def test_human_name(meta_name, expected):
assert data.Metadata.human_name(meta_name) == expected
|