-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_transcripts.py
More file actions
241 lines (195 loc) · 9.56 KB
/
test_transcripts.py
File metadata and controls
241 lines (195 loc) · 9.56 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import pytest
from app.logic.transcript import *
from app.models.user import User
from app.models.courseParticipant import CourseParticipant
from app.models.event import Event
from app.models import mainDB
@pytest.fixture(autouse=True)
def setup():
testUser = User.create(username = "namet",
bnumber = "B001234567",
email = "namet@berea.edu",
phoneNumber = "555-123-1234",
firstName = "Test",
lastName = "Name",
isStudent = 1,
isFaculty = 0,
isCeltsAdmin = 0,
isCeltsStudentStaff = 0,
)
newTrainingEvent = Event.create(name = "Test Training Event",
term = 1,
description= "Event for testing",
timeStart = "18:00:00",
timeEnd = "21:00:00",
location = "The testing lab",
isRsvpRequired = 0,
isPrerequisiteForProgram = 0,
isTraining = 1,
isService = 0,
startDate = "2021-12-12",
recurringId = None,
program=2)
EventParticipant.create(user = testUser,
event = newTrainingEvent,
attended = True,
hoursEarned = 2)
newBonnerEvent = Event.create(name = "Test Bonner Event",
term = 1,
description= "Event for testing",
timeStart = "18:00:00",
timeEnd = "21:00:00",
location = "The testing lab",
isRsvpRequired = 0,
isPrerequisiteForProgram = 0,
isTraining = 0,
isService = 0,
isCanceled = 0,
startDate = "2021-12-12",
recurringId = None,
program= 5)
EventParticipant.create(user = testUser,
event = newBonnerEvent,
attended = True,
hoursEarned = 2)
adminName = "ramsayb2"
newCourse = Course.create(courseName = "Test Course",
term = 1,
status = 1,
courseCredit = "45",
createdBy = "ramsayb2",
isAllSectionsServiceLearning = 0,
isPermanentlyDesignated = 0,
sectionBQuestion1 = "",
sectionBQuestion2 = "",
sectionBQuestion3 = "",
sectionBQuestion4 = "",
sectionBQuestion5 = "",
sectionBQuestion6 = "")
CourseInstructor.create(course = newCourse, user = adminName)
CourseParticipant.create(course = newCourse, user = testUser, hoursEarned = 3.0)
newProgramEvent = Event.create(name = "Test Program Event",
term = 1,
description= "Event for testing",
timeStart = "18:00:00",
timeEnd = "21:00:00",
location = "The testing lab",
isRsvpRequired = 0,
isPrerequisiteForProgram = 0,
isTraining = 0,
isService = 0,
startDate = "2021-12-12",
recurringId = None,
program= 1)
EventParticipant.create(user = testUser,
event = newProgramEvent,
attended = True,
hoursEarned = 2)
newNonProgramEvent = Event.create(name = "Test Non-Program Event",
term = 3,
description= "Event for testing",
timeStart = "18:00:00",
timeEnd = "21:00:00",
location = "The testing lab",
isRsvpRequired = 0,
isPrerequisiteForProgram = 0,
isTraining = 0,
isService = 0,
startDate = "2021-12-12",
recurringId = None,
program = 9)
EventParticipant.create(user = testUser,
event = newNonProgramEvent,
attended = True,
hoursEarned = 2)
@pytest.fixture(autouse=True)
def teardown():
yield
testingTrainingEvent = Event.get(Event.name == "Test Training Event")
testingTrainingEvent.delete_instance(recursive=True, delete_nullable=True)
# delete bonner
testingBonnerEvent = Event.get(Event.name == "Test Bonner Event")
testingBonnerEvent.delete_instance(recursive=True, delete_nullable=True)
# delete courses
testingCourse = Course.get(Course.courseName == "Test Course")
testingCourse.delete_instance(recursive=True, delete_nullable=True)
# delete program
testingProgramEvent = Event.get(Event.name == "Test program Event")
testingProgramEvent.delete_instance(recursive=True, delete_nullable=True)
# delete program
testingProgramEvent = Event.get(Event.name == "Test Non-Program Event")
testingProgramEvent.delete_instance(recursive=True, delete_nullable=True)
# delete user
user = User.get(User.username == "namet")
user.delete_instance(recursive=True, delete_nullable=True)
@pytest.mark.integration
def testingSLCourses():
username = "namet"
adminName = "ramsayb2"
testingSLCExist= getSlCourseTranscript(username)
testingSLCNotExist = getSlCourseTranscript(adminName)
checkingNewCourse = Course.get(Course.courseName == "Test Course")
assert not testingSLCNotExist.exists()
assert testingSLCExist.exists()
assert checkingNewCourse in testingSLCExist
@pytest.mark.integration
def testingProgram():
username = "namet"
adminName = "ramsayb2"
programDict = getProgramTranscript(username)
# check that bonners events are included
checkingProgram = Program.get_by_id(5)
assert programDict
assert checkingProgram in [t for t in programDict]
emptyProgramDict = getProgramTranscript(adminName)
assert not emptyProgramDict
@pytest.mark.integration
def testingZeroHourEvents():
username = "namet"
adminName = "ramsayb2"
with mainDB.atomic() as transaction:
zeroHourEvent = Event.create(name = "Test Zero Hour Event",
term = 1,
description = "Event for testing zero hours",
timeStart = "18:00:00",
timeEnd = "21:00:00",
location = "The testing lab",
isRsvpRequired = 0,
isPrerequisiteForProgram = 0,
isTraining = 0,
isService = 0,
startDate = "2021-12-12",
recurringId = None,
program = 9)
EventParticipant.create(user = username,
event = zeroHourEvent,
attended = True,
hoursEarned = 0)
zeroHourEvents = getZeroHourEvents(username)
emptyZeroHourEvents = getZeroHourEvents(adminName)
assert emptyZeroHourEvents == []
assert zeroHourEvent in zeroHourEvents
transaction.rollback()
@pytest.mark.integration
def testingTotalHours():
totalHours = getTotalHours("namet")
assert totalHours["totalCourseHours"] == 3
assert totalHours["totalEventHours"] == 8
assert totalHours["totalHours"] == 11
@pytest.mark.integration
def test_getStartYear():
with mainDB.atomic() as transaction:
# Multiple Courses and Events
newCourse = Course.create(term = 5, status=1, createdBy='ramsayb2')
CourseParticipant.create(course=newCourse, user='namet', hoursEarned=3.0)
assert getStartYear('namet') == 2020
# Event Participant with no Course Participant
CourseParticipant.delete().where(CourseParticipant.user == 'namet').execute()
assert getStartYear('namet') == 2020
# No Activity
EventParticipant.delete().where(EventParticipant.user == 'namet').execute()
assert getStartYear('namet') == "N/A"
# Course Participant with no Event Participant
CourseParticipant.create(course=newCourse, user='namet', hoursEarned=3.0)
assert getStartYear('namet') == 2022
transaction.rollback()