def test_history(self):
     arr = []
     other_arr = []
     arr.append("Account was created")
     self.assertEqual(self.my_account.history(), arr)
     self.my_account.deposit(1000)
     arr.append("Deposited 1000$")
     self.assertEqual(self.my_account.history(), arr)
     arr.append("Balance check -> 1000$")
     self.my_account.balance()
     self.assertEqual(self.my_account.history(), arr)
     int(self.my_account)
     arr.append("__int__ check -> 1000$")
     self.assertEqual(self.my_account.history(), arr)
     self.my_account.withdraw(500)
     arr.append("500$ was withdrawed")
     self.assertEqual(self.my_account.history(), arr)
     self.my_account.balance()
     arr.append("Balance check -> 500$")
     self.assertEqual(self.my_account.history(), arr)
     self.my_account.withdraw(1000)
     arr.append("Withdraw for 1000$ failed.")
     self.assertEqual(self.my_account.history(), arr)
     other_account = BankAccount("Bard", 0, "$")
     other_arr.append("Account was created")
     self.assertEqual(other_account.history(), other_arr)
     self.my_account.deposit(1000)
     arr.append("Deposited 1000$")
     self.my_account.transfer_to(other_account, 500)
     arr.append("Transfer to Bard for 500$")
     other_arr.append("Transfer from Nikola for 500$")
     self.assertEqual(self.my_account.history(), arr)
     self.assertEqual(other_account.history(), other_arr)
class TestBankAccount(unittest.TestCase):
    def setUp(self):
        self.account = BankAccount("Pesho", 0, "BGN")

    def test_str(self):
        self.assertEqual(str(self.account),
                         "Bank account for Pesho with balance of 0BGN")

    def test_int(self):
        self.assertEqual(int(self.account), 0)

    def test_depsit(self):
        self.account.deposit(50)
        self.assertEqual(int(self.account), 50)

    def test_deposit_with_negative(self):
        self.assertRaises(ValueError, self.account.deposit, -50)

    def test_balance(self):
        self.account.deposit(150)
        self.assertEqual(self.account.balance(), 150)

    def test_withdraw(self):
        self.account.deposit(1000)
        self.account.withdraw(600)
        self.assertEqual(self.account.balance(), 400)

    def test_withdraw_with_too_much(self):
        self.account.deposit(200)
        self.account.withdraw(500)
        self.assertEqual(self.account.balance(), 200)

    def test_transfer_to(self):
        account_2 = BankAccount("Gosho", 1000, "BGN")
        account_2.transfer_to(self.account, 600)
        self.assertEqual(account_2.balance(), 400)
        self.assertEqual(self.account.balance(), 600)

    def test_history(self):
        self.account.deposit(1000)
        self.account.balance()
        str(self.account)
        int(self.account)
        self.account.history()
        self.account.withdraw(500)
        self.account.balance()
        self.account.withdraw(1000)
        self.account.balance()
        history = self.account.history()
        expected = [
            'Account was created', 'Deposited 1000BGN',
            'Balance check -> 1000BGN', '__int__ check -> 1000BGN',
            '500BGN was withdrawed', 'Balance check -> 500BGN',
            'Withdraw for 1000BGN failed.', 'Balance check -> 500BGN'
        ]
        self.assertEqual(history, expected)
class TestBankAccount(unittest.TestCase):

    def setUp(self):
        self.acc = BankAccount("Sasho", 100, "dollars")
        self.acc2 = BankAccount("Misho", 200, "dollars")

    def test_init(self):
        self.assertEqual(self.acc.get_name(), "Sasho")
        self.assertEqual(self.acc.get_balance(), 100)
        self.assertEqual(self.acc.get_currency(), "dollars")

    def test_deposits(self):
        self.acc.deposit(200)
        self.assertEqual(self.acc.get_balance(), 300)

    def test_withdraw(self):
        self.acc.withdraw(100)
        self.assertEqual(self.acc.get_balance(), 0)

    def test_transfer(self):
        self.acc.transfer_to(self.acc2, 100)
        self.assertEqual(self.acc2.get_balance(), 300)

    def test_history(self):
        arr2 = self.acc.history(self.acc2, 50)
        arr = ["Account was created", "Balance : "+str(self.acc.get_balance()), "Sasho transfered 50 dollars to Misho", "Balance : 100"]
        self.assertEqual(arr, arr2)
class TestBankAccount(unittest.TestCase):

    def setUp(self):
        self.account = BankAccount("Rado", 0, "$")

    def test_init(self):
        self.assertEqual(
            str(self.account), 'Bank account for Rado with balance of 0$')

    def test_deposit(self):
        self.account.deposit(1000)
        self.assertEqual(self.account.balance(), 1000)

    def test_int(self):
        self.account.deposit(1000)
        self.assertEqual(int(self.account), self.account.balance())

    def test_withdrow(self):
        self.account.deposit(1000)
        self.account.withdrow(1000)
        self.assertEqual(int(self.account), 0)

    def test_history(self):
        self.account.deposit(1000)
        self.assertEqual(self.account.history(), [
                         'Account was created', 'Deposited 1000$'])

    def test_transfer(self):
        account2 = BankAccount("Bat Georgi", 100, "$")
        account2.transfer_to(self.account, 100)
        self.assertEqual(account2.balance(), 0)
        self.assertEqual(self.account.balance(), 100)
 def test_bankaccount__history(self):
     account = BankAccount("Rado", 0, "$")
     account.deposit(1000)
     account.balance()
     int(account)
     check_history = ['Account was created', 'Deposited 1000$',
                      'Balance check -> 1000$', '__int__ check -> 1000$']
     rado = BankAccount("Rado", 1000, "BGN")
     ivo = BankAccount("Ivo", 0, "BGN")
     rado.transfer_to(ivo, 500)
     rado.balance()
     ivo.balance()
     rado_history = ['Account was created', 'Transfer to Ivo for 500BGN',
                     'Balance check -> 500BGN']
     self.assertListEqual(account.history(), check_history)
     self.assertListEqual(rado.history(), rado_history)
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.acc = BankAccount("Rado", 0, "$")

    def test_creat_new_bank_account(self):
        self.assertTrue(isinstance(self.acc, BankAccount))

    def test_validation_bank_account(self):
        with self.assertRaises(ValueError):
            account = BankAccount("", -10, "$")

    def test_initial_zero_balance_bank_account(self):
        self.assertEqual(self.acc.balance(), 0)

    def test_str_dunder_bank_account(self):
        self.assertEqual(str(self.acc), "Bank account for Rado with balance of 0$")

    def test_repr_dunder_bank_account(self):
        self.assertEqual(repr(self.acc), "Rado : 0$")

    def test_int_dunder_bank_account(self):
        self.assertEqual(int(self.acc), 0)

    def test_deposit_bank_account(self):
        self.acc.deposit(1000)
        self.assertEqual(int(self.acc), 1000)

    def test_balance_bank_account(self):
        self.acc.deposit(1000)
        self.assertEqual(self.acc.balance(), 1000)

    def test_deposit_raise_error(self):
        with self.assertRaises(ValueError):
            self.acc.deposit(-1111)

    def test_withdraw_bank_account(self):
        self.acc.deposit(1000)
        self.assertTrue(self.acc.withdraw(500))

    def test_withdraw_answer_false_bank_account(self):
        self.acc.deposit(1000)
        self.assertFalse(self.acc.withdraw(1509))

    def test_history_bank_account(self):
        self.acc.deposit(1000)
        self.assertEqual(self.acc.history(), ['Account was created', 'Deposited 1000$'])

    def test_transfer_to_bank_account(self):
        rado = BankAccount("Rado", 1000, "BGN")
        ivo = BankAccount("Ivo", 0, "BGN")
        self.assertTrue(rado.transfer_to(ivo, 500))

    def test_raise_type_error_bank_account(self):
        rado = BankAccount("Rado", 1000, "BGN")
        ivo = BankAccount("Ivo", 0, "BGN")
        self.assertRaises(not(rado.transfer_to(ivo, 500), TypeError))
class TestBankAccount(unittest.TestCase):

    def setUp(self):
        self.initial_balance = 1000
        self.rado = BankAccount("Rado", self.initial_balance, "BGN")

    def test_bank_account_init(self):
        self.assertEqual(self.rado.name, "Rado")
        self.assertEqual(self.rado.balance(), 1000)
        self.assertEqual(self.rado.currency, 'BGN')
        self.assertEqual(
            self.rado.history(), ['Account was created', 'Balance check -> 1000$'])
        self.assertGreater(self.rado.balance(), -1)

    def test_if_created_with_negative_balance(self):
        with self.assertRaises(ValueError):
            BankAccount("rado", -10, "USD")

    def test_deposit_working(self):
        old_deposit = self.rado.balance()
        sum_to_add = 100
        self.rado.deposit(sum_to_add)
        new_deposit = self.rado.balance()
        self.assertEqual(new_deposit, old_deposit + sum_to_add)

    def test_witdrawal_possible_withnegative_ammount(self):
        self.assertFalse(self.rado.withdraw(200000))

    def test_trasfer_with_diff_currencies(self):
        self.raiko = BankAccount("Raiko", self.initial_balance, "USD")
        self.assertFalse(self.raiko.transfer_to(self.rado, 333))

    def test_history(self):
        self.rado.deposit(1000)
        self.rado.balance()
        self.rado.withdraw(500)
        self.assertEqual(self.rado.history(),
                         ['Account was created', 'Deposited 1000$', 'Balance check -> 2000$', '500$ was withdrawed'])
Exemple #8
0
def main():
    bank_account = BankAccount("Kirkor Kirkorov", 100, "dollars")
    bank_account.deposit(500)
    print(bank_account.balance())
    bank_account.withdraw(200)
    print(bank_account.balance())
    print(bank_account)
    print(int(bank_account))

    account_1 = BankAccount("Panajot", 500, "euros")
    account_2 = BankAccount("Panajot", 500, "dollars")

    print(bank_account == account_1)
    print(bank_account == account_2)

    print(bank_account.transfer_to(account_1, 100))
    print(bank_account.transfer_to(account_2, 100))

    print(bank_account)
    print(account_1)
    print(account_2)

    print(bank_account.history())
class BankAccountTest(unittest.TestCase):
    def setUp(self):
        self.my_account = BankAccount("Nikola", 0, "$")

    def test_new_bank_account_consturctor(self):
        self.assertTrue(isinstance(self.my_account, BankAccount))
        self.assertEqual(self.my_account.holder(), "Nikola")
        self.assertEqual(self.my_account.balance(), 0)
        self.assertEqual(self.my_account.currency(), "$")

    def test_deposit(self):
        self.my_account.deposit(1000)
        self.assertEqual(self.my_account.balance(), 1000)
        with self.assertRaises(ValueError):
            self.my_account.deposit(-1000)

    def test_withdraw(self):
        self.my_account.deposit(50)
        self.assertTrue(self.my_account.withdraw(50) == True)
        self.assertTrue(self.my_account.withdraw(50) == False)

    def test_int_cast(self):
        self.assertEqual(int(self.my_account), 0)

    def test_str_cast(self):
        self.assertEqual(str(self.my_account),
                         "Bank account for Nikola with balance of 0$")

    def test_transfer_to(self):
        other_account = BankAccount("Bard", 0, "$")
        self.my_account.deposit(500)
        self.my_account.transfer_to(other_account, 500)
        self.assertEqual(other_account.balance(), 500)
        self.assertEqual(self.my_account.balance(), 0)
        with self.assertRaises(ValueError):
            self.my_account.transfer_to(other_account, 500)
        other_account.currency = "BGR"
        self.my_account.money = 500
        with self.assertRaises(ValueError):
            self.my_account.transfer_to(other_account, 500)

    def test_history(self):
        arr = []
        other_arr = []
        arr.append("Account was created")
        self.assertEqual(self.my_account.history(), arr)
        self.my_account.deposit(1000)
        arr.append("Deposited 1000$")
        self.assertEqual(self.my_account.history(), arr)
        arr.append("Balance check -> 1000$")
        self.my_account.balance()
        self.assertEqual(self.my_account.history(), arr)
        int(self.my_account)
        arr.append("__int__ check -> 1000$")
        self.assertEqual(self.my_account.history(), arr)
        self.my_account.withdraw(500)
        arr.append("500$ was withdrawed")
        self.assertEqual(self.my_account.history(), arr)
        self.my_account.balance()
        arr.append("Balance check -> 500$")
        self.assertEqual(self.my_account.history(), arr)
        self.my_account.withdraw(1000)
        arr.append("Withdraw for 1000$ failed.")
        self.assertEqual(self.my_account.history(), arr)
        other_account = BankAccount("Bard", 0, "$")
        other_arr.append("Account was created")
        self.assertEqual(other_account.history(), other_arr)
        self.my_account.deposit(1000)
        arr.append("Deposited 1000$")
        self.my_account.transfer_to(other_account, 500)
        arr.append("Transfer to Bard for 500$")
        other_arr.append("Transfer from Nikola for 500$")
        self.assertEqual(self.my_account.history(), arr)
        self.assertEqual(other_account.history(), other_arr)
class BankAccountTest(unittest.TestCase):

    def setUp(self):
        self.account = BankAccount("Joro", 10, "BGN")

    def test_create_bank_account_class(self):
        self.assertTrue(isinstance(self.account, BankAccount))

    def test_is_name_valid_type(self):
        with self.assertRaises(TypeError):
            BankAccount(1000, 10, "BGN")

    def test_is_balance_valid_type(self):
        with self.assertRaises(TypeError):
            BankAccount("Joro", "gosho", "BGN")

    def test_is_currency_valid_type(self):
        with self.assertRaises(TypeError):
            BankAccount("Joro", 100, 1000)

    def test_is_balance_positive_number(self):
        with self.assertRaises(ValueError):
            BankAccount("Joro", -10, "BGN")

    def test_is_balance_private(self):
        with self.assertRaises(AttributeError):
            self.account.balance += 10

    def test_is_amount_being_deposited(self):
        old_balance = self.account.get_balance()
        self.account.deposit(10)
        new_balance = self.account.get_balance()
        self.assertEqual(10, new_balance - old_balance)

    def test_is_withdraw_possible_with_negative_number(self):
        self.assertFalse(self.account.withdraw(-10))

    def test_is_withdraw_possible_if_balance_not_enough(self):
        self.assertFalse(self.account.withdraw(20))

    def test_is_amount_multiple_by_10(self):
        with self.assertRaises(ValueError):
            self.account.withdraw(5)

    def test_account_str_print(self):
        self.assertEqual(str(self.account), "Bank account for Joro with balance of 10BGN")

    def test_account_int_return(self):
        self.assertEqual(int(self.account), 10)

    def test_is_trasfer_possible_if_accounts_have_different_currencies(self):
        kiro = BankAccount("Kiro", 50, "$")
        self.assertFalse(self.account.transfer_to(kiro, 100))

    def test_history_of_account_that_is_just_created(self):
        self.assertEqual(["Account was created"], self.account.history())

    def test_history_after_some_actions(self):
        self.account.deposit(20)
        self.account.get_balance()
        int(self.account)
        self.account.withdraw(20)
        self.account.get_balance()
        self.account.withdraw(50)
        self.assertEqual(['Account was created', 'Deposited 20BGN', 'Balance check -> 30BGN', '__int__ check -> 30BGN', '20BGN was withdrawed', 'Balance check -> 10BGN', 'Withdraw for 50BGN failed.'], self.account.history())