def test_create_parentless_account(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create an account without parent that is not ROOT acc = Account(name="test account", type="ASSET", commodity=EUR) new_book.add(acc) with pytest.raises(ValueError): new_book.validate() new_book.cancel() # create an account without parent that is ROOT but with wrong name acc = Account(name="test account", type="ROOT", commodity=EUR) new_book.add(acc) with pytest.raises(ValueError): new_book.validate() new_book.cancel() # create an account without parent that is ROOT with correct name acc = Account(name="Root Account", type="ROOT", commodity=EUR) new_book.add(acc) new_book.flush() assert len(new_book.accounts) == 0 root_accs = new_book.query(Account).all() assert len(root_accs) == 3
def test_create_samenameandparent_accounts(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account acc1 = Account(name="test account", type="ASSET", commodity=EUR, parent=racc) acc2 = Account(name="test account", type="ASSET", commodity=EUR, parent=racc) with pytest.raises(ValueError): new_book.validate()
def test_create_unknowntype_account(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create account with unknown type with pytest.raises(ValueError): acc = Account(name="test account", type="FOO", commodity=EUR, parent=racc) new_book.validate()
def test_create_root_subaccount(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create root account should raise an exception acc = Account(name="subroot accout", type="ROOT", commodity=EUR, parent=racc) with pytest.raises(ValueError): new_book.validate() # except if we add the control_mode 'allow-root-subaccounts' to the book new_book.control_mode.append("allow-root-subaccounts") new_book.validate() assert len(new_book.accounts) == 1