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)
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.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.Ivo = BankAccount("Ivo", 1000, "$")
        self.Rado = BankAccount("Rado", 500, "$")


    def test_bank_account_init(self):
        self.assertEqual(self.Ivo._name, "Ivo")
        self.assertEqual(self.Ivo._balance, 1000)
        self.assertEqual(self.Ivo._currency, "$")

    def test_deposit(self):
        self.Ivo.deposit(200)
        self.assertEqual(self.Ivo._balance, 1200)

    def test_balance(self):
        self.assertEqual(self.Ivo.balance(), 1000)

    def test_withdraw(self):
        self.assertEqual(self.Ivo.withdraw(400), True)
        self.assertEqual(self.Ivo.withdraw(1400), False)

    def test___str__(self):
        self.assertEqual(str(self.Ivo), "Bank account for Ivo with balance of 1000$")

    def test___int__(self):
        self.assertEqual(int(self.Ivo), 1000)
 def test_balance_cannot_be_written(self):
     account1 = BankAccount()
     account2 = BankAccount(100)
     self.assertEqual(account1.balance, 0)
     with self.assertRaises(Exception):
         account1.balance = 50
     self.assertEqual(account1.balance, 0)
     self.assertEqual(account2.balance, 100)
     with self.assertRaises(Exception):
         account2.balance = 50
     self.assertEqual(account2.balance, 100)
     account1.deposit(100)
     account2.deposit(10)
     self.assertEqual(account1.balance, 100)
     self.assertEqual(account2.balance, 110)
     with self.assertRaises(Exception):
         account2.balance = 500
     self.assertEqual(account2.balance, 110)
     account2.transfer(account1, 50)
     self.assertEqual(account1.balance, 150)
     self.assertEqual(account2.balance, 60)
 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)
Example #7
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())
Example #8
0
class User:
    def __init__(self, username, email_address):
        self.name = username
        self.email = email_address
        self.account = BankAccount(0.02, 0)

    def deposit(self, amount):
        self.account.deposit(amount)
        return self

    def withdraw(self, amount):
        self.account.withdraw(amount)
        return self

    def balance(self):
        return self.account.balance()
Example #9
0
class TestBankAccount(unittest.TestCase):
    def setUp(self):
        self.my_bank_account = BankAccount("Rado", 1000, "$")

    def test_create_new_bank_account_class(self):
        self.assertTrue(isinstance(self.my_bank_account, BankAccount))

    # testvame dali tazi funkciq vrushta greshka
    def test_deposit_amount(self):
        with self.assertRaises(ValueError):
            self.my_bank_account.deposit(-1)
        self.my_bank_account.deposit(1000)
        self.assertEqual(self.my_bank_account.initial_balance, 2000)

    def test_check_balance(self):
        current_balance = self.my_bank_account.balance()

        self.assertEqual(self.my_bank_account.initial_balance, current_balance)

    def test_withdraw_negative_amount(self):
        with self.assertRaises(ValueError):
            self.my_bank_account.withdraw(-50)
        self.my_bank_account.withdraw(1000)
        self.assertEqual(self.my_bank_account.initial_balance, 0)

    def test_transfer_to(self):
        other_acc = BankAccount("Pesho", 1010, "$")
        # self.assertEqual(self.my_bank_account.currency, other_acc.currency)
        self.my_bank_account.transfer_to(other_acc, 500)
        self.assertEqual(self.my_bank_account.initial_balance, 1000 - 500)
        self.assertEqual(other_acc.initial_balance, 1010 + 500)

        result = self.my_bank_account.transfer_to(other_acc, 20)
        self.assertTrue(result)

    def test_transfer_negative_amount(self):
        other_acc = BankAccount("Pesho", 1010, "$")
        some_acc = BankAccount("Anton", 1000, "lqlq")

        with self.assertRaises(ValueError):
            self.my_bank_account.transfer_to(other_acc, -50)
            self.my_bank_account.transfer_to(other_acc, 1010)
            self.my_bank_account.transfer_to(some_acc, 40)
Example #10
0
class TestBankAccount(unittest.TestCase):
    def setUp(self):
        self.bank_account = BankAccount("Rado", 0, "$")

    def test_bankaccount_init(self):
        self.assertEqual(self.bank_account._name, "Rado")
        self.assertEqual(self.bank_account._balance, 0)
        self.assertEqual(self.bank_account._currency, "$")

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

    def test_bankaccount_int(self):
        self.assertEqual(int(self.bank_account), 0)

    def test_bankaccount_eq(self):
        other1 = BankAccount("Martin", 1000, "$")
        self.assertTrue(self.bank_account._currency == other1._currency)

        other2 = BankAccount("Martin", 1000, "lv")
        self.assertFalse(self.bank_account._currency == other2._currency)

    def test_bankaccount_deposit(self):
        self.bank_account.deposit(100)
        self.assertEqual(self.bank_account._balance, 100)

    def test_bankaccount_balance(self):
        self.assertEqual(self.bank_account.balance(), '0$')

    def test_bankaccount_withdraw(self):
        self.bank_account._balance = 100
        self.assertTrue(self.bank_account.withdraw(50))
        self.assertFalse(self.bank_account.withdraw(200))

    def test_bankaccount_transfer_to(self):
        other = BankAccount("Martin", 1000, "$")
        self.bank_account._balance = 100
        self.assertTrue(self.bank_account.transfer_to(other, 50))
        #self.bank_account.transfer_to(other, 50)
        self.assertEqual(other._balance, 1050)
        self.assertEqual(self.bank_account._balance, 50)
class TestBankAccount(unittest.TestCase):
	def setUp(self):
		self.bank_account = BankAccount("Rado", 0, "$")

	def test_bankaccount_init(self):
		self.assertEqual(self.bank_account._name, "Rado")
		self.assertEqual(self.bank_account._balance, 0)
		self.assertEqual(self.bank_account._currency, "$")

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

	def test_bankaccount_int(self):
		self.assertEqual(int(self.bank_account), 0)

	def test_bankaccount_eq(self):
		other1 = BankAccount("Martin", 1000, "$")
		self.assertTrue(self.bank_account._currency == other1._currency)

		other2 = BankAccount("Martin", 1000, "lv")
		self.assertFalse(self.bank_account._currency == other2._currency)

	def test_bankaccount_deposit(self):
		self.bank_account.deposit(100)
		self.assertEqual(self.bank_account._balance, 100)

	def test_bankaccount_balance(self):
		self.assertEqual(self.bank_account.balance(), '0$')

	def test_bankaccount_withdraw(self):
		self.bank_account._balance = 100
		self.assertTrue(self.bank_account.withdraw(50))
		self.assertFalse(self.bank_account.withdraw(200))

	def test_bankaccount_transfer_to(self):
		other = BankAccount("Martin", 1000, "$")
		self.bank_account._balance = 100
		self.assertTrue(self.bank_account.transfer_to(other, 50))
		#self.bank_account.transfer_to(other, 50)
		self.assertEqual(other._balance, 1050)
		self.assertEqual(self.bank_account._balance, 50)
Example #12
0
 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)
Example #13
0
class Test(unittest.TestCase):
    def setUp(self):
        self.rado = BankAccount("Rado", 1000, "$")

    def test_bank_account_deposit(self):
        self.assertEqual(self.rado.deposit(1000), 2000)

    def test_balance(self):
        self.assertEqual(self.rado.balance(), 1000)

    def test_withdraw(self):
        self.assertEqual(self.rado.withdraw(300), True)

    def test_str(self):
        self.assertEqual(str(self.rado),
                         "Bank account for Rado with balance of 1000$")

    def test_int(self):
        self.assertEqual(int(self.rado), 1000)

    def test_transfer_to_account(self):
        self.ivo = BankAccount("Ivo", 3000, "$")
        self.assertEqual(self.rado.transfer_to(self.ivo, 20), True)
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'])
Example #15
0
class TestBankAccount(unittest.TestCase):

    def setUp(self):
        self.account_1 = BankAccount("Rado", 1000, "$")
        self.account_2 = BankAccount("Mimi", 100, 'BGN')
        self.account_3 = BankAccount("Gosho", 1000, 'BGN')

    def test_BankAccount_str_(self):
        # verify strings
        verify = 'Bank account for Rado with balance of 0$'
        self.assertTrue(self.account_1.__str__(), verify)

    def test_bankaccount_deposit(self):
        # check if deposit of 1000$ is in __balance
        self.assertEqual(self.account_1.deposit(1000),
                         self.account_1._BankAccount__balance)

    def test_bankaccount_balance(self):
        # check if method balance == property __balance
        self.assertEqual(self.account_1.balance(),
                         self.account_1._BankAccount__balance)

    def test_bankaccount__int__(self):
        # int() == int() True
        self.assertTrue(int(self.account_1), int())
        # int(1000) == 1000 True
        self.assertEqual(int(self.account_1), self.account_1.balance())

    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)

    def test_bankaccount_withdraw(self):
        # check if wihdraw > balance  return False
        self.assertFalse(self.account_1.withdraw(1000), False)
        # check if withdraw(500) is smaller than balance
        self.assertLess(self.account_1.withdraw(200), self.account_1.balance())

    def test_bankaccount__currency(self):
        self.assertNotEqual(self.account_1._currency, self.account_2._currency)
        self.assertEqual(self.account_2._currency, self.account_3._currency)

    def test_bankaccount_transfer_to(self):
        self.assertEqual(self.account_2._currency, self.account_3._currency)
        self.assertLess(self.account_2.withdraw(50),
                        self.account_2._BankAccount__balance)
        self.assertLessEqual(self.account_3.balance(),
                             self.account_3.deposit(50))
        self.assertIsNot(self.account_2._currency, self.account_1._currency)
 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_transfer(self):
     account2 = BankAccount("Bat Georgi", 100, "$")
     account2.transfer_to(self.account, 100)
     self.assertEqual(account2.balance(), 0)
     self.assertEqual(self.account.balance(), 100)
Example #18
0
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)