def account(): """ Creates account with 0 balance. :return: """ account = BankAccount() return account
def test_deposit(self): bank = BankAccount() bank.deposit(20) self.assertEqual(20, bank.balance()) bank.deposit(15) self.assertEqual(35, bank.balance())
def test_withdraw(self): bank = BankAccount() bank.deposit(30) bank.withdraw(20) self.assertEqual(10, bank.balance()) with self.assertRaises(InsufficientFunds): bank.withdraw(50)
def createAccount(): # get information from user and generate an id owner = input('Enter your name: ') balance = float(input('Enter your initial deposit: ')) id = uuid.uuid4().hex # return the new bank account object return BankAccount(owner, balance, id)
def test_history(self): account = BankAccount("Test", 0, "$") account.deposit(20) account.balance() int(account) expected = ["Account was created", "Deposited 20$", "Balance check -> 20$", "__int__ check -> 20$"] self.assertEqual(account.history(), expected)
def __init__(self, name, email, bank): self.name = name self.email = email self.account = BankAccount(int_rate=0.02, balance=0)
def __init__(self, name, email): self.name = name self.email = email self.accounts = {'checking': BankAccount(), 'savings': BankAccount()}
def setUp(self): self.account = BankAccount("Rado", 0, "$")
def test_deposit_in_not_empty_account(self): account = BankAccount("Ivo", 1000, "$") account.deposit(500) self.assertEqual(account.balance(), 1500)
from bank import BankAccount # If File name: bank.py and in the same folder b1 = BankAccount("56789", "Tony", 500.0) b2 = BankAccount("12345", "Jerry", 190.0) b1.withdraw(100.0) b2.deposit(50.0) print(b1 < b2) print(b1 > b2)
def test_get_name_when_name_not_string_but_object(self): name = ("Radoslav", "Georgiev") account = BankAccount(name, 0, "%") self.assertEqual(str(name), account.holder())
def test_get_name(self): name = "Test" account = BankAccount(name, 0, "$") self.assertEqual(account.holder(), name)
def test_initial_non_zero_balance(self): initial_balance = 100 account = BankAccount("Test", initial_balance, "$") self.assertEqual(account.balance(), initial_balance)
def account_with_random_balance(): account = BankAccount() account.credit(random.randint(100, 200)) return account
account_init_balance = account_with_random_balance.get_balance() account_with_random_balance.credit(100) assert account_with_random_balance.get_balance( ) - account_init_balance == 100 def test_when_new_account_is_created_then_balance_is_0(account): assert account.get_balance( ) == 0, "The balance after account was created should be 0." def test_when_new_account_is_credited_with_negative_value_then_valueerror_should_raise( account): with pytest.raises(ValueError): account.credit(100) def test_when_new_account_is_credit_by_100_then_its_balance_should_be_100( account): account.credit(100) assert account.get_balance() == 100 @pytest.mark.parametrize( 'value', [1.23, 'jano', True, BankAccount(), list, None]) def test_when_wrong_type_is_credited_then_exception_TypeError_should_be_raised( account, value): with pytest.raises(TypeError): account.credit(value)
def setUp(self): self.account_yangu = BankAccount()
def test_currency_always_string(self): currency = 1 account = BankAccount("Test", 0, currency) self.assertEqual(str(currency), account.currency())
def test_negative_initial_amount(self): with self.assertRaises(ValueError): BankAccount("Test", -100, "$")
def setUp(self): self.currency = "BGN" self.account = BankAccount("Rado", 0, self.currency)
def test_history_when_account_is_created(self): account = BankAccount("Test", 0, "$") expected = ["Account was created"] self.assertEqual(account.history(), expected)
def test_history_with_balance_check(self): account = BankAccount("Test", 0, "$") expected = ["Account was created", "Balance check -> 0$"] self.assertEqual(account.history(), expected)
def setUp(self): self.user_account = BankAccount()
def create_account(self, account_type, initial_amount=0): self.accounts[account_type] = BankAccount(initial_amount)