-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest.py
More file actions
91 lines (83 loc) · 4.29 KB
/
Copy pathtest.py
File metadata and controls
91 lines (83 loc) · 4.29 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import unittest
import os
from sql_connection_manager import SqlConnectionManager
from vaccine_caregiver import VaccineCaregiver
from enums import *
from utils import *
# from covid19_vaccine import COVID19Vaccine as covid
# from vaccine_patient import VaccinePatient as patient
class TestDB(unittest.TestCase):
def test_db_connection(self):
try:
self.connection_manager = SqlConnectionManager(Server=os.getenv("Server"),
DBname=os.getenv("DBName"),
UserId=os.getenv("UserID"),
Password=os.getenv("Password"))
self.conn = self.connection_manager.Connect()
except Exception:
self.fail("Connection to databse failed")
class TestVaccineCaregiver(unittest.TestCase):
def test_init(self):
with SqlConnectionManager(Server=os.getenv("Server"),
DBname=os.getenv("DBName"),
UserId=os.getenv("UserID"),
Password=os.getenv("Password")) as sqlClient:
with sqlClient.cursor(as_dict=True) as cursor:
try:
# clear the tables before testing
clear_tables(sqlClient)
# create a new VaccineCaregiver object
self.caregiver_a = VaccineCaregiver(name="Steve Ma",
cursor=cursor)
# check if the patient is correctly inserted into the database
sqlQuery = '''
SELECT *
FROM Caregivers
WHERE CaregiverName = 'Steve Ma'
'''
cursor.execute(sqlQuery)
rows = cursor.fetchall()
if len(rows) < 1:
self.fail("Creating caregiver failed")
# clear the tables after testing, just in-case
# clear_tables(sqlClient)
except Exception:
# clear the tables if an exception occurred
clear_tables(sqlClient)
self.fail("Creating caregiver failed")
def test_verify_schedule(self):
with SqlConnectionManager(Server=os.getenv("Server"),
DBname=os.getenv("DBName"),
UserId=os.getenv("UserID"),
Password=os.getenv("Password")) as sqlClient:
with sqlClient.cursor(as_dict=True) as cursor:
try:
# clear the tables before testing
clear_tables(sqlClient)
# create a new VaccineCaregiver object
self.caregiver_a = VaccineCaregiver(name="Steve Ma",
cursor=cursor)
# check if schedule has been correctly inserted into CareGiverSchedule
sqlQuery = '''
SELECT *
FROM Caregivers, CareGiverSchedule
WHERE Caregivers.CaregiverName = 'Steve Ma'
AND Caregivers.CaregiverId = CareGiverSchedule.CaregiverId
'''
cursor.execute(sqlQuery)
rows = cursor.fetchall()
hoursToSchedlue = [10,11]
minutesToSchedlue = [0, 15, 30, 45]
for row in rows:
slot_hour = row["SlotHour"]
slot_minute = row["SlotMinute"]
if slot_hour not in hoursToSchedlue or slot_minute not in minutesToSchedlue:
self.fail("CareGiverSchedule verification failed")
# clear the tables after testing, just in-case
clear_tables(sqlClient)
except Exception:
# clear the tables if an exception occurred
clear_tables(sqlClient)
self.fail("CareGiverSchedule verification failed")
if __name__ == '__main__':
unittest.main()