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