def test_init(self): user = User(password=123, balance=5) self.assertEqual(user.balance, 5) self.assertEqual(user.password, 123) user = User(password='******', balance=5) self.assertEqual(user.balance, 5) self.assertEqual(user.password, '123')
def test_add_users(self): atm = ATM() atm._add_user(password=123, balance=15) expected_users = {123: User(123, 15, atm)} for user, expected_user in zip(atm.users, expected_users): self.assertEqual(user, expected_user)
def test_inner_withdrawal(self): user = User(password=123, balance=50) user._withdraw(10) expected_balance = 40 self.assertEqual(user.balance, expected_balance)
def test_inner_deposit(self): user = User(password=123, balance=5) user._deposit(15) expected_balance = 20 self.assertEqual(user.balance, expected_balance)
def test_check_balance(self): user = User(password=456, balance=500) expected_balance = 500 self.assertEqual(user.check_balance(), expected_balance)
def test_repr(self): self.assertEqual(User(333, 555).__repr__(), 'User(password=333, balance=555)')
def test_unsupported_password_init(self): with self.assertRaisesRegexp(AssertionError, 'password must contain numbers only'): User(password='******', balance=5)
def test_negative_balance_init(self): with self.assertRaisesRegexp(AssertionError, 'cannot open a new user with negative balance'): User(password=123, balance=-5)