-
Notifications
You must be signed in to change notification settings - Fork 0
/
testmoneymanager.py
51 lines (40 loc) · 1.95 KB
/
testmoneymanager.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
import unittest
from tkinter import messagebox
from moneymanager import MoneyManager, item_types
class TestMoneyManager(unittest.TestCase):
def setUp(self):
self.user = MoneyManager()
self.user.balance = 1000.0
def test_legal_deposit_works(self):
'''Tests that depositing money using the account's deposit funds function
adds the amount to the balance'''
self.user.deposit_funds(1000)
self.assertEqual(2000, self.user.balance)
def test_illegal_deposit_raises_exception(self):
'''Tests that that depositing a value that is not a float results into
an exception being raised'''
self.assertEqual(self.user.deposit_funds("4dssjd"), False)
def test_legal_entry(self):
'''Tests that adding a new entry with a legal amount subtracts the funds from
the balance'''
self.user.add_entry(999, item_types[0])
self.assertEqual(self.user.balance, 1)
def test_illegal_entry_amount(self):
'''Tets that withdrawing an illegal amount raises an exception'''
valid_input, valid_type, correct_amount = self.user.add_entry(
'banana', item_types[1])
self.assertEqual(
(valid_input, valid_type, correct_amount), (False, True, True))
def test_illegal_entry_type(self):
'''Tests that adding illegal entry type raises an exception'''
valid_input, valid_type, correct_amount = self.user.add_entry(
90, 'banana')
self.assertEqual(
(valid_input, valid_type, correct_amount), (True, False, True))
def test_insufficient_funds_entry(self):
'''Tests when a user tries to spend more than the account balance'''
valid_input, valid_type, correct_amount = self.user.add_entry(
1001, item_types[0])
self.assertEqual(
(valid_input, valid_type, correct_amount), (True, True, False))
unittest.main()