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
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