-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.py
183 lines (153 loc) · 5.07 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
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
173
174
175
176
177
178
179
180
181
182
183
class Test:
def __init__(self):
self.failed = False
def load_environment(self):
import os
from dotenv import load_dotenv
load_dotenv()
user = os.getenv("USERNAME")
password = os.getenv("PASSWORD")
db = os.getenv("POSTGRESQL_DB")
db_user = os.getenv("POSTGRESQL_DB_USER")
db_pass = os.getenv("POSTGRESQL_DB_PASSWORD")
db_host = os.getenv("POSTGRESQL_DB_HOST")
db_port = os.getenv("POSTGRESQL_DB_PORT")
if (
not db
or not db_user
or not db_pass
or not db_host
or not db_port
or not password
or not user
):
raise Exception("Missing Certain Environment Variables")
return True
class DatabaseTest(Test):
def __init__(self):
from Database import Database
self.database = Database()
self.uid_to_delete = ""
self.failed = False
def add_test(self):
from Person import Person
t = Person(
None,
"Saul",
"Good",
"Man",
"www.google.com",
"www.google.com",
True,
True,
"12345",
"user",
)
try:
res = self.database.add(t)[0]
self.uid_to_delete = str(res[0])
return True
except Exception as e:
self.failed = True
print("Add Test Unit Test failed\n", e)
return False
def delete_test(self):
try:
self.database.remove(self.uid_to_delete)
return True
except Exception:
self.failed = True
raise Exception("Deleting User Test Failed")
def get_test(self): # bad test
try:
res = self.database.get()
assert len(res) > 0
return True
except Exception as e:
self.failed = True
print("Get All Values test failed")
print(e)
return False
class SQLTest(Test):
def __init__(self):
from database.pgQueries import pgQueries
self.queries = pgQueries()
self.failed = False
def check_queries_exist(self):
try:
assert len(self.queries.select_blacklist) > 0 and isinstance(
self.queries.select_blacklist, str
)
assert len(self.queries.select_cabinet) > 0 and isinstance(
self.queries.select_cabinet, str
)
assert len(self.queries.select_all_no_blacklist) > 0 and isinstance(
self.queries.select_all_no_blacklist, str
)
assert len(self.queries.select_all) > 0 and isinstance(
self.queries.select_all, str
)
assert len(self.queries.select_people) > 0 and isinstance(
self.queries.select_people, str
)
assert len(self.queries.select_active) > 0 and isinstance(
self.queries.select_active, str
)
assert len(self.queries.remove_cabinet) > 0 and isinstance(
self.queries.remove_cabinet, str
)
assert len(self.queries.delete_person) > 0 and isinstance(
self.queries.delete_person, str
)
assert len(self.queries.mark_active) > 0 and isinstance(
self.queries.mark_active, str
)
assert len(self.queries.mark_inactive) > 0 and isinstance(
self.queries.mark_inactive, str
)
assert len(self.queries.mark_all_inactive) > 0 and isinstance(
self.queries.mark_all_inactive, str
)
assert len(self.queries.add_blacklist) > 0 and isinstance(
self.queries.add_blacklist, str
)
assert len(self.queries.add_cabinet) > 0 and isinstance(
self.queries.add_cabinet, str
)
assert len(self.queries.add_person) > 0 and isinstance(
self.queries.add_person, str
)
except AttributeError as e:
print("pgQueries class is missing the following query: ", e.name)
self.failed *= 1
class EmailTest(Test):
def __init__(self):
self.failed = False
def email_self(self):
from Email import Email
try:
e = Email(
"[TEST] This is a Test",
"[TEST] This is a Test",
["acmbyte.ccny@gmail.com"],
)
e.email()
except Exception as e:
print("Email Self Test Failed: \n", e)
self.failed *= 1
if __name__ == "__main__":
pgTest = SQLTest()
dbTest = DatabaseTest()
eTest = EmailTest()
eTest.email_self()
pgTest.load_environment()
pgTest.check_queries_exist()
dbTest.load_environment()
dbTest.add_test()
dbTest.get_test()
dbTest.delete_test()
if pgTest.failed or dbTest.failed or eTest.failed:
print("Tests Failed")
exit(1)
print("Tests Passed!")
exit(0)