def test_dateIsDateObjectWhenRetrieved(self): db = Db(path=self.f.name + '/tmp') accountOne = Account(name='one') db.recordAccount(accountOne) t1 = Transaction(name="a", date=dtd.today(), amount=123) t1.account = accountOne db.recordTransactions([t1]) transactions = db.transactions('a') self.assertTrue(isinstance(transactions[0].date, dtd))
def test_accountByIds(self): db = Db(path=self.f.name + '/tmp') db.recordAccount(Account(name='one')) db.recordAccount(Account(name='two')) db.recordAccount(Account(name='three')) accounts = db.accountByIds([1, 3]) self.assertEqual(2, len(accounts)) self.assertEqual({'one', 'three'}, {a.name for a in accounts})
def test_recordTransactions(self): db = Db(path=self.f.name + '/tmp') account = Account(name='test') db.recordAccount(account) transaction = Transaction() transaction.name = 'test' transaction.amount = 3 transaction.account = account db.recordTransaction(transaction) self.assertTrue(transaction.isValid()) self.assertTrue(transaction.exists())
def test_listTransactions(self): db = Db(path=self.f.name + '/tmp') accountOne = Account(name='one') accountTwo = Account(name='two') db.recordAccount(accountOne) db.recordAccount(accountTwo) t1 = Transaction(name="a", date=dtd.today(), amount=123) t1.account = accountOne t2 = Transaction(name="b", date=dtd.today(), amount=2000) t2.account = accountTwo t3 = Transaction(name="ab", date=dtd.today(), amount=3.00) t3.account = accountTwo db.recordTransactions([t1, t2, t3]) transactions = db.transactions('a') self.assertEqual({'a', 'ab'}, {t.name for t in transactions})
def test_accountByName_when_it_exists(self): db = Db(path=self.f.name + '/tmp') account = db.accountByName('test') db.recordAccount(account) account2 = db.accountByName('test') self.assertEqual(account.id, account2.id)
def test_recordAccount(self): db = Db(path=self.f.name + '/tmp') account = db.accountByName('test') db.recordAccount(account) self.assertTrue(account.isValid()) self.assertTrue(account.exists())