-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_bank.py
More file actions
76 lines (48 loc) · 2 KB
/
test_bank.py
File metadata and controls
76 lines (48 loc) · 2 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Unit tests for bank.py"""
import pytest
from bank_api.bank import Bank
@pytest.fixture
def bank() -> Bank:
return Bank()
def test_create_account_raises_error_if_name_blank(bank: Bank):
# This means: assert an exception is raised during the following block
with pytest.raises(Exception):
bank.create_account('')
def test_bank_creates_empty(bank: Bank):
assert len(bank.accounts) == 0
assert len(bank.transactions) == 0
def test_can_create_and_get_account(bank: Bank):
bank.create_account('Test')
account = bank.get_account('Test')
assert len(bank.accounts) == 1
assert account.name == 'Test'
def test_get_account_raises_error_if_no_account_matches(bank: Bank):
bank.create_account('Name 1')
# This means: assert an exception is raised during the following block
with pytest.raises(ValueError):
bank.get_account('Name 2')
# TODO: Add unit tests for bank.add_funds()
def test_add_funds_successful(bank: Bank):
bank.create_account("TestName 1")
bank.add_funds("TestName 1", 100)
assert len(bank.transactions) == 1
def test_add_funds_raises_error_if_no_account_matches(bank: Bank):
bank.create_account("TestName 1")
with pytest.raises(ValueError):
bank.add_funds("TestName 2", 100)
def test_add_funds_string_amount_does_not_add_transaction(bank: Bank):
bank.create_account("TestName 1")
bank.add_funds("TestName 1", "100")
assert len(bank.transactions) == 0
def test_add_funds_decimal_value_does_not_add_transaction(bank: Bank):
bank.create_account("TestName 1")
bank.add_funds("TestName 1", 100.50)
assert len(bank.transactions) == 0
def test_add_funds_does_not_add_for_negative_amount(bank: Bank):
bank.create_account("TestName 1")
bank.add_funds("TestName 1", -1)
assert len(bank.transactions) == 0
def test_add_funds_does_not_add_for_zero_amount(bank: Bank):
bank.create_account("TestName 1")
bank.add_funds("TestName 1", 0)
assert len(bank.transactions) == 0