class TestBankTransfer(unittest.TestCase): def setUp(self): kir = Kir() self.first_bank = Bank(1) kir.add_bank(self.first_bank) self.second_bank = Bank(2) kir.add_bank(self.second_bank) first_client_id = 1 second_client_id = 2 third_client_id = 3 first_bank_client = self.first_bank.makeClient(first_client_id) second_bank_client = self.second_bank.makeClient(second_client_id) second_bank_client2 = self.second_bank.makeClient(third_client_id) self.first_bank_client_account = self.first_bank.makeAccount( first_client_id, 3) self.second_bank_client_account = self.second_bank.makeAccount( second_client_id, 4) self.second_bank_client_account2 = self.second_bank.makeAccount( third_client_id, 5) def test_transfer_to_another_bank(self): money = 100 b1 = self.first_bank b2 = self.second_bank first_client_money = self.first_bank_client_account.get_account_balance( ) second_client_money = self.second_bank_client_account.get_account_balance( ) self.first_bank_client_account.deposit(money) result = self.first_bank.transfer(self.first_bank_client_account, self.second_bank_client_account, money) self.assertEqual(result, True, "Transfer error") self.assertEqual(self.first_bank_client_account.getBalance(), first_client_money, "First client still have a money") self.assertEqual(self.second_bank_client_account.getBalance(), (second_client_money + money)) def test_rollback(self): money = 1000 self.first_bank_client_account.deposit(money) self.second_bank.closeProduct(self.second_bank_client_account2.getId()) result = self.first_bank.transfer(self.first_bank_client_account, self.second_bank_client_account2, money) self.assertEqual(result, False, "Transfer should't be done") self.assertEqual(self.first_bank_client_account.getBalance(), money, "First client should still have a money")
class TestBank(unittest.TestCase): def setUp(self): self.bank_id = 1 self.newBank = Bank(self.bank_id) self.USER_ID = 3 self.SECOND_USER_ID = 2 self.PRODUCT_ID = 5 self.PRODUCT_ID_2 = 7 def test_empty_get_clients(self): self.assertEqual(self.newBank.getClients(), []) def test_empty_get_products(self): self.assertEqual(self.newBank.getProducts(), []) def test_empty_get_raports(self): self.assertEqual(self.newBank.getRaports(), []) def test_make_client(self): self.newBank.makeClient(self.USER_ID) self.assertEqual(self.newBank.getClients()[0], self.USER_ID) def test_make_account(self): account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) self.assertEqual(type(self.newBank.getProducts()[0]), BankAccount) self.assertEqual(self.newBank.getProducts()[0], account) def test_make_investment(self): account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) account.deposit(100) self.assertEqual(account.current_account_balance(), 100) investment = self.newBank.makeInvestment(3, 45, account, 3, self.USER_ID, self.PRODUCT_ID_2) self.assertEqual(account.current_account_balance(), 100 - 45) self.assertEqual(type(self.newBank.getProducts()[1]), Investment) self.assertEqual(self.newBank.getProducts()[1], investment) def test_make_credit(self): account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) account.deposit(100) credit = self.newBank.makeCredit(200, account, 3, self.USER_ID, self.PRODUCT_ID_2, 12) self.assertEqual(account.current_account_balance(), 100 + 200) self.assertEqual(type(self.newBank.getProducts()[1]), Credit) self.assertEqual(self.newBank.getProducts()[1], credit) def test_get_user_products(self): self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID_2) self.assertNotEqual(len(self.newBank.getUserProducts(self.USER_ID)), 5) self.assertNotEqual(len(self.newBank.getUserProducts(self.USER_ID)), 1) self.assertEqual(len(self.newBank.getUserProducts(self.USER_ID)), 2) def test_get_user_product(self): self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) product = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID_2) self.assertNotEqual(self.newBank.getUserProduct(self.USER_ID, self.PRODUCT_ID), product) self.assertEqual(self.newBank.getUserProduct(self.USER_ID, self.PRODUCT_ID_2), product) def test_get_user_accounts(self): account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) credit = self.newBank.makeCredit(3, account, 3, self.USER_ID, self.PRODUCT_ID_2, 12) self.assertNotEqual(self.newBank.getUserAccounts(self.USER_ID)[0], credit) self.assertEqual(self.newBank.getUserAccounts(self.USER_ID)[0], account) def test_get_user_credits(self): account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) credit = self.newBank.makeCredit(3, account, 3, self.USER_ID, self.PRODUCT_ID_2, 12) self.assertNotEqual(self.newBank.getUserCredits(self.USER_ID)[0], account) self.assertEqual(self.newBank.getUserCredits(self.USER_ID)[0], credit) def test_get_user_investments(self): account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) investment = self.newBank.makeInvestment(3, 45, account, 3, self.USER_ID, self.PRODUCT_ID_2) self.assertNotEqual(self.newBank.getUserInvestments(self.USER_ID)[0], account) self.assertEqual(self.newBank.getUserInvestments(self.USER_ID)[0], investment) def test_transfer(self): first_account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) second_account = self.newBank.makeAccount(self.SECOND_USER_ID, self.PRODUCT_ID_2) money = 1024 first_account.deposit(money) self.assertEqual(self.newBank.transfer(first_account, second_account, money), True) self.assertEqual(first_account.current_account_balance(), 0) self.assertEqual(second_account.current_account_balance(), 1024) def test_get_product_by_id(self): first_account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) second_account = self.newBank.makeAccount(self.SECOND_USER_ID, self.PRODUCT_ID_2) self.assertEqual(self.newBank.getProductById(self.PRODUCT_ID_2), second_account) self.assertEqual(self.newBank.getProductById(self.PRODUCT_ID), first_account) self.assertEqual(self.newBank.getProductById(45), False) def test_close_product(self): first_account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID) second_account = self.newBank.makeAccount(self.USER_ID, self.PRODUCT_ID_2) self.assertEqual(self.newBank.getProductById(self.PRODUCT_ID_2), second_account) self.newBank.closeProduct(self.PRODUCT_ID_2) self.assertNotEqual(self.newBank.getProductById(self.PRODUCT_ID_2), second_account) self.assertEqual(self.newBank.getProductById(self.PRODUCT_ID), first_account)