示例#1
0
    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')
示例#2
0
    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)
示例#3
0
    def test_inner_withdrawal(self):
        user = User(password=123, balance=50)
        user._withdraw(10)

        expected_balance = 40
        self.assertEqual(user.balance, expected_balance)
示例#4
0
    def test_inner_deposit(self):
        user = User(password=123, balance=5)
        user._deposit(15)

        expected_balance = 20
        self.assertEqual(user.balance, expected_balance)
示例#5
0
    def test_check_balance(self):
        user = User(password=456, balance=500)

        expected_balance = 500
        self.assertEqual(user.check_balance(), expected_balance)
示例#6
0
 def test_repr(self):
     self.assertEqual(User(333, 555).__repr__(), 'User(password=333, balance=555)')
示例#7
0
 def test_unsupported_password_init(self):
     with self.assertRaisesRegexp(AssertionError, 'password must contain numbers only'):
         User(password='******', balance=5)
示例#8
0
 def test_negative_balance_init(self):
     with self.assertRaisesRegexp(AssertionError, 'cannot open a new user with negative balance'):
         User(password=123, balance=-5)