1 | import grok |
---|
2 | import datetime |
---|
3 | from zope.component import queryUtility |
---|
4 | from zope.event import notify |
---|
5 | from zope.interface.verify import verifyObject, verifyClass |
---|
6 | from waeup.kofa.interfaces import ICSVExporter |
---|
7 | from waeup.kofa.students.catalog import StudentsQuery |
---|
8 | from waeup.kofa.students.export import ( |
---|
9 | StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter, |
---|
10 | CourseTicketExporter, StudentPaymentsExporter, BedTicketsExporter, |
---|
11 | StudentPaymentsOverviewExporter, StudentStudyLevelsOverviewExporter, |
---|
12 | get_students,) |
---|
13 | from waeup.kofa.students.accommodation import BedTicket |
---|
14 | from waeup.kofa.students.interfaces import ICSVStudentExporter |
---|
15 | from waeup.kofa.students.payments import StudentOnlinePayment |
---|
16 | from waeup.kofa.students.student import Student |
---|
17 | from waeup.kofa.students.studycourse import StudentStudyCourse |
---|
18 | from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket |
---|
19 | from waeup.kofa.students.tests.test_batching import StudentImportExportSetup |
---|
20 | from waeup.kofa.testing import FunctionalLayer |
---|
21 | |
---|
22 | curr_year = datetime.datetime.now().year |
---|
23 | year_range = range(curr_year - 9, curr_year + 1) |
---|
24 | year_range_str = ','.join([str(i) for i in year_range]) |
---|
25 | |
---|
26 | class ExportHelperTests(StudentImportExportSetup): |
---|
27 | layer = FunctionalLayer |
---|
28 | def setUp(self): |
---|
29 | super(ExportHelperTests, self).setUp() |
---|
30 | student = Student() |
---|
31 | self.app['students'].addStudent(student) |
---|
32 | student = self.setup_student(student) |
---|
33 | notify(grok.ObjectModifiedEvent(student)) |
---|
34 | self.student = self.app['students'][student.student_id] |
---|
35 | return |
---|
36 | |
---|
37 | def test_get_students_plain(self): |
---|
38 | # without a filter we get all students |
---|
39 | result = get_students(self.app) |
---|
40 | self.assertEqual(len(list(result)), 1) |
---|
41 | return |
---|
42 | |
---|
43 | def test_get_students_by_session(self): |
---|
44 | # we can filter out students of a certain session |
---|
45 | my_filter1 = StudentsQuery(current_session=2012) |
---|
46 | result = get_students(self.app, stud_filter=my_filter1) |
---|
47 | self.assertEqual(len(list(result)), 1) |
---|
48 | |
---|
49 | my_filter2 = StudentsQuery(current_session=1964) |
---|
50 | result = get_students(self.app, stud_filter=my_filter2) |
---|
51 | self.assertEqual(len(list(result)), 0) |
---|
52 | return |
---|
53 | |
---|
54 | def test_get_students_by_level(self): |
---|
55 | # we can filter out students of a certain level |
---|
56 | my_filter1 = StudentsQuery(current_level=200) |
---|
57 | result = get_students(self.app, stud_filter=my_filter1) |
---|
58 | self.assertEqual(len(list(result)), 1) |
---|
59 | |
---|
60 | my_filter2 = StudentsQuery(current_level=300) |
---|
61 | result = get_students(self.app, stud_filter=my_filter2) |
---|
62 | self.assertEqual(len(list(result)), 0) |
---|
63 | return |
---|
64 | |
---|
65 | def test_get_students_by_deptcode(self): |
---|
66 | # we can filter out students of a certain dept. |
---|
67 | my_filter1 = StudentsQuery(depcode='NA') |
---|
68 | result = get_students(self.app, stud_filter=my_filter1) |
---|
69 | self.assertEqual(len(list(result)), 1) |
---|
70 | |
---|
71 | my_filter2 = StudentsQuery(depcode='NOTEXISTING') |
---|
72 | result = get_students(self.app, stud_filter=my_filter2) |
---|
73 | self.assertEqual(len(list(result)), 0) |
---|
74 | return |
---|
75 | |
---|
76 | def test_get_students_by_faccode(self): |
---|
77 | # we can filter out students of a certain faculty. |
---|
78 | my_filter1 = StudentsQuery(faccode='NA') |
---|
79 | result = get_students(self.app, stud_filter=my_filter1) |
---|
80 | self.assertEqual(len(list(result)), 1) |
---|
81 | |
---|
82 | my_filter2 = StudentsQuery(faccode='NOTEXISTING') |
---|
83 | result = get_students(self.app, stud_filter=my_filter2) |
---|
84 | self.assertEqual(len(list(result)), 0) |
---|
85 | return |
---|
86 | |
---|
87 | def test_get_students_by_current_mode(self): |
---|
88 | # we can filter out students in a certain mode. |
---|
89 | my_filter1 = StudentsQuery(current_mode='ug_ft') |
---|
90 | result = get_students(self.app, stud_filter=my_filter1) |
---|
91 | self.assertEqual(len(list(result)), 1) |
---|
92 | |
---|
93 | my_filter2 = StudentsQuery(current_mode='NOTEXISTING') |
---|
94 | result = get_students(self.app, stud_filter=my_filter2) |
---|
95 | self.assertEqual(len(list(result)), 0) |
---|
96 | return |
---|
97 | |
---|
98 | |
---|
99 | class StudentsExporterTest(StudentImportExportSetup): |
---|
100 | |
---|
101 | layer = FunctionalLayer |
---|
102 | |
---|
103 | std_csv_entry = ( |
---|
104 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
105 | 'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,' |
---|
106 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
107 | ) |
---|
108 | |
---|
109 | def setUp(self): |
---|
110 | super(StudentsExporterTest, self).setUp() |
---|
111 | self.setup_for_export() |
---|
112 | return |
---|
113 | |
---|
114 | def test_ifaces(self): |
---|
115 | # make sure we fullfill interface contracts |
---|
116 | obj = StudentsExporter() |
---|
117 | verifyObject(ICSVStudentExporter, obj) |
---|
118 | verifyClass(ICSVStudentExporter, StudentsExporter) |
---|
119 | return |
---|
120 | |
---|
121 | def test_get_as_utility(self): |
---|
122 | # we can get an student exporter as utility |
---|
123 | result = queryUtility(ICSVExporter, name="students") |
---|
124 | self.assertTrue(result is not None) |
---|
125 | return |
---|
126 | |
---|
127 | def test_export(self): |
---|
128 | # we can really export students |
---|
129 | # set values we can expect in export file |
---|
130 | self.setup_student(self.student) |
---|
131 | exporter = StudentsExporter() |
---|
132 | exporter.export([self.student], self.outfile) |
---|
133 | result = open(self.outfile, 'rb').read() |
---|
134 | self.assertTrue( |
---|
135 | 'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,' |
---|
136 | 'firstname,lastname,matric_number,middlename,nationality,officer_comment,' |
---|
137 | 'perm_address,personal_updated,' |
---|
138 | 'phone,reg_number,sex,student_id,suspended,suspended_comment,password,' |
---|
139 | 'state,history,certcode,is_postgrad,current_level,current_session\r\n' |
---|
140 | |
---|
141 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
142 | 'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,' |
---|
143 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
144 | in result |
---|
145 | ) |
---|
146 | return |
---|
147 | |
---|
148 | def test_export_all(self): |
---|
149 | # we can really export students |
---|
150 | # set values we can expect in export file |
---|
151 | self.setup_student(self.student) |
---|
152 | exporter = StudentsExporter() |
---|
153 | exporter.export_all(self.app, self.outfile) |
---|
154 | result = open(self.outfile, 'rb').read() |
---|
155 | self.assertTrue( |
---|
156 | 'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,' |
---|
157 | 'firstname,lastname,matric_number,middlename,nationality,officer_comment,' |
---|
158 | 'perm_address,personal_updated' |
---|
159 | ',phone,reg_number,sex,student_id,suspended,suspended_comment,password,' |
---|
160 | 'state,history,certcode,is_postgrad,current_level,current_session\r\n' |
---|
161 | |
---|
162 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
163 | 'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,' |
---|
164 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
165 | in result |
---|
166 | ) |
---|
167 | return |
---|
168 | |
---|
169 | def test_export_student(self): |
---|
170 | # we can export a single student |
---|
171 | self.setup_student(self.student) |
---|
172 | exporter = StudentsExporter() |
---|
173 | exporter.export_student(self.student, self.outfile) |
---|
174 | result = open(self.outfile, 'rb').read() |
---|
175 | self.assertTrue( |
---|
176 | 'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,' |
---|
177 | 'firstname,lastname,matric_number,middlename,nationality,officer_comment,' |
---|
178 | 'perm_address,personal_updated' |
---|
179 | ',phone,reg_number,sex,student_id,suspended,suspended_comment,password,' |
---|
180 | 'state,history,certcode,is_postgrad,current_level,current_session\r\n' |
---|
181 | |
---|
182 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
183 | 'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,' |
---|
184 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
185 | in result |
---|
186 | ) |
---|
187 | return |
---|
188 | |
---|
189 | def test_export_filtered(self): |
---|
190 | # we can export a filtered set of students (filtered by session/level) |
---|
191 | self.setup_student(self.student) |
---|
192 | self.app['students'].addStudent(self.student) |
---|
193 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
194 | exporter = StudentsExporter() |
---|
195 | |
---|
196 | exporter.export_filtered( |
---|
197 | self.app, self.outfile, |
---|
198 | current_session=None, current_level=None) |
---|
199 | result1 = open(self.outfile, 'rb').read() |
---|
200 | exporter.export_filtered( |
---|
201 | self.app, self.outfile, |
---|
202 | current_session=2012, current_level=None) |
---|
203 | result2 = open(self.outfile, 'rb').read() |
---|
204 | # current_level can be both a string ... |
---|
205 | exporter.export_filtered( |
---|
206 | self.app, self.outfile, |
---|
207 | current_session=None, current_level=u'200') |
---|
208 | result3 = open(self.outfile, 'rb').read() |
---|
209 | exporter.export_filtered( |
---|
210 | self.app, self.outfile, |
---|
211 | current_session=2011, current_level=None) |
---|
212 | result4 = open(self.outfile, 'rb').read() |
---|
213 | # ... and an integer |
---|
214 | exporter.export_filtered( |
---|
215 | self.app, self.outfile, |
---|
216 | current_session=None, current_level=100) |
---|
217 | result5 = open(self.outfile, 'rb').read() |
---|
218 | self.assertTrue(self.std_csv_entry in result1) |
---|
219 | self.assertTrue(self.std_csv_entry in result2) |
---|
220 | self.assertTrue(self.std_csv_entry in result3) |
---|
221 | self.assertTrue(self.std_csv_entry not in result4) |
---|
222 | self.assertTrue(self.std_csv_entry not in result5) |
---|
223 | return |
---|
224 | |
---|
225 | def test_export_filtered_by_dept(self): |
---|
226 | # we can export a set of students filtered by department |
---|
227 | self.setup_student(self.student) |
---|
228 | self.app['students'].addStudent(self.student) |
---|
229 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
230 | exporter = StudentsExporter() |
---|
231 | # current_session can be both a string ... |
---|
232 | exporter.export_filtered( |
---|
233 | self.app, self.outfile, |
---|
234 | current_session='2012', current_level=u'200', depcode='NA') |
---|
235 | result1 = open(self.outfile, 'rb').read() |
---|
236 | # ... and an integer |
---|
237 | exporter.export_filtered( |
---|
238 | self.app, self.outfile, |
---|
239 | current_session=2012, current_level=200, depcode='NODEPT') |
---|
240 | result2 = open(self.outfile, 'rb').read() |
---|
241 | self.assertTrue(self.std_csv_entry in result1) |
---|
242 | self.assertTrue(self.std_csv_entry not in result2) |
---|
243 | return |
---|
244 | |
---|
245 | def test_export_filtered_by_faculty(self): |
---|
246 | # we can export a set of students filtered by faculty |
---|
247 | self.setup_student(self.student) |
---|
248 | self.app['students'].addStudent(self.student) |
---|
249 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
250 | exporter = StudentsExporter() |
---|
251 | |
---|
252 | exporter.export_filtered( |
---|
253 | self.app, self.outfile, |
---|
254 | current_session=2012, current_level='200', faccode='NA') |
---|
255 | result1 = open(self.outfile, 'rb').read() |
---|
256 | exporter.export_filtered( |
---|
257 | self.app, self.outfile, |
---|
258 | current_session=2012, current_level=200, faccode='NOFAC') |
---|
259 | result2 = open(self.outfile, 'rb').read() |
---|
260 | self.assertTrue(self.std_csv_entry in result1) |
---|
261 | self.assertTrue(self.std_csv_entry not in result2) |
---|
262 | return |
---|
263 | |
---|
264 | class StudentStudyCourseExporterTest(StudentImportExportSetup): |
---|
265 | |
---|
266 | layer = FunctionalLayer |
---|
267 | |
---|
268 | def setUp(self): |
---|
269 | super(StudentStudyCourseExporterTest, self).setUp() |
---|
270 | self.setup_for_export() |
---|
271 | return |
---|
272 | |
---|
273 | def test_ifaces(self): |
---|
274 | # make sure we fullfill interface contracts |
---|
275 | obj = StudentStudyCourseExporter() |
---|
276 | verifyObject(ICSVStudentExporter, obj) |
---|
277 | verifyClass(ICSVStudentExporter, StudentStudyCourseExporter) |
---|
278 | return |
---|
279 | |
---|
280 | def test_get_as_utility(self): |
---|
281 | # we can get an student exporter as utility |
---|
282 | result = queryUtility(ICSVExporter, name="studentstudycourses") |
---|
283 | self.assertTrue(result is not None) |
---|
284 | return |
---|
285 | |
---|
286 | def test_export_empty(self): |
---|
287 | # we can export a nearly empty study course |
---|
288 | study_course = StudentStudyCourse() |
---|
289 | exporter = StudentStudyCourseExporter() |
---|
290 | exporter.export([study_course], self.outfile) |
---|
291 | result = open(self.outfile, 'rb').read() |
---|
292 | self.assertEqual( |
---|
293 | result, |
---|
294 | 'certificate,current_level,current_session,current_verdict,' |
---|
295 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
296 | |
---|
297 | ',,,0,,,0,\r\n' |
---|
298 | ) |
---|
299 | return |
---|
300 | |
---|
301 | def test_export(self): |
---|
302 | # we can really export study courses. |
---|
303 | # set values we can expect in export file |
---|
304 | self.setup_student(self.student) |
---|
305 | study_course = self.student.get('studycourse') |
---|
306 | exporter = StudentStudyCourseExporter() |
---|
307 | exporter.export([study_course], self.outfile) |
---|
308 | result = open(self.outfile, 'rb').read() |
---|
309 | self.assertEqual( |
---|
310 | result, |
---|
311 | 'certificate,current_level,current_session,current_verdict,' |
---|
312 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
313 | |
---|
314 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
315 | ) |
---|
316 | return |
---|
317 | |
---|
318 | def test_export_all(self): |
---|
319 | # we can really export students |
---|
320 | # set values we can expect in export file |
---|
321 | self.setup_student(self.student) |
---|
322 | exporter = StudentStudyCourseExporter() |
---|
323 | exporter.export_all(self.app, self.outfile) |
---|
324 | result = open(self.outfile, 'rb').read() |
---|
325 | self.assertEqual( |
---|
326 | result, |
---|
327 | 'certificate,current_level,current_session,current_verdict,' |
---|
328 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
329 | |
---|
330 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
331 | ) |
---|
332 | return |
---|
333 | |
---|
334 | def test_export_student(self): |
---|
335 | # we can export studycourse of a certain student |
---|
336 | self.setup_student(self.student) |
---|
337 | exporter = StudentStudyCourseExporter() |
---|
338 | exporter.export_student(self.student, self.outfile) |
---|
339 | result = open(self.outfile, 'rb').read() |
---|
340 | self.assertEqual( |
---|
341 | result, |
---|
342 | 'certificate,current_level,current_session,current_verdict,' |
---|
343 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
344 | |
---|
345 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
346 | ) |
---|
347 | return |
---|
348 | |
---|
349 | def test_export_filtered(self): |
---|
350 | # we can export studycourses of a filtered set of students |
---|
351 | self.setup_student(self.student) |
---|
352 | self.app['students'].addStudent(self.student) |
---|
353 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
354 | |
---|
355 | exporter = StudentStudyCourseExporter() |
---|
356 | exporter.export_filtered( |
---|
357 | self.student, self.outfile, current_session=2012) |
---|
358 | result = open(self.outfile, 'rb').read() |
---|
359 | self.assertEqual( |
---|
360 | result, |
---|
361 | 'certificate,current_level,current_session,current_verdict,' |
---|
362 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
363 | |
---|
364 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
365 | ) |
---|
366 | return |
---|
367 | |
---|
368 | |
---|
369 | |
---|
370 | class StudentStudyLevelExporterTest(StudentImportExportSetup): |
---|
371 | |
---|
372 | layer = FunctionalLayer |
---|
373 | |
---|
374 | def setUp(self): |
---|
375 | super(StudentStudyLevelExporterTest, self).setUp() |
---|
376 | self.setup_for_export() |
---|
377 | return |
---|
378 | |
---|
379 | def test_ifaces(self): |
---|
380 | # make sure we fullfill interface contracts |
---|
381 | obj = StudentStudyLevelExporter() |
---|
382 | verifyObject(ICSVStudentExporter, obj) |
---|
383 | verifyClass(ICSVStudentExporter, StudentStudyLevelExporter) |
---|
384 | return |
---|
385 | |
---|
386 | def test_get_as_utility(self): |
---|
387 | # we can get an student exporter as utility |
---|
388 | result = queryUtility(ICSVExporter, name="studentstudylevels") |
---|
389 | self.assertTrue(result is not None) |
---|
390 | return |
---|
391 | |
---|
392 | def test_export_empty(self): |
---|
393 | # we can export a nearly empty study level |
---|
394 | study_level = StudentStudyLevel() |
---|
395 | exporter = StudentStudyLevelExporter() |
---|
396 | exporter.export([study_level], self.outfile) |
---|
397 | result = open(self.outfile, 'rb').read() |
---|
398 | self.assertEqual( |
---|
399 | result, |
---|
400 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
401 | 'validated_by,validation_date,' |
---|
402 | 'student_id,number_of_tickets,certcode\r\n' |
---|
403 | '0.0,,,0,0,,,,0,\r\n' |
---|
404 | ) |
---|
405 | return |
---|
406 | |
---|
407 | def test_export(self): |
---|
408 | # we can really export study levels. |
---|
409 | # set values we can expect in export file |
---|
410 | self.setup_student(self.student) |
---|
411 | study_course = self.student.get('studycourse') |
---|
412 | study_level = study_course[study_course.keys()[0]] |
---|
413 | exporter = StudentStudyLevelExporter() |
---|
414 | exporter.export([study_level], self.outfile) |
---|
415 | result = open(self.outfile, 'rb').read() |
---|
416 | self.assertEqual( |
---|
417 | result, |
---|
418 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
419 | 'validated_by,validation_date,' |
---|
420 | 'student_id,number_of_tickets,certcode\r\n' |
---|
421 | '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
422 | ) |
---|
423 | return |
---|
424 | |
---|
425 | def test_export_all(self): |
---|
426 | # we can really export study levels |
---|
427 | # set values we can expect in export file |
---|
428 | self.setup_student(self.student) |
---|
429 | exporter = StudentStudyLevelExporter() |
---|
430 | exporter.export_all(self.app, self.outfile) |
---|
431 | result = open(self.outfile, 'rb').read() |
---|
432 | self.assertEqual( |
---|
433 | result, |
---|
434 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
435 | 'validated_by,validation_date,' |
---|
436 | 'student_id,number_of_tickets,certcode\r\n' |
---|
437 | '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
438 | ) |
---|
439 | return |
---|
440 | |
---|
441 | def test_export_student(self): |
---|
442 | # we can really export study levels of a certain student |
---|
443 | self.setup_student(self.student) |
---|
444 | exporter = StudentStudyLevelExporter() |
---|
445 | exporter.export_student(self.student, self.outfile) |
---|
446 | result = open(self.outfile, 'rb').read() |
---|
447 | self.assertEqual( |
---|
448 | result, |
---|
449 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
450 | 'validated_by,validation_date,' |
---|
451 | 'student_id,number_of_tickets,certcode\r\n' |
---|
452 | '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
453 | ) |
---|
454 | return |
---|
455 | |
---|
456 | def test_export_filtered(self): |
---|
457 | # we can export studylevels of a filtered set of students |
---|
458 | self.setup_student(self.student) |
---|
459 | self.app['students'].addStudent(self.student) |
---|
460 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
461 | |
---|
462 | exporter = StudentStudyLevelExporter() |
---|
463 | exporter.export_filtered( |
---|
464 | self.student, self.outfile, current_level=200) |
---|
465 | result = open(self.outfile, 'rb').read() |
---|
466 | self.assertEqual( |
---|
467 | result, |
---|
468 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
469 | 'validated_by,validation_date,' |
---|
470 | 'student_id,number_of_tickets,certcode\r\n' |
---|
471 | '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
472 | ) |
---|
473 | return |
---|
474 | |
---|
475 | class CourseTicketExporterTest(StudentImportExportSetup): |
---|
476 | |
---|
477 | layer = FunctionalLayer |
---|
478 | |
---|
479 | def setUp(self): |
---|
480 | super(CourseTicketExporterTest, self).setUp() |
---|
481 | self.setup_for_export() |
---|
482 | return |
---|
483 | |
---|
484 | def test_ifaces(self): |
---|
485 | # make sure we fullfill interface contracts |
---|
486 | obj = CourseTicketExporter() |
---|
487 | verifyObject(ICSVStudentExporter, obj) |
---|
488 | verifyClass(ICSVStudentExporter, CourseTicketExporter) |
---|
489 | return |
---|
490 | |
---|
491 | def test_get_as_utility(self): |
---|
492 | # we can get an student exporter as utility |
---|
493 | result = queryUtility(ICSVExporter, name="coursetickets") |
---|
494 | self.assertTrue(result is not None) |
---|
495 | return |
---|
496 | |
---|
497 | def test_export_empty(self): |
---|
498 | # we can export a nearly empty course ticket |
---|
499 | ticket = CourseTicket() |
---|
500 | exporter = CourseTicketExporter() |
---|
501 | exporter.export([ticket], self.outfile) |
---|
502 | result = open(self.outfile, 'rb').read() |
---|
503 | self.assertEqual( |
---|
504 | result, |
---|
505 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
506 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
507 | '0,0,,,,,,,0,,,,,,\r\n' |
---|
508 | ) |
---|
509 | return |
---|
510 | |
---|
511 | def test_export(self): |
---|
512 | # we can really export course tickets. |
---|
513 | # set values we can expect in export file |
---|
514 | self.setup_student(self.student) |
---|
515 | study_course = self.student.get('studycourse') |
---|
516 | study_level = study_course[study_course.keys()[0]] |
---|
517 | ticket = study_level['CRS1'] |
---|
518 | exporter = CourseTicketExporter() |
---|
519 | exporter.export([ticket], self.outfile) |
---|
520 | result = open(self.outfile, 'rb').read() |
---|
521 | self.assertEqual( |
---|
522 | result, |
---|
523 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
524 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
525 | '1,1,CRS1,100,DEP1,FAC1,100,2012,0,100,,2,Course 1,A111111,CERT1\r\n' |
---|
526 | ) |
---|
527 | return |
---|
528 | |
---|
529 | def test_export_all(self): |
---|
530 | # we can really export all course tickets |
---|
531 | # set values we can expect in export file |
---|
532 | self.setup_student(self.student) |
---|
533 | exporter = CourseTicketExporter() |
---|
534 | exporter.export_all(self.app, self.outfile) |
---|
535 | result = open(self.outfile, 'rb').read() |
---|
536 | self.assertEqual( |
---|
537 | result, |
---|
538 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
539 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
540 | '1,1,CRS1,100,DEP1,FAC1,100,2012,0,100,,2,Course 1,A111111,CERT1\r\n' |
---|
541 | ) |
---|
542 | return |
---|
543 | |
---|
544 | def test_export_student(self): |
---|
545 | # we can really export all course tickets of a certain student |
---|
546 | self.setup_student(self.student) |
---|
547 | exporter = CourseTicketExporter() |
---|
548 | exporter.export_student(self.student, self.outfile) |
---|
549 | result = open(self.outfile, 'rb').read() |
---|
550 | self.assertEqual( |
---|
551 | result, |
---|
552 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
553 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
554 | '1,1,CRS1,100,DEP1,FAC1,100,2012,0,100,,2,Course 1,A111111,CERT1\r\n' |
---|
555 | ) |
---|
556 | return |
---|
557 | |
---|
558 | def test_export_filtered(self): |
---|
559 | # we can export course tickets of a filtered set of students |
---|
560 | self.setup_student(self.student) |
---|
561 | self.app['students'].addStudent(self.student) |
---|
562 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
563 | |
---|
564 | exporter = CourseTicketExporter() |
---|
565 | exporter.export_filtered( |
---|
566 | self.student, self.outfile, current_level=200) |
---|
567 | result = open(self.outfile, 'rb').read() |
---|
568 | self.assertEqual( |
---|
569 | result, |
---|
570 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
571 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
572 | '1,1,CRS1,100,DEP1,FAC1,100,2012,0,100,,2,Course 1,A111111,CERT1\r\n' |
---|
573 | ) |
---|
574 | # if the coursetickets catalog is used to filter students |
---|
575 | # and (course) code is not None |
---|
576 | # only course tickets which belong to this course are exported |
---|
577 | exporter.export_filtered( |
---|
578 | self.student, self.outfile, catalog='coursetickets', code='CRS1') |
---|
579 | result = open(self.outfile, 'rb').read() |
---|
580 | self.assertEqual( |
---|
581 | result, |
---|
582 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
583 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
584 | '1,1,CRS1,100,DEP1,FAC1,100,2012,0,100,,2,Course 1,A111111,CERT1\r\n' |
---|
585 | ) |
---|
586 | exporter.export_filtered( |
---|
587 | self.student, self.outfile, catalog='coursetickets', code='any code') |
---|
588 | result = open(self.outfile, 'rb').read() |
---|
589 | self.assertEqual( |
---|
590 | result, |
---|
591 | 'automatic,carry_over,code,credits,dcode,fcode,level,level_session,' |
---|
592 | 'mandatory,passmark,score,semester,title,student_id,certcode\r\n' |
---|
593 | ) |
---|
594 | return |
---|
595 | |
---|
596 | class StudentPaymentsExporterTest(StudentImportExportSetup): |
---|
597 | |
---|
598 | layer = FunctionalLayer |
---|
599 | |
---|
600 | def setUp(self): |
---|
601 | super(StudentPaymentsExporterTest, self).setUp() |
---|
602 | self.setup_for_export() |
---|
603 | return |
---|
604 | |
---|
605 | def test_ifaces(self): |
---|
606 | # make sure we fullfill interface contracts |
---|
607 | obj = StudentPaymentsExporter() |
---|
608 | verifyObject(ICSVStudentExporter, obj) |
---|
609 | verifyClass(ICSVStudentExporter, StudentPaymentsExporter) |
---|
610 | return |
---|
611 | |
---|
612 | def test_get_as_utility(self): |
---|
613 | # we can get a payments exporter as utility |
---|
614 | result = queryUtility(ICSVExporter, name="studentpayments") |
---|
615 | self.assertTrue(result is not None) |
---|
616 | return |
---|
617 | |
---|
618 | def test_export_empty(self): |
---|
619 | # we can export a nearly empty payment |
---|
620 | payment = StudentOnlinePayment() |
---|
621 | payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1) |
---|
622 | exporter = StudentPaymentsExporter() |
---|
623 | exporter.export([payment], self.outfile) |
---|
624 | result = open(self.outfile, 'rb').read() |
---|
625 | self.assertEqual( |
---|
626 | result, |
---|
627 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
628 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
629 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
630 | |
---|
631 | ',0.0,2012-04-01 13:12:01,schoolfee,1,,,,,unpaid,,0.0,,,,,\r\n' |
---|
632 | ) |
---|
633 | return |
---|
634 | |
---|
635 | def test_export(self): |
---|
636 | # we can really export student payments. |
---|
637 | # set values we can expect in export file |
---|
638 | self.setup_student(self.student) |
---|
639 | payment = self.student['payments']['my-payment'] |
---|
640 | exporter = StudentPaymentsExporter() |
---|
641 | exporter.export([payment], self.outfile) |
---|
642 | result = open(self.outfile, 'rb').read() |
---|
643 | self.assertEqual( |
---|
644 | result, |
---|
645 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
646 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
647 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
648 | |
---|
649 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
650 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
651 | 'r-code,,A111111,created,2012\r\n' |
---|
652 | ) |
---|
653 | return |
---|
654 | |
---|
655 | def test_export_all(self): |
---|
656 | # we can really export all payments |
---|
657 | # set values we can expect in export file |
---|
658 | self.setup_student(self.student) |
---|
659 | exporter = StudentPaymentsExporter() |
---|
660 | exporter.export_all(self.app, self.outfile) |
---|
661 | result = open(self.outfile, 'rb').read() |
---|
662 | self.assertEqual( |
---|
663 | result, |
---|
664 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
665 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
666 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
667 | |
---|
668 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
669 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
670 | 'r-code,,A111111,created,2012\r\n' |
---|
671 | ) |
---|
672 | return |
---|
673 | |
---|
674 | def test_export_student(self): |
---|
675 | # we can really export all payments of a certain student |
---|
676 | # set values we can expect in export file |
---|
677 | self.setup_student(self.student) |
---|
678 | exporter = StudentPaymentsExporter() |
---|
679 | exporter.export_student(self.student, self.outfile) |
---|
680 | result = open(self.outfile, 'rb').read() |
---|
681 | self.assertEqual( |
---|
682 | result, |
---|
683 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
684 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
685 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
686 | |
---|
687 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
688 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
689 | 'r-code,,A111111,created,2012\r\n' |
---|
690 | ) |
---|
691 | return |
---|
692 | |
---|
693 | def test_export_filtered(self): |
---|
694 | # we can export payments of a filtered set of students |
---|
695 | self.setup_student(self.student) |
---|
696 | self.app['students'].addStudent(self.student) |
---|
697 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
698 | |
---|
699 | exporter = StudentPaymentsExporter() |
---|
700 | exporter.export_filtered( |
---|
701 | self.student, self.outfile, current_level=200) |
---|
702 | result = open(self.outfile, 'rb').read() |
---|
703 | self.assertEqual( |
---|
704 | result, |
---|
705 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
706 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
707 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
708 | |
---|
709 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
710 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
711 | 'r-code,,A111111,created,2012\r\n' |
---|
712 | ) |
---|
713 | return |
---|
714 | |
---|
715 | class BedTicketsExporterTest(StudentImportExportSetup): |
---|
716 | |
---|
717 | layer = FunctionalLayer |
---|
718 | |
---|
719 | def setUp(self): |
---|
720 | super(BedTicketsExporterTest, self).setUp() |
---|
721 | self.setup_for_export() |
---|
722 | return |
---|
723 | |
---|
724 | def test_ifaces(self): |
---|
725 | # make sure we fullfill interface contracts |
---|
726 | obj = BedTicketsExporter() |
---|
727 | verifyObject(ICSVStudentExporter, obj) |
---|
728 | verifyClass(ICSVStudentExporter, BedTicketsExporter) |
---|
729 | return |
---|
730 | |
---|
731 | def test_get_as_utility(self): |
---|
732 | # we can get a bedtickets exporter as utility |
---|
733 | result = queryUtility(ICSVExporter, name="bedtickets") |
---|
734 | self.assertTrue(result is not None) |
---|
735 | return |
---|
736 | |
---|
737 | def test_export_empty(self): |
---|
738 | # we can export a nearly empty bedticket |
---|
739 | bedticket = BedTicket() |
---|
740 | bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
741 | bedticket.bed = bed |
---|
742 | exporter = BedTicketsExporter() |
---|
743 | exporter.export([bedticket], self.outfile) |
---|
744 | result = open(self.outfile, 'rb').read() |
---|
745 | self.assertMatches( |
---|
746 | result, |
---|
747 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
748 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
749 | 'hall-1_A_101_A,,,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,,,regular_male_fr\r\n' |
---|
750 | ) |
---|
751 | return |
---|
752 | |
---|
753 | def test_export(self): |
---|
754 | # we can really export student bedtickets. |
---|
755 | # set values we can expect in export file |
---|
756 | self.setup_student(self.student) |
---|
757 | bedticket = self.student['accommodation']['2004'] |
---|
758 | exporter = BedTicketsExporter() |
---|
759 | exporter.export([bedticket], self.outfile) |
---|
760 | result = open(self.outfile, 'rb').read() |
---|
761 | self.assertMatches( |
---|
762 | result, |
---|
763 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
764 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
765 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,' |
---|
766 | 'A111111,regular_male_fr\r\n' |
---|
767 | ) |
---|
768 | return |
---|
769 | |
---|
770 | def test_export_all(self): |
---|
771 | # we can really export all bedtickets |
---|
772 | # set values we can expect in export file |
---|
773 | self.setup_student(self.student) |
---|
774 | exporter = BedTicketsExporter() |
---|
775 | exporter.export_all(self.app, self.outfile) |
---|
776 | result = open(self.outfile, 'rb').read() |
---|
777 | self.assertMatches( |
---|
778 | result, |
---|
779 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
780 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
781 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,' |
---|
782 | 'A111111,regular_male_fr\r\n' |
---|
783 | ) |
---|
784 | return |
---|
785 | |
---|
786 | def test_export_student(self): |
---|
787 | # we can really export all bedtickets of a certain student |
---|
788 | # set values we can expect in export file |
---|
789 | self.setup_student(self.student) |
---|
790 | exporter = BedTicketsExporter() |
---|
791 | exporter.export_student(self.student, self.outfile) |
---|
792 | result = open(self.outfile, 'rb').read() |
---|
793 | self.assertMatches( |
---|
794 | result, |
---|
795 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
796 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
797 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,' |
---|
798 | 'A111111,regular_male_fr\r\n' |
---|
799 | ) |
---|
800 | return |
---|
801 | |
---|
802 | def test_export_filtered(self): |
---|
803 | # we can export payments of a filtered set of students |
---|
804 | self.setup_student(self.student) |
---|
805 | self.app['students'].addStudent(self.student) |
---|
806 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
807 | |
---|
808 | exporter = BedTicketsExporter() |
---|
809 | exporter.export_filtered( |
---|
810 | self.student, self.outfile, current_level=200) |
---|
811 | result = open(self.outfile, 'rb').read() |
---|
812 | self.assertMatches( |
---|
813 | result, |
---|
814 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
815 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
816 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,' |
---|
817 | '2004,A111111,regular_male_fr\r\n') |
---|
818 | return |
---|
819 | |
---|
820 | |
---|
821 | class StudentPaymentsOverviewExporterTest(StudentImportExportSetup): |
---|
822 | |
---|
823 | layer = FunctionalLayer |
---|
824 | |
---|
825 | def setUp(self): |
---|
826 | super(StudentPaymentsOverviewExporterTest, self).setUp() |
---|
827 | self.setup_for_export() |
---|
828 | return |
---|
829 | |
---|
830 | def test_ifaces(self): |
---|
831 | # make sure we fullfill interface contracts |
---|
832 | obj = StudentPaymentsOverviewExporter() |
---|
833 | verifyObject(ICSVStudentExporter, obj) |
---|
834 | verifyClass(ICSVStudentExporter, StudentPaymentsOverviewExporter) |
---|
835 | return |
---|
836 | |
---|
837 | def test_get_as_utility(self): |
---|
838 | # we can get a payments exporter as utility |
---|
839 | result = queryUtility(ICSVExporter, name="paymentsoverview") |
---|
840 | self.assertTrue(result is not None) |
---|
841 | return |
---|
842 | |
---|
843 | def test_export(self): |
---|
844 | self.setup_student(self.student) |
---|
845 | exporter = StudentPaymentsOverviewExporter() |
---|
846 | exporter.export([self.student], self.outfile) |
---|
847 | result = open(self.outfile, 'rb').read() |
---|
848 | self.assertEqual( |
---|
849 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
850 | 'current_level,current_session,current_mode,' |
---|
851 | '%s\r\n' |
---|
852 | 'A111111,created,CERT1,NA,NA,0,200,2012,ug_ft,' |
---|
853 | ',,,,,,,,,\r\n' % year_range_str, |
---|
854 | result |
---|
855 | ) |
---|
856 | return |
---|
857 | |
---|
858 | def test_export_all(self): |
---|
859 | # we can really export students |
---|
860 | # set values we can expect in export file |
---|
861 | self.setup_student(self.student) |
---|
862 | # We add successful payments |
---|
863 | payment = StudentOnlinePayment() |
---|
864 | payment.p_id = 'my-id' |
---|
865 | payment.p_session = 2009 |
---|
866 | payment.amount_auth = 12.12 |
---|
867 | payment.p_state = u'paid' |
---|
868 | self.student['payments']['my-2ndpayment'] = payment |
---|
869 | exporter = StudentPaymentsOverviewExporter() |
---|
870 | exporter.export_all(self.app, self.outfile) |
---|
871 | result = open(self.outfile, 'rb').read() |
---|
872 | self.assertEqual( |
---|
873 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
874 | 'current_level,current_session,current_mode,' |
---|
875 | '%s\r\nA111111,created,CERT1,NA,NA,0,' |
---|
876 | '200,2012,ug_ft,,,,,,12.12,,,,\r\n' % year_range_str, |
---|
877 | result |
---|
878 | ) |
---|
879 | return |
---|
880 | |
---|
881 | class StudentStudyLevelsOverviewExporterTest(StudentImportExportSetup): |
---|
882 | |
---|
883 | layer = FunctionalLayer |
---|
884 | |
---|
885 | def setUp(self): |
---|
886 | super(StudentStudyLevelsOverviewExporterTest, self).setUp() |
---|
887 | self.setup_for_export() |
---|
888 | return |
---|
889 | |
---|
890 | def test_ifaces(self): |
---|
891 | obj = StudentStudyLevelsOverviewExporter() |
---|
892 | verifyObject(ICSVStudentExporter, obj) |
---|
893 | verifyClass(ICSVStudentExporter, StudentStudyLevelsOverviewExporter) |
---|
894 | return |
---|
895 | |
---|
896 | def test_get_as_utility(self): |
---|
897 | result = queryUtility(ICSVExporter, name="studylevelsoverview") |
---|
898 | self.assertTrue(result is not None) |
---|
899 | return |
---|
900 | |
---|
901 | def test_export(self): |
---|
902 | self.setup_student(self.student) |
---|
903 | exporter = StudentStudyLevelsOverviewExporter() |
---|
904 | exporter.export([self.student], self.outfile) |
---|
905 | result = open(self.outfile, 'rb').read() |
---|
906 | self.assertEqual( |
---|
907 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
908 | 'entry_session,current_level,current_session,' |
---|
909 | '10,100,110,120,200,210,220,300,310,320,400,410,420,500,' |
---|
910 | '510,520,600,610,620,700,710,720,800,810,820,900,910,920,999\r\n' |
---|
911 | 'A111111,created,CERT1,NA,NA,0,2010,200,2012,,2012' |
---|
912 | ',,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n', |
---|
913 | result |
---|
914 | ) |
---|
915 | return |
---|
916 | |
---|
917 | def test_export_all(self): |
---|
918 | self.setup_student(self.student) |
---|
919 | exporter = StudentStudyLevelsOverviewExporter() |
---|
920 | exporter.export_all(self.app, self.outfile) |
---|
921 | result = open(self.outfile, 'rb').read() |
---|
922 | self.assertEqual( |
---|
923 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
924 | 'entry_session,current_level,current_session,' |
---|
925 | '10,100,110,120,200,210,220,300,310,320,400,410,420,500,' |
---|
926 | '510,520,600,610,620,700,710,720,800,810,820,900,910,920,999\r\n' |
---|
927 | 'A111111,created,CERT1,NA,NA,0,2010,200,2012,,2012' |
---|
928 | ',,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n', |
---|
929 | result |
---|
930 | ) |
---|
931 | return |
---|