def test_remove_transaction_inverse_different_curr(self): self.account_repo.add_account( AccountDAO(None, 'Crypto Wallet', '300', 'USD')) 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) acc2.transfer(acc1, Decimal('500'), Decimal('3.73')) self.assertEqual(len(acc1.transactions), 1) self.assertEqual(acc1.balance, Decimal('500') * Decimal('3.73')) self.assertEqual(len(acc2.transactions), 1) self.assertEqual(acc2.balance, Decimal('-200')) acc1.remove_transaction(2) self.assertEqual(len(acc1.transactions), 0) self.assertEqual(acc1.balance, Decimal('0')) self.assertEqual(len(acc2.transactions), 0) self.assertEqual(acc2.balance, Decimal('300')) self.assertIsNone(self.trans_repo.get_transaction(1)) self.assertIsNone(self.trans_repo.get_transaction(2))
def test_remove_transaction_inverse_same_curr(self): self.account_repo.add_account(AccountDAO(None, 'Cash', '360', '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) acc2.transfer(acc1, Decimal('250')) self.assertEqual(len(acc1.transactions), 1) self.assertEqual(acc1.balance, Decimal('250')) self.assertEqual(len(acc2.transactions), 1) self.assertEqual(acc2.balance, Decimal('110')) acc1.remove_transaction(2) self.assertEqual(len(acc1.transactions), 0) self.assertEqual(acc1.balance, Decimal('0')) self.assertEqual(len(acc2.transactions), 0) self.assertEqual(acc2.balance, Decimal('360')) self.assertIsNone(self.trans_repo.get_transaction(1)) self.assertIsNone(self.trans_repo.get_transaction(2))
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)
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')
def test_transfer_diff_curr(self): self.account_repo.add_account( AccountDAO(None, 'Crypto Wallet', '500', 'USD')) 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) acc2.transfer(acc1, Decimal('250'), Decimal('3.73')) self.assertEqual(acc1.balance, Decimal('250') * Decimal('3.73')) self.assertEqual(acc2.balance, Decimal('250')) t_in = acc1.transactions[0] t_out = acc2.transactions[0] self.assertEqual(t_out.account, acc2) self.assertEqual(t_out.id, 1) self.assertEqual(t_out.value, Decimal('-250')) self.assertEqual(t_out.converted_value, Decimal('-250')) self.assertEqual(t_out.exchange_rate, Decimal('1')) self.assertEqual(t_out.inverse_transaction, t_in) self.assertEqual(t_in.account, acc1) self.assertEqual(t_in.id, 2) self.assertEqual(t_in.value, Decimal('250')) self.assertEqual(t_in.converted_value, Decimal('250') * Decimal('3.73')) self.assertEqual(t_in.exchange_rate, Decimal('3.73')) self.assertEqual(t_in.inverse_transaction, t_out) t_out_dao = self.trans_repo.get_transaction(1) t_in_dao = self.trans_repo.get_transaction(2) self.assertEqual(t_out_dao.inv_trans_id, 2) self.assertEqual(t_in_dao.inv_trans_id, 1)
def setUp(self) -> None: dao = AccountDAO(None, 'Credit card', '0', 'PLN') self.account_repo.add_account(dao)