-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_shoppinglist.py
102 lines (86 loc) · 4.75 KB
/
test_shoppinglist.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
import sys
import unittest
from shoppinglists import Shoppinglist
class Shoppingtest(unittest.TestCase):
"""
Class performing unit testing for class ShoppingList
"""
def setUp(self):
"""Defining setUp() method that runs prior to each test."""
self.shoppings = Shoppinglist()
self.shoppings.Shoppinglists = {}
def test_for_creating_a_shoppinglist(self):
""" defining method to test for Creating a shopping list """
current_count = len(self.shoppings.Shoppinglists)
output = self.shoppings.create('Shoppinglist 1', '[email protected]')
self.assertEqual(1, output, "Shopping list successfully created")
def test_if_name_empty(self):
"""defining method to test for adding a shopping list with an empty title """
output = self.shoppings.create('', 'owner')
self.assertEqual(4, output, "please fill all fields")
def tests_if_shopping_exists(self):
"""defining method to test for adding a shopping list That already exists """
self.shoppings.create('muthomi', '[email protected]')
output = self.shoppings.create('muthomi', '[email protected]')
self.assertEqual(2, output, "That shopping list already exists!")
def tests_delete_shoppinglist(self):
"""defining method to test for deleting a shoppinglist"""
self.shoppings.Shoppinglists = {}
self.shoppings.create('muthomi', '[email protected]')
output = self.shoppings.delete('muthomi')
self.assertEqual(1, output, "Succesfully deleted!")
def tests_delete_an_unavailable_shoppinglist(self):
"""defining method to test for deleting a shopping list that does not exist"""
self.shoppings.Shoppinglists = {}
self.shoppings.create('muthomi', '[email protected]')
output = self.shoppings.delete('nnnnnn')
self.assertEqual(2, output, "You can not delete a shopping list that does not exist")
def tests_edit_shoppinglis(self):
"""defining method to test for editing a shoppinglist"""
self.shoppings.Shoppinglists = {}
self.shoppings.create('muthomi', '[email protected]')
output = self.shoppings.edit('muthomi', 'mate', '[email protected]')
self.assertEqual(1, output, "shopping list successfully edited")
def tests_edit_null_title(self):
"""defining method to test for editing a shoppinglist and leaving the name null"""
self.shoppings.Shoppinglists = {}
self.shoppings.create('muthomi', '[email protected]')
output = self.shoppings.edit('muthomi', '', '[email protected]')
self.assertEqual(4,output,"Please fill the name field")
def tests_edit_name_not_found(self):
"""defining method to test for editing a shoppinglist and leaving the name null"""
self.shoppings.Shoppinglists = {}
self.shoppings.create('muthomi', '[email protected]')
output = self.shoppings.edit('mate', 'mwiti', '[email protected]')
self.assertEqual(3,output,"Please fill the name field")
def tests_Add_item(self):
"""defining method to test adding an item in a shoppinglist"""
self.shoppings.ShoppingItems = []
current_count = len(self.shoppings.ShoppingItems)
output = self.shoppings.createitem('muthomi', 'muthomi','[email protected]')
self.assertEqual(current_count+1, output, "Item successfully added")
def tests_addEmpty_item(self):
"""defining method to test adding an empty item in a shoppinglist"""
self.shoppings.ShoppingItems = []
output = self.shoppings.createitem('', 'mate','[email protected]')
self.assertEqual(3,output,"Cannot add an empty item ")
def tests_delete_null_item(self):
"""defining method to test deleting an item that doesn't exist in a shoppinglist"""
self.shoppings.ShoppingItems = []
self.shoppings.createitem('mate', 'mate','[email protected]')
output = self.shoppings.deleteitem('fish','mate')
self.assertEqual(2, output, "Cannot Delete an item that does not exist")
def tests_delete_items(self):
"""defining method to test deleting an existing item"""
self.shoppings.ShoppingItems = []
self.shoppings.createitem('mate', 'mate','[email protected]')
output = self.shoppings.deleteitem('mate','mate')
self.assertEqual(1, output, "Item successfully deleted")
def tests_edit_null_item(self):
"""defining method to test editing an empty item field"""
self.shoppings.Shoppingitems = []
self.shoppings.createitem('mate', 'mate', '[email protected]')
output = self.shoppings.itemedit('', 'mate')
self.assertEqual(3, output, "The item can not be empty")
if __name__ == "__main__":
unittest.main()