Esempio n. 1
0
 def test_transactions_deposit(self):
     expected_transactions = [
         ('OPEN', 0, 0),
         ('DEPOSIT', 100, 100),
     ]
     account = BankAccount()
     account.deposit(100)
     self.assertEqual(account.transactions, expected_transactions)
Esempio n. 2
0
 def test_transactions_scenario(self):
     expected_transactions = [
         ('OPEN', 0, 0),
         ('DEPOSIT', 100, 100),
         ('WITHDRAWAL', -40, 60),
         ('DEPOSIT', 95, 155),
     ]
     account = BankAccount()
     account.deposit(100)
     account.withdraw(40)
     account.deposit(95)
     self.assertEqual(account.transactions, expected_transactions)
Esempio n. 3
0
 def test_dir_does_not_show_balance_attribute(self):
     account = BankAccount()
     account.deposit(100)
     self.assertNotIn('_balance', dir(account))
     allowed = {
         'accounts',
         'balance',
         'deposit',
         'withdraw',
         'transfer',
         'transactions',
         'name',
     } | set(dir(type('', (), {})()))
     self.assertEqual(set(dir(account)) - allowed, set())
Esempio n. 4
0
 def test_account_comparisons(self):
     account1 = BankAccount()
     account2 = BankAccount()
     self.assertTrue(account1 == account2)
     self.assertTrue(account1 >= account2)
     self.assertTrue(account1 <= account2)
     account1.deposit(100)
     account2.deposit(10)
     self.assertTrue(account1 != account2)
     self.assertTrue(account2 < account1)
     self.assertTrue(account1 > account2)
     self.assertTrue(account2 < account1)
     self.assertTrue(account1 >= account2)
     self.assertTrue(account2 <= account1)
Esempio n. 5
0
 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)
Esempio n. 6
0
 def test_repr(self):
     account = BankAccount()
     self.assertEqual(repr(account), 'BankAccount(balance=0)')
     account.deposit(200)
     self.assertEqual(repr(account), 'BankAccount(balance=200)')
Esempio n. 7
0
 def test_deposit(self):
     account = BankAccount()
     account.deposit(100)
     self.assertEqual(account.balance, 100)
Esempio n. 8
0
 def test_truthy_accounts(self):
     account = BankAccount()
     self.assertIs(bool(account), False)
     account.deposit(100)
     self.assertIs(bool(account), True)
Esempio n. 9
0
 def test_str(self):
     account = BankAccount()
     self.assertEqual(str(account), 'Account with balance of $0')
     account.deposit(200)
     self.assertEqual(str(account), 'Account with balance of $200')