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.flush()
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_nobook_account(self, new_book): USD = Commodity(namespace="FOO", mnemonic="BAZ", fullname="cuz") # create account with no book attachable to it with pytest.raises(ValueError): acc = Account(name="test account", type="ASSET", commodity=USD) new_book.flush()
def test_book_trading_accounts(self, new_book): assert len(new_book.accounts) == 0 assert len(new_book.currencies) == 1 # get (and create on the fly) the trading account for the default currency ncur = new_book.currencies(mnemonic="USD") cur = new_book.default_currency ta = new_book.trading_account(ncur) new_book.flush() assert len(new_book.currencies) == 2 assert len(new_book.accounts) == 3 acc = new_book.root_account.children[0] assert acc.name == "Trading" assert acc.commodity == cur acc = acc.children[0] assert acc.name == cur.namespace assert acc.commodity == cur acc = acc.children[0] assert acc.name == ncur.mnemonic assert acc.commodity == ncur ncur = new_book.currencies(mnemonic="CAD") ta = new_book.trading_account(ncur) new_book.flush() assert len(new_book.accounts) == 4 assert len(new_book.currencies) == 3 ncur = new_book.currencies(mnemonic="USD") ta = new_book.trading_account(ncur) assert len(new_book.accounts) == 4 assert len(new_book.currencies) == 3
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.flush()
def test_create_children_accounts(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create account with unknown type acc = Account(name="test account", type="ASSET", commodity=EUR, parent=racc, children=[Account(name="test sub-account", type="ASSET", commodity=EUR)]) new_book.flush() assert len(acc.children) == 1
def test_create_unicodename_account(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create normal account acc = Account(name=u"inouï étrange", type="ASSET", commodity=EUR, parent=racc) new_book.flush() assert len(new_book.accounts) == 1 assert len(repr(acc)) >= 2
def test_create_samenameanddifferentparent_accounts(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create 2 accounts with same name but different parent acc1 = Account(name="test account", type="ASSET", commodity=EUR, parent=racc) acc2 = Account(name="test account", type="ASSET", commodity=EUR, parent=acc1) new_book.flush() assert acc1.fullname == "test account" assert acc2.fullname == "test account:test account"
def test_create_standardliability_account(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create normal account acc = Account(name="test account", type="LIABILITY", commodity=EUR, parent=racc) new_book.flush() assert len(new_book.accounts) == 1 assert acc.non_std_scu == 0 assert acc.commodity_scu == EUR.fraction assert acc.get_balance() == 0 assert acc.sign == -1 assert not acc.is_template
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.flush() # except if we add the control_mode 'allow-root-subaccounts' to the book new_book.control_mode.append("allow-root-subaccounts") new_book.flush() assert len(new_book.accounts) == 1
def test_book_transactions(self, new_book): ncur = new_book.currencies(mnemonic="CAD") new_book.flush() assert len(new_book.currencies) == 2 assert not new_book.is_saved new_book.cancel() assert new_book.is_saved assert len(new_book.currencies) == 1 nncur = new_book.currencies(mnemonic="USD") new_book.flush() assert not new_book.is_saved assert len(new_book.currencies) == 2 new_book.save() assert new_book.is_saved assert len(new_book.currencies) == 2 new_book.delete(nncur) assert not new_book.is_saved assert len(new_book.currencies) == 2 assert not new_book.is_saved new_book.flush() assert not new_book.is_saved assert len(new_book.currencies) == 1 new_book.save() assert new_book.is_saved assert len(new_book.currencies) == 1 nncur = new_book.currencies(mnemonic="USD") new_book.flush() assert len(new_book.currencies) == 2 assert not new_book.is_saved
def test_create_children_accounts(self, new_book): EUR = new_book.commodities[0] racc = new_book.root_account # create account with unknown type acc = Account(name="test account", type="ASSET", commodity=EUR, parent=racc, children=[ Account(name="test sub-account", type="ASSET", commodity=EUR) ]) new_book.flush() assert len(acc.children) == 1
def test_create_save_cancel_flush(self, new_book): EUR = new_book.commodities[0] EUR.mnemonic = "foo" assert EUR.mnemonic == "foo" new_book.cancel() assert EUR.mnemonic == "EUR" EUR.mnemonic = "foo" assert EUR.mnemonic == "foo" new_book.flush() assert EUR.mnemonic == "foo" new_book.cancel() assert EUR.mnemonic == "EUR" EUR.mnemonic = "foo" new_book.save() assert EUR.mnemonic == "foo"
def test_book_transactions(self, new_book): ncur = new_book.currencies(mnemonic="CAD") new_book.flush() assert len(new_book.currencies) == 2 assert not new_book.is_saved new_book.cancel() assert new_book.is_saved assert len(new_book.currencies) == 1 nncur = new_book.currencies(mnemonic="USD") new_book.flush() assert not new_book.is_saved assert len(new_book.currencies) == 2 new_book.save() assert new_book.is_saved assert len(new_book.currencies) == 2 new_book.delete(nncur) assert not new_book.is_saved assert len(new_book.currencies) == 1 new_book.save() assert new_book.is_saved assert len(new_book.currencies) == 1 nncur = new_book.currencies(mnemonic="USD") new_book.flush() assert len(new_book.currencies) == 2 assert not new_book.is_saved