def test_add_account_incompatible(self, book): # test compatibility between child account and parent account for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = Account(name=acc_type1, type=acc_type1, parent=book.root_account, commodity=None) book.save() assert len(book.accounts) == 13 for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = book.accounts(name=acc_type1) for acc_type2 in ACCOUNT_TYPES: if not _is_parent_child_types_consistent( acc_type1, acc_type2, []): acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) with pytest.raises(ValueError): book.validate() book.cancel() book.save() assert len(book.accounts) == 13
def test_add_account_compatibility(self, session): # test compatibility between child account and parent account for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = Account(name=acc_type1, type=acc_type1, parent=session.book.root_account, commodity=None) for acc_type2 in ACCOUNT_TYPES: if not _is_parent_child_types_consistent(acc_type1, acc_type2): with pytest.raises(ValueError): acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) else: acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) session.save() assert len(session.accounts) == 100
def test_is_parent_child_types_consistent(self): combi_OK = [("ROOT", "BANK"), (None, "ROOT"), ("ROOT", "EQUITY"), ("ROOT", "ASSET"), ("ROOT", "EXPENSE")] combi_not_OK = [ ("ROOT", "ROOT"), ("ROOT", None), (None, "ASSET"), ("ASSET", "EQUITY"), ("EQUITY", "ASSET"), ("ASSET", "INCOME"), ("EXPENSE", "ASSET"), ] for p, c in combi_OK: assert _is_parent_child_types_consistent(p, c, []) for p, c in combi_not_OK: assert not _is_parent_child_types_consistent(p, c, [])
def test_add_account_compatibility(self, book): # test compatibility between child account and parent account for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = Account(name=acc_type1, type=acc_type1, parent=book.root_account, commodity=None) for acc_type2 in ACCOUNT_TYPES: if _is_parent_child_types_consistent(acc_type1, acc_type2, []): acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) book.save() assert len(book.accounts) == 100
def test_is_parent_child_types_consistent(self): combi_OK = [ ("ROOT", "BANK"), (None, "ROOT"), ("ROOT", "EQUITY"), ("ROOT", "ASSET"), ("ROOT", "EXPENSE"), ] combi_not_OK = [ ("ROOT", "ROOT"), ("ROOT", None), (None, "ASSET"), ("ASSET", "EQUITY"), ("EQUITY", "ASSET"), ("ASSET", "INCOME"), ("EXPENSE", "ASSET"), ] for p, c in combi_OK: assert _is_parent_child_types_consistent(p, c, []) for p, c in combi_not_OK: assert not _is_parent_child_types_consistent(p, c, [])
def test_add_account_compatibility(self, book): # test compatibility between child account and parent account for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = Account(name=acc_type1, type=acc_type1, parent=book.root_account, commodity=None) for acc_type2 in ACCOUNT_TYPES: if not _is_parent_child_types_consistent(acc_type1, acc_type2, []): with pytest.raises(ValueError): acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) book.flush() book.session.expunge(acc2) else: acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) book.save() assert len(book.accounts) == 100
def test_add_account_incompatible(self, book): # test compatibility between child account and parent account for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = Account(name=acc_type1, type=acc_type1, parent=book.root_account, commodity=None) book.save() assert len(book.accounts) == 13 for acc_type1 in ACCOUNT_TYPES - root_types: acc1 = book.accounts(name=acc_type1) for acc_type2 in ACCOUNT_TYPES: if not _is_parent_child_types_consistent(acc_type1, acc_type2, []): acc2 = Account(name=acc_type2, type=acc_type2, parent=acc1, commodity=None) with pytest.raises(ValueError): book.validate() book.cancel() book.save() assert len(book.accounts) == 13