Esempio n. 1
0
    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})
Esempio n. 2
0
    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))
Esempio n. 3
0
 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())
Esempio n. 4
0
    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})
Esempio n. 5
0
    def __init__(self, parent=None):
        super(Backend, self).__init__(parent=parent)

        self._db = Db.Get()
        self._transactionModel = TransactionModel()
        self._transactionModel.setTransactions(self._db.transactions())
        self._categoryModel = CategoryModel()
        self._categoryModel.setCategories([Category('income'), Category('test')])

        self._transactionImportModel = TransactionModel()

        self._transactionModelProxy = ProxyModel()
        self._transactionModelProxy.setSourceModel(self._transactionModel)
        self._transactionModelProxy.setFilterRole(TransactionModel.NameRole)

        self._transactionImportModelProxy = ProxyModel()
        self._transactionImportModelProxy.setSourceModel(self._transactionImportModel)
        self._transactionImportModelProxy.setFilterRole(TransactionModel.NameRole)
Esempio n. 6
0
 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)
Esempio n. 7
0
 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())
Esempio n. 8
0
 def test_accountByName_when_it_does_not_exists(self):
     db = Db(path=self.f.name + '/tmp')
     account = db.accountByName('test')
     self.assertTrue(account.isValid())
     self.assertFalse(account.exists())
Esempio n. 9
0
 def test_dbCreation(self):
     db = Db(path=self.f.name + '/tmp')
     self.assertEqual(db.path(), self.f.name + '/tmp')