-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_bankaccounts_application.py
172 lines (139 loc) · 5.31 KB
/
test_bankaccounts_application.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import unittest
from uuid import uuid4
from decimal import Decimal
from bankaccounts.application import BankAccounts
from bankaccounts.exceptions import *
class TestBankAccounts(unittest.TestCase):
def test(self):
accounts = BankAccounts()
# Check account not found error.
with self.assertRaises(AccountNotFoundError):
accounts.get_balance(uuid4())
# Create an account.
account_id1 = accounts.open_account(
full_name="Alice",
email_address="alice@example.com",
)
# Check balance.
self.assertEqual(accounts.get_balance(account_id1), Decimal("0.00"))
# Deposit funds.
accounts.deposit_funds(
credit_account_id=account_id1,
amount=Decimal("200.00"),
)
# Check balance.
self.assertEqual(accounts.get_balance(account_id1), Decimal("200.00"))
# Withdraw funds.
accounts.withdraw_funds(
debit_account_id=account_id1,
amount=Decimal("50.00"),
)
# # Check balance.
self.assertEqual(accounts.get_balance(account_id1), Decimal("150.00"))
# Fail to withdraw funds - insufficient funds.
with self.assertRaises(InsufficientFundsError):
accounts.withdraw_funds(
debit_account_id=account_id1,
amount=Decimal("151.00"),
)
# Check balance - should be unchanged.
self.assertEqual(accounts.get_balance(account_id1), Decimal("150.00"))
# Create another account.
account_id2 = accounts.open_account(
full_name="Bob",
email_address="bob@example.com",
)
# Transfer funds.
accounts.transfer_funds(
debit_account_id=account_id1,
credit_account_id=account_id2,
amount=Decimal("100.00"),
)
# Check balances.
self.assertEqual(accounts.get_balance(account_id1), Decimal("50.00"))
self.assertEqual(accounts.get_balance(account_id2), Decimal("100.00"))
# Fail to transfer funds - insufficient funds.
with self.assertRaises(InsufficientFundsError):
accounts.transfer_funds(
debit_account_id=account_id1,
credit_account_id=account_id2,
amount=Decimal("1000.00"),
)
# Check balances - should be unchanged.
self.assertEqual(accounts.get_balance(account_id1), Decimal("50.00"))
self.assertEqual(accounts.get_balance(account_id2), Decimal("100.00"))
# Close account.
accounts.close_account(account_id1)
# Fail to transfer funds - account closed.
with self.assertRaises(AccountClosedError):
accounts.transfer_funds(
debit_account_id=account_id1,
credit_account_id=account_id2,
amount=Decimal("50.00"),
)
# Fail to transfer funds - account closed.
with self.assertRaises(AccountClosedError):
accounts.transfer_funds(
debit_account_id=account_id2,
credit_account_id=account_id1,
amount=Decimal("50.00"),
)
# Fail to withdraw funds - account closed.
with self.assertRaises(AccountClosedError):
accounts.withdraw_funds(
debit_account_id=account_id1,
amount=Decimal("1.00"),
)
# Fail to deposit funds - account closed.
with self.assertRaises(AccountClosedError):
accounts.deposit_funds(
credit_account_id=account_id1,
amount=Decimal("1000.00"),
)
# Check balance - should be unchanged.
self.assertEqual(accounts.get_balance(account_id1), Decimal("50.00"))
# Check overdraft limit.
self.assertEqual(
accounts.get_overdraft_limit(account_id2),
Decimal("0.00"),
)
# Set overdraft limit.
accounts.set_overdraft_limit(
account_id=account_id2,
overdraft_limit=Decimal("500.00"),
)
# Can't set negative overdraft limit.
with self.assertRaises(AssertionError):
accounts.set_overdraft_limit(
account_id=account_id2,
overdraft_limit=Decimal("-500.00"),
)
# Check overdraft limit.
self.assertEqual(
accounts.get_overdraft_limit(account_id2),
Decimal("500.00"),
)
# Withdraw funds.
accounts.withdraw_funds(
debit_account_id=account_id2,
amount=Decimal("500.00"),
)
# Check balance - should be overdrawn.
self.assertEqual(
accounts.get_balance(account_id2),
Decimal("-400.00"),
)
# Fail to withdraw funds - insufficient funds.
with self.assertRaises(InsufficientFundsError):
accounts.withdraw_funds(
debit_account_id=account_id2,
amount=Decimal("101.00"),
)
# Fail to set overdraft limit - account closed.
with self.assertRaises(AccountClosedError):
accounts.set_overdraft_limit(
account_id=account_id1,
overdraft_limit=Decimal("500.00"),
)
if __name__ == '__main__':
unittest.main()