Files @ c712105bed3c
Branch filter:

Location: NPO-Accounting/conservancy_beancount/tests/test_data_account.py

Brett Smith
Revise chart of accounts used throughout.

The main impetus of this change is to rename accounts that were outside
Beancount's accepted five root accounts, to move them into that
structure. This includes:

Accrued:*Payable: → Liabilities:Payable:*
Accrued:*Receivable: → Assets:Receivable:*
UneanedIncome:* → Liabilities:UnearnedIncome:*

Note the last change did inspire in a change to our validation rules. We no
longer require income-type on unearned income, because it's no longer
considered income at all. Once it's earned and converted to an Income
account, that has an income-type of course.

This did inspire another rename that was not required, but
provided more consistency with the other account names above:

Assets:Prepaid* → Assets:Prepaid:*

Where applicable, I have generally extended tests to make sure one of each
of the five account types is tested. (This mostly meant adding an Equity
account to the tests.) I also added tests for key parts of the hierarchy,
like Assets:Receivable and Liabilities:Payable, where applicable.

As part of this change, Account.is_real_asset() got renamed to
Account.is_cash_equivalent(), to better self-document its purpose.
"""Test Account class"""
# 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 conservancy_beancount import data

@pytest.mark.parametrize('acct_name,under_arg,expected', [
    ('Expenses:Tax:Sales', 'Expenses:Tax:Sales:', False),
    ('Expenses:Tax:Sales', 'Expenses:Tax:Sales', True),
    ('Expenses:Tax:Sales', 'Expenses:Tax:', True),
    ('Expenses:Tax:Sales', 'Expenses:Tax', True),
    ('Expenses:Tax:Sales', 'Expenses:', True),
    ('Expenses:Tax:Sales', 'Expenses', True),
    ('Expenses:Tax:Sales', 'Expense', False),
    ('Expenses:Tax:Sales', 'Equity:', False),
    ('Expenses:Tax:Sales', 'Equity', False),
])
def test_is_under_one_arg(acct_name, under_arg, expected):
    expected = under_arg if expected else None
    assert data.Account(acct_name).is_under(under_arg) == expected

@pytest.mark.parametrize('acct_name,expected', [
    ('Assets:Cash', None),
    ('Assets:Checking', None),
    ('Assets:Prepaid:Expenses', 'Assets:Prepaid'),
    ('Assets:Receivable:Accounts', 'Assets:Receivable'),
])
def test_is_under_multi_arg(acct_name, expected):
    assert expected == data.Account(acct_name).is_under(
        'Assets:Prepaid', 'Assets:Receivable',
    )
    if expected:
        expected += ':'
    assert expected == data.Account(acct_name).is_under(
        'Assets:Prepaid:', 'Assets:Receivable:',
    )

@pytest.mark.parametrize('acct_name,expected', [
    ('Assets:Bank:Checking', True),
    ('Assets:Cash', True),
    ('Assets:Cash:EUR', True),
    ('Assets:Prepaid:Expenses', False),
    ('Assets:Prepaid:Vacation', False),
    ('Assets:Receivable:Accounts', False),
    ('Assets:Receivable:Fraud', False),
    ('Expenses:Other', False),
    ('Equity:OpeningBalance', False),
    ('Income:Other', False),
    ('Liabilities:CreditCard', False),
])
def test_is_cash_equivalent(acct_name, expected):
    assert data.Account(acct_name).is_cash_equivalent() == expected

@pytest.mark.parametrize('acct_name,expected', [
    ('Assets:Bank:Check9999', True),
    ('Assets:Bank:CheckCard', True),
    ('Assets:Bank:Checking', True),
    ('Assets:Bank:Savings', False),
    ('Assets:Cash', False),
    ('Assets:Check9999', True),
    ('Assets:CheckCard', True),
    ('Assets:Checking', True),
    ('Assets:Prepaid:Expenses', False),
    ('Assets:Receivable:Accounts', False),
    ('Expenses:Other', False),
    ('Equity:OpeningBalance', False),
    ('Income:Other', False),
    ('Liabilities:CreditCard', False),
])
def test_is_checking(acct_name, expected):
    assert data.Account(acct_name).is_checking() == expected

@pytest.mark.parametrize('acct_name,expected', [
    ('Assets:Cash', False),
    ('Assets:Prepaid:Expenses', False),
    ('Assets:Receivable:Accounts', False),
    ('Expenses:Other', False),
    ('Equity:OpeningBalance', False),
    ('Income:Other', False),
    ('Liabilities:CreditCard', True),
    ('Liabilities:CreditCard:Visa', True),
    ('Liabilities:Payable:Accounts', False),
    ('Liabilities:UnearnedIncome:Donations', False),
])
def test_is_credit_card(acct_name, expected):
    assert data.Account(acct_name).is_credit_card() == expected