Files
@ 0d370c445b9e
Branch filter:
Location: NPO-Accounting/conservancy_beancount/tests/test_data_iter_postings.py - annotation
0d370c445b9e
1.8 KiB
text/x-python
plugin: User configuration is passed to hooks on initialization.
3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 163ecbc7d3d2 3a73bc22393a 3a73bc22393a e9096b95002a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a 3a73bc22393a e9096b95002a e9096b95002a e9096b95002a e9096b95002a e9096b95002a | """Test data.iter_postings function"""
# 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 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'}),
])
def test_iter_postings(simple_txn):
for source, post in zip(simple_txn.postings, data.iter_postings(simple_txn)):
assert all(source[x] == post[x] for x in range(len(source) - 1))
assert isinstance(post.account, data.Account)
assert post.meta['note'] # Only works with PostingMeta
def test_setting_metadata_propagates_to_source(simple_txn):
for index, post in enumerate(data.iter_postings(simple_txn)):
post.meta['edited'] = str(index)
for index, post in enumerate(simple_txn.postings):
assert post.meta['edited'] == str(index)
assert not isinstance(post.meta, data.PostingMeta)
def test_deleting_metadata_propagates_to_source(simple_txn):
posts = list(data.iter_postings(simple_txn))
del posts[1].meta['extra']
assert 'extra' not in simple_txn.postings[1].meta
|