-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting_account.py
More file actions
54 lines (42 loc) · 1.83 KB
/
Copy pathtesting_account.py
File metadata and controls
54 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
from class_account import Account
from class_user import User
class TestAccount(unittest.TestCase):
def setUp(self):
self.user = User("Alice")
self.account = Account(self.user, "Checking", balance=1000)
def test_deposit_valid(self):
self.account.deposit("Alice", 500)
self.assertEqual(self.account.balance, 1500)
def test_deposit_invalid(self):
with self.assertRaises(ValueError):
self.account.deposit("Alice", -100)
def test_withdraw_valid(self):
self.account.withdraw("Alice", 200)
self.assertEqual(self.account.balance, 800)
def test_withdraw_invalid_negative(self):
with self.assertRaises(ValueError):
self.account.withdraw("Alice", -50)
def test_withdraw_insufficient_funds(self):
with self.assertRaises(ValueError):
self.account.withdraw("Alice", 2000)
def test_add_secondary_holder(self):
self.account.add_holder("Bob", "secondary")
self.assertIn("Bob", self.account.secondary_holders)
def test_add_primary_when_exists(self):
with self.assertRaises(ValueError):
self.account.add_holder("Charlie", "primary")
def test_remove_secondary_holder(self):
self.account.add_holder("Bob", "secondary")
self.account.remove_holder("Bob")
self.assertNotIn("Bob", self.account.secondary_holders)
def test_remove_primary_holder_should_fail(self):
with self.assertRaises(ValueError):
self.account.remove_holder(self.user)
def test_close_account_with_balance(self):
with self.assertRaises(ValueError):
self.account.close_account()
def test_close_account_successfully(self):
self.account.balance = 0
self.account.close_account()
self.assertIsNone(self.account.primary_holder)