-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
129 lines (97 loc) · 2.78 KB
/
test.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
"""
Test cases for Addressbook
Author: James Dolan
TODO:
verify sorting is succesful
verify search is succesful
"""
import sys, os
from db import *
def main():
entry0 = ['Travis', 'Barnes', 'street ad1', 'street ad2', 'Eugene', 'OR', '11111',
'555-555-5555', '555-444-4444', 'ttb@uoregon.edu', '08/30/1991',
'Insert notes here']
entry1 = ['George', 'Castanza', '5th street','', 'NYC', 'NY', '11111',
'555-333-3333', '', 'castanza@seinfeld.com', '' , '']
entry2 = ['Giacomo', 'Ouillizzoni', '123 Fake St.','Apt 7', 'FakeTown', 'FakeState',
'33333','555-222-2222', '', 'gguillizzoni@mail.com', '', 'Cool dude.']
entry3 = ['Thomas', 'Mark', '', '', 'City', 'State', '33333','555-777-7777',
'', 'markt@mail.com', '', '']
entry3_edit = ['Lucy', 'Mark', '', '', 'City', 'State', '33333','555-777-7777',
'555-000-0000', 'markt@mail.com', '10/13/97', '']
'testing connection to db'
print("### connecting to db ###")
try:
os.system('rm Test.ab')
db_init("Test")
if(db_exists("Test")):
print("*** connected succesfully ***")
else:
raise Exception
except:
print('!!! connection failed !!!')
'testing insertion'
print('\n### testing insertion ###')
try:
insert_entry(entry0)
insert_entry(entry1)
insert_entry(entry2)
insert_entry(entry3)
if(get_id(entry0) and get_id(entry1) and get_id(entry2) and get_id(entry3)):
print('*** inserted entries succesfully ***')
else:
raise Exception
except:
print('!!! insertion failed !!!')
'testing deletion'
print('\n### testing deletion ###')
try:
delete_entry(get_id(entry0))
if(not get_id(entry0)):
print('*** delete succesful ***')
else:
raise Exception
except:
print('!!! deletion failed !!!')
'testing search'
print('\n### testing search ###')
try:
result = []
for row in search_entry('Thomas', 'Zip'):
result.append(row[0])
if result[0] == 'Thomas':
print('*** search succesful ***')
else:
raise Exception
except:
print('!!! search failed !!!')
'testing sorting'
print('\n### testing sorting ###')
try:
order = []
for row in query_entrylist('Zip'):
order.append(row[0])
if order[0] == 'George' and order[1] == 'Thomas' and order[2] == 'Giacomo':
print('*** sorting by zip succesful ***')
else: raise Exception
name_order = []
for row in query_entrylist('Last Name'):
name_order.append(row[0])
if order == name_order:
print('*** sorting by last name succesful ***')
else: raise Exception
except:
print('!!! sorting failed !!!')
'testing editing'
print('\n### testing sorting ###')
try:
edit_entry(get_id(entry3), entry3_edit)
if(search_entry('Lucy', 'Zip')):
print('*** edit succesful ***')
else:
raise Exception
except:
print('!!! edit failed !!!')
os.system('rm Test.ab')
if __name__ == "__main__":
main()