-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestcentre.py
383 lines (318 loc) · 11.3 KB
/
testcentre.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Justice Ndou'
__website__ = 'http://jobcloud.freelancing-seo.com/'
__email__ = '[email protected]'
# Copyright 2014 Freelancing Solutions.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
########################################################################################################################
########################################################################################################################
################################################## FUNCTIONS AND UNIT FOR TESTING USERS ###############################
########################################################################################################################
########################################################################################################################
from ConstantsAndErrorCodes import MyConstants, ErrorCodes
from google.appengine.ext import db
"""
FORMAT FOR TESTCENTRE
QUESTION
ANSWER1
ANSWER2
ANSWER3
ANSWER4
[RIGHT ANSWER] [ 1 --> 4]
YOUR ANSWER (MUST MATCH RIGHT ANSWER)
We can load the test questions by making use of the blostore to upload a file with the questions and answers ub the
format above once verified the test will then be offered online.
"""
# Used for exam logic and courses and tests for different subjects
# The Question and Answers Actual questions will be checked by the administrators once uploaded to make sure that they
# are correct.
class MultiChoice(db.Expando, MyConstants, ErrorCodes):
_answersChoice = [1, 2, 3, 4]
question = db.StringProperty(multiline=True)
answer1 = db.StringProperty(multiline=True)
answer2 = db.StringProperty(multiline=True)
answer3 = db.StringProperty(multiline=True)
answer4 = db.StringProperty(multiline=True)
rightanswer = db.StringProperty(default=_answersChoice[0]) # The choices will be selected from the _answersChoice constant.
youranswer = db.StringProperty(default='5') # The answer the person taking the exam choosed 5 means not answered.
def readQuestion(self):
try:
if not(self.question == self.undefined):
return self.question
else:
return self.undefined
except:
return self._generalError
def writeQuestion(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.question = strinput
return True
else:
return False
except:
return self._generalError
def readAnswer1(self):
try:
if not(self.answer1 == self.undefined):
return self.answer1
else:
return self.undefined
except:
return self._generalError
def writeAnswer1(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.answer1 = strinput
return True
else:
return False
except:
return self._generalError
def readAnswer2(self):
try:
if not(self.answer2 == self.undefined):
return self.answer2
else:
return self.undefined
except:
return self._generalError
def writeAnswer2(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.answer2 = strinput
return True
else:
return False
except:
return self._generalError
def readAnswer3(self):
try:
if not(self.answer3 == self.undefined):
return self.answer3
else:
return self.undefined
except:
return self._generalError
def writeAnswer3(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.answer3 = strinput
return True
else:
return False
except:
return self._generalError
def readAnswer4(self):
try:
if not(self.answer4 == self.undefined):
return self.answer4
else:
return self.undefined
except:
return self._generalError
def writeAnswer4(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.answer4 = strinput
return True
else:
return False
except:
return self._generalError
def readRightAnswer(self):
try:
if not(self.rightanswer == self.undefined):
return self.rightanswer
else:
return self.undefined
except:
return self._generalError
def writeRightAnswer(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.rightanswer = strinput
return True
else:
return False
except:
return self._generalError
def readYourAnswer(self):
try:
if not(self.youranswer == self.undefined):
return self.youranswer
else:
return self.undefined
except:
return self._generalError
def writeYourAnswer(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
strinput = strinput.lower()
if not(strinput == self.undefined):
self.youranswer = strinput
return True
else:
return False
except:
return self._generalError
def checkAnswer(self):
try:
if self.readYourAnswer() == self.readRightAnswer():
return True
else:
return False
except:
return self._generalError
class Exam(db.Expando, MyConstants, ErrorCodes):
Testname = db.StringProperty()
TestLevel = db.StringProperty()
TestCode = db.StringProperty(indexed=True)
_TestKind = ['interview', 'freelancer']
strTestKind = db.StringProperty(default=_TestKind[1]) # freelancer
Questions = db.ListProperty(item_type=str) # This string list stores the indexes of the multiple choice questions and answers
def writeTestName(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not(strinput == self.undefined):
self.Testname = strinput
return True
else:
return False
except:
return self._generalError
def readTestName(self):
try:
temp = str(self.Testname)
temp = temp.strip()
if not(temp == self.undefined):
return temp
else:
return self.undefined
except:
return self._generalError
def readTestKind(self):
try:
temp = str(self.strTestKind)
temp = temp.strip()
if temp in self._TestKind:
return temp
else:
return self.undefined
except:
return self._generalError
def writeTestKind(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if strinput in self._TestKind:
self.strTestKind = strinput
return True
else:
return False
except:
return self._generalError
def writeTestLevel(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not(strinput == self.undefined):
self.TestLevel = strinput
return True
else:
return False
except:
return self._generalError
def readTestLevel(self):
try:
temp = str(self.TestLevel)
temp = temp.strip()
if not(temp == self.undefined):
return temp
else:
return self.undefined
except:
return self._generalError
def writeTestCode(self, strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if not(strinput == self.undefined):
self.TestCode = strinput
return True
else:
return False
except:
return self._generalError
def readTestCode(self):
try:
temp = str(self.TestCode)
temp = temp.strip()
if not(temp == self.undefined):
return temp
else:
return self.undefined
except:
return self._generalError
def CreateTestCode(self):
pass
def CreateQuestion(self, inQuestion, inAnswer1, inAnswer2, inAnswer3, inAnswer4, inRightAnswer):
try:
TempMulti = MultiChoice()
if TempMulti.writeQuestion(inQuestion) and TempMulti.writeAnswer1(inAnswer1) and \
TempMulti.writeAnswer2(inAnswer2) and TempMulti.writeAnswer3(inAnswer3) and \
TempMulti.writeAnswer4(inAnswer4) and TempMulti.writeRightAnswer(inRightAnswer):
tempKey = TempMulti.put()
self.Questions.append(tempKey)
return True
else:
return False
except:
return self._generalError
def CreateExam(self, inTestName, inTestLevel, inTestCode, inTestKind):
try:
if self.writeTestName(inTestName) and self.writeTestLevel(inTestLevel) and self.writeTestCode(inTestCode) and self.writeTestKind(inTestKind):
return True
else:
return False
except:
return self._generalError
#Todo- Create procedures to deal with Exams and Exam Creation
class TestCentre(db.Expando, MyConstants, ErrorCodes):
Tests = Exam()
# Used to store User Marks on each course and test
class TestResults(db.Expando, MyConstants, ErrorCodes):
pass