Beispiel #1
0
    def test_add_transaction_multiple(self):
        dao = self.account_repo.get_account(1)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo,
                                                  self.trans_repo)

        t_dao1 = TransactionDAO(None, None, None, '255.255',
                                '2021-07-04 10:20:25.123', 'PLN', '1')
        t_dao2 = TransactionDAO(None, None, None, '255.255',
                                '2021-07-04 10:20:25.123', 'USD', '3.73')
        acc.add_transaction(t_dao1)
        acc.add_transaction(t_dao2)

        t_dao1 = self.trans_repo.get_transaction(1)
        t_dao2 = self.trans_repo.get_transaction(2)
        self.assertEqual(t_dao1.account_id, 1)
        self.assertEqual(t_dao2.account_id, 1)
        self.assertEqual(acc.balance,
                         (Decimal('255.26') * Decimal('3.73') +
                          Decimal('255.26')).quantize(Decimal(10)**-2))
        self.assertEqual(len(acc.transactions), 2)

        trans1_from_acc = acc.transactions[0]
        trans2_from_acc = acc.transactions[1]
        trans1_from_db = Transaction.from_dao(t_dao1)
        trans2_from_db = Transaction.from_dao(t_dao2)
        self.assertEqual(trans1_from_acc.id, trans1_from_db.id)
        self.assertEqual(trans2_from_acc.id, trans2_from_db.id)
Beispiel #2
0
    def test_inverse_transaction_change(self):
        self.account_repo.add_account(AccountDAO(None, 'Cash', '500', 'PLN'))
        dao1 = self.account_repo.get_account(1)
        dao2 = self.account_repo.get_account(2)
        acc1: Account = PersistentAccount.from_dao(dao1, self.account_repo, self.trans_repo)
        acc2: Account = PersistentAccount.from_dao(dao2, self.account_repo, self.trans_repo)

        t_dao1 = TransactionDAO(None, None, None, '200', '2021-07-04 10:20:25.123', 'PLN', '1')
        t_dao2 = TransactionDAO(None, None, None, '-200', '2021-07-04 10:20:25.123', 'PLN', '1')
        acc1.add_transaction(t_dao1)
        acc2.add_transaction(t_dao2)

        self.assertEqual(acc1.balance, Decimal('300'))
        self.assertEqual(acc2.balance, Decimal('300'))

        t1 = acc1.transactions[0]
        t2 = acc2.transactions[0]
        t1.inverse_transaction = t2
        t2.inverse_transaction = t1

        self.assertEqual(t1.inverse_transaction, t2)
        self.assertEqual(t2.inverse_transaction, t1)

        t1_dao = self.trans_repo.get_transaction(1)
        t2_dao = self.trans_repo.get_transaction(2)

        self.assertEqual(t1_dao.inv_trans_id, 2)
        self.assertEqual(t2_dao.inv_trans_id, 1)
Beispiel #3
0
    def test_remove_transaction(self):
        dao = self.account_repo.get_account(1)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo,
                                                  self.trans_repo)

        t_dao1 = TransactionDAO(None, None, None, '120',
                                '2021-07-04 10:20:25.123', 'PLN', '1')
        t_dao2 = TransactionDAO(None, None, None, '350',
                                '2021-07-04 10:20:25.123', 'USD', '3.73')
        acc.add_transaction(t_dao1)
        acc.add_transaction(t_dao2)

        acc.remove_transaction(1)

        self.assertIsNone(self.trans_repo.get_transaction(1))
        t_dao = self.trans_repo.get_transaction(2)
        self.assertEqual(t_dao.account_id, 1)
        self.assertEqual(acc.balance, Decimal('350') * Decimal('3.73'))
        self.assertEqual(len(acc.transactions), 1)

        trans_from_acc = acc.transactions[0]
        trans_from_db = Transaction.from_dao(t_dao)
        self.assertEqual(trans_from_acc.id, trans_from_db.id)
Beispiel #4
0
    def test_value_change_same_curr(self):
        dao = self.account_repo.get_account(1)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo, self.trans_repo)

        t_dao = TransactionDAO(None, None, None, '250', '2021-07-04 10:20:25.123', 'PLN', '1')
        acc.add_transaction(t_dao)
        self.assertEqual(acc.balance, Decimal('350'))

        trans = acc.transactions[0]
        trans.value = Decimal('100')
        self.assertEqual(acc.balance, Decimal('200'))

        t_dao = self.trans_repo.get_transaction(1)
        self.assertEqual(t_dao.value, '100')
Beispiel #5
0
    def test_note_change(self):
        dao = self.account_repo.get_account(1)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo, self.trans_repo)

        t_dao = TransactionDAO(None, None, None, '400', '2021-07-04 10:20:25.123', 'PLN', '1')
        acc.add_transaction(t_dao)
        self.assertEqual(acc.balance, Decimal('500'))

        trans = acc.transactions[0]
        trans.note = "Some income"

        self.assertEqual(trans.note, "Some income")

        t_dao = self.trans_repo.get_transaction(1)
        self.assertEqual(t_dao.note, "Some income")
Beispiel #6
0
    def test_add_transaction_same_curr(self):
        dao = self.account_repo.get_account(1)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo,
                                                  self.trans_repo)

        t_dao = TransactionDAO(None, None, None, '255.255',
                               '2021-07-04 10:20:25.123', 'PLN', '1')
        acc.add_transaction(t_dao)

        t_dao = self.trans_repo.get_transaction(1)
        self.assertEqual(t_dao.account_id, 1)
        self.assertEqual(acc.balance, Decimal('255.26'))
        self.assertEqual(len(acc.transactions), 1)

        trans_from_acc = acc.transactions[0]
        trans_from_db = Transaction.from_dao(t_dao)
        self.assertEqual(trans_from_acc.id, trans_from_db.id)
Beispiel #7
0
    def test_value_change_diff_curr(self):
        dao = AccountDAO(None, 'Crypto Wallet', '700', 'USD')
        self.account_repo.add_account(dao)
        dao = self.account_repo.get_account(2)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo, self.trans_repo)

        t_dao = TransactionDAO(None, None, None, '200', '2021-07-04 10:20:25.123', 'PLN', '0.27')
        acc.add_transaction(t_dao)
        self.assertEqual(acc.balance, Decimal('754'))

        trans = acc.transactions[0]
        trans.value = Decimal('100')

        self.assertEqual(acc.balance, Decimal('727'))

        t_dao = self.trans_repo.get_transaction(1)
        self.assertEqual(t_dao.value, '100')
Beispiel #8
0
    def test_add_transaction_different_curr(self):
        dao = self.account_repo.get_account(1)
        acc: Account = PersistentAccount.from_dao(dao, self.account_repo,
                                                  self.trans_repo)

        t_dao = TransactionDAO(None, None, None, '255.255',
                               '2021-07-04 10:20:25.123', 'USD', '3.73')
        acc.add_transaction(t_dao)

        t_dao = self.trans_repo.get_transaction(1)
        self.assertEqual(t_dao.account_id, 1)
        self.assertEqual(acc.balance,
                         (Decimal('255.26') * Decimal('3.73')).quantize(
                             Decimal(10)**-2))
        self.assertEqual(len(acc.transactions), 1)

        trans_from_acc = acc.transactions[0]
        trans_from_db = Transaction.from_dao(t_dao)
        self.assertEqual(trans_from_acc.id, trans_from_db.id)