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 | class BursaryDataExporterTest(StudentImportExportSetup): |
---|
764 | |
---|
765 | layer = FunctionalLayer |
---|
766 | |
---|
767 | def setUp(self): |
---|
768 | super(BursaryDataExporterTest, self).setUp() |
---|
769 | self.setup_for_export() |
---|
770 | return |
---|
771 | |
---|
772 | def test_export_all(self): |
---|
773 | # we can really export all payments |
---|
774 | # set values we can expect in export file |
---|
775 | self.setup_student(self.student) |
---|
776 | exporter = DataForBursaryExporter() |
---|
777 | exporter.export_all(self.app, self.outfile) |
---|
778 | result = open(self.outfile, 'rb').read() |
---|
779 | self.assertEqual( |
---|
780 | result, |
---|
781 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,p_item,' |
---|
782 | 'p_level,p_session,p_state,payment_date,r_amount_approved,r_code,' |
---|
783 | 'r_desc,student_id,matric_number,firstname,middlename,lastname,' |
---|
784 | 'state,current_session,entry_session,entry_mode,faccode,depcode\r\n' |
---|
785 | |
---|
786 | '666,12.12,2012-04-01 13:12:01,schoolfee,1,my-id,p-item,100,2012,' |
---|
787 | 'paid,2012-04-01 14:12:01,12.12,r-code,,A111111,234,' |
---|
788 | 'Anna,M.,Tester,created,2012,2010,ug_ft,NA,NA\r\n' |
---|
789 | ) |
---|
790 | return |
---|
791 | |
---|
792 | class BedTicketsExporterTest(StudentImportExportSetup): |
---|
793 | |
---|
794 | layer = FunctionalLayer |
---|
795 | |
---|
796 | def setUp(self): |
---|
797 | super(BedTicketsExporterTest, self).setUp() |
---|
798 | self.setup_for_export() |
---|
799 | return |
---|
800 | |
---|
801 | def test_ifaces(self): |
---|
802 | # make sure we fullfill interface contracts |
---|
803 | obj = BedTicketsExporter() |
---|
804 | verifyObject(ICSVStudentExporter, obj) |
---|
805 | verifyClass(ICSVStudentExporter, BedTicketsExporter) |
---|
806 | return |
---|
807 | |
---|
808 | def test_get_as_utility(self): |
---|
809 | # we can get a bedtickets exporter as utility |
---|
810 | result = queryUtility(ICSVExporter, name="bedtickets") |
---|
811 | self.assertTrue(result is not None) |
---|
812 | return |
---|
813 | |
---|
814 | def test_export_empty(self): |
---|
815 | # we can export a nearly empty bedticket |
---|
816 | bedticket = BedTicket() |
---|
817 | bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
818 | bedticket.bed = bed |
---|
819 | exporter = BedTicketsExporter() |
---|
820 | exporter.export([bedticket], self.outfile) |
---|
821 | result = open(self.outfile, 'rb').read() |
---|
822 | self.assertMatches( |
---|
823 | result, |
---|
824 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
825 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
826 | 'hall-1_A_101_A,,,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,,,regular_male_fr\r\n' |
---|
827 | ) |
---|
828 | return |
---|
829 | |
---|
830 | def test_export(self): |
---|
831 | # we can really export student bedtickets. |
---|
832 | # set values we can expect in export file |
---|
833 | self.setup_student(self.student) |
---|
834 | bedticket = self.student['accommodation']['2004'] |
---|
835 | exporter = BedTicketsExporter() |
---|
836 | exporter.export([bedticket], self.outfile) |
---|
837 | result = open(self.outfile, 'rb').read() |
---|
838 | self.assertMatches( |
---|
839 | result, |
---|
840 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
841 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
842 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,' |
---|
843 | 'A111111,regular_male_fr\r\n' |
---|
844 | ) |
---|
845 | return |
---|
846 | |
---|
847 | def test_export_all(self): |
---|
848 | # we can really export all bedtickets |
---|
849 | # set values we can expect in export file |
---|
850 | self.setup_student(self.student) |
---|
851 | exporter = BedTicketsExporter() |
---|
852 | exporter.export_all(self.app, self.outfile) |
---|
853 | result = open(self.outfile, 'rb').read() |
---|
854 | self.assertMatches( |
---|
855 | result, |
---|
856 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
857 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
858 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,' |
---|
859 | 'A111111,regular_male_fr\r\n' |
---|
860 | ) |
---|
861 | return |
---|
862 | |
---|
863 | def test_export_student(self): |
---|
864 | # we can really export all bedtickets of a certain student |
---|
865 | # set values we can expect in export file |
---|
866 | self.setup_student(self.student) |
---|
867 | exporter = BedTicketsExporter() |
---|
868 | exporter.export_student(self.student, self.outfile) |
---|
869 | result = open(self.outfile, 'rb').read() |
---|
870 | self.assertMatches( |
---|
871 | result, |
---|
872 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
873 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
874 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,' |
---|
875 | 'A111111,regular_male_fr\r\n' |
---|
876 | ) |
---|
877 | return |
---|
878 | |
---|
879 | def test_export_filtered(self): |
---|
880 | # we can export payments of a filtered set of students |
---|
881 | self.setup_student(self.student) |
---|
882 | self.app['students'].addStudent(self.student) |
---|
883 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
884 | |
---|
885 | exporter = BedTicketsExporter() |
---|
886 | exporter.export_filtered( |
---|
887 | self.student, self.outfile, current_level=200) |
---|
888 | result = open(self.outfile, 'rb').read() |
---|
889 | self.assertMatches( |
---|
890 | result, |
---|
891 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
892 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
893 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,' |
---|
894 | '2004,A111111,regular_male_fr\r\n') |
---|
895 | return |
---|
896 | |
---|
897 | |
---|
898 | class StudentPaymentsOverviewExporterTest(StudentImportExportSetup): |
---|
899 | |
---|
900 | layer = FunctionalLayer |
---|
901 | |
---|
902 | def setUp(self): |
---|
903 | super(StudentPaymentsOverviewExporterTest, self).setUp() |
---|
904 | self.setup_for_export() |
---|
905 | return |
---|
906 | |
---|
907 | def test_ifaces(self): |
---|
908 | # make sure we fullfill interface contracts |
---|
909 | obj = StudentPaymentsOverviewExporter() |
---|
910 | verifyObject(ICSVStudentExporter, obj) |
---|
911 | verifyClass(ICSVStudentExporter, StudentPaymentsOverviewExporter) |
---|
912 | return |
---|
913 | |
---|
914 | def test_get_as_utility(self): |
---|
915 | # we can get a payments exporter as utility |
---|
916 | result = queryUtility(ICSVExporter, name="paymentsoverview") |
---|
917 | self.assertTrue(result is not None) |
---|
918 | return |
---|
919 | |
---|
920 | def test_export(self): |
---|
921 | self.setup_student(self.student) |
---|
922 | exporter = StudentPaymentsOverviewExporter() |
---|
923 | exporter.export([self.student], self.outfile) |
---|
924 | result = open(self.outfile, 'rb').read() |
---|
925 | self.assertTrue( |
---|
926 | 'student_id,matric_number,display_fullname,state,certcode,' |
---|
927 | 'faccode,depcode,is_postgrad,' |
---|
928 | 'current_level,current_session,current_mode,' |
---|
929 | '%s\r\n' |
---|
930 | 'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,2012,ug_ft,' |
---|
931 | % year_range_str in result |
---|
932 | ) |
---|
933 | return |
---|
934 | |
---|
935 | def test_export_all(self): |
---|
936 | # we can really export students |
---|
937 | # set values we can expect in export file |
---|
938 | self.setup_student(self.student) |
---|
939 | # We add successful payments |
---|
940 | payment = StudentOnlinePayment() |
---|
941 | payment.p_id = 'my-id' |
---|
942 | payment.p_session = 2009 |
---|
943 | payment.amount_auth = 13.13 |
---|
944 | payment.p_state = u'paid' |
---|
945 | payment.p_category = u'schoolfee' |
---|
946 | self.student['payments']['my-2ndpayment'] = payment |
---|
947 | exporter = StudentPaymentsOverviewExporter() |
---|
948 | exporter.export_all(self.app, self.outfile) |
---|
949 | result = open(self.outfile, 'rb').read() |
---|
950 | self.assertTrue( |
---|
951 | 'student_id,matric_number,display_fullname,state,' |
---|
952 | 'certcode,faccode,depcode,is_postgrad,' |
---|
953 | 'current_level,current_session,current_mode,' |
---|
954 | '%s\r\nA111111,234,Anna M. Tester,created,CERT1,NA,NA,0,' |
---|
955 | '200,2012,ug_ft' % year_range_str in result |
---|
956 | ) |
---|
957 | return |
---|
958 | |
---|
959 | class StudentStudyLevelsOverviewExporterTest(StudentImportExportSetup): |
---|
960 | |
---|
961 | layer = FunctionalLayer |
---|
962 | |
---|
963 | def setUp(self): |
---|
964 | super(StudentStudyLevelsOverviewExporterTest, self).setUp() |
---|
965 | self.setup_for_export() |
---|
966 | return |
---|
967 | |
---|
968 | def test_ifaces(self): |
---|
969 | obj = StudentStudyLevelsOverviewExporter() |
---|
970 | verifyObject(ICSVStudentExporter, obj) |
---|
971 | verifyClass(ICSVStudentExporter, StudentStudyLevelsOverviewExporter) |
---|
972 | return |
---|
973 | |
---|
974 | def test_get_as_utility(self): |
---|
975 | result = queryUtility(ICSVExporter, name="studylevelsoverview") |
---|
976 | self.assertTrue(result is not None) |
---|
977 | return |
---|
978 | |
---|
979 | def test_export(self): |
---|
980 | self.setup_student(self.student) |
---|
981 | exporter = StudentStudyLevelsOverviewExporter() |
---|
982 | exporter.export([self.student], self.outfile) |
---|
983 | result = open(self.outfile, 'rb').read() |
---|
984 | self.assertEqual( |
---|
985 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
986 | 'entry_session,current_level,current_session,' |
---|
987 | '10,100,110,120,200,210,220,300,310,320,400,410,420,500,' |
---|
988 | '510,520,600,610,620,700,710,720,800,810,820,900,910,920,999\r\n' |
---|
989 | 'A111111,created,CERT1,NA,NA,0,2010,200,2012,,2012' |
---|
990 | ',,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n', |
---|
991 | result |
---|
992 | ) |
---|
993 | return |
---|
994 | |
---|
995 | def test_export_all(self): |
---|
996 | self.setup_student(self.student) |
---|
997 | exporter = StudentStudyLevelsOverviewExporter() |
---|
998 | exporter.export_all(self.app, self.outfile) |
---|
999 | result = open(self.outfile, 'rb').read() |
---|
1000 | self.assertEqual( |
---|
1001 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
1002 | 'entry_session,current_level,current_session,' |
---|
1003 | '10,100,110,120,200,210,220,300,310,320,400,410,420,500,' |
---|
1004 | '510,520,600,610,620,700,710,720,800,810,820,900,910,920,999\r\n' |
---|
1005 | 'A111111,created,CERT1,NA,NA,0,2010,200,2012,,2012' |
---|
1006 | ',,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n', |
---|
1007 | result |
---|
1008 | ) |
---|
1009 | return |
---|
1010 | |
---|
1011 | class ComboCardExporterTest(StudentImportExportSetup): |
---|
1012 | |
---|
1013 | layer = FunctionalLayer |
---|
1014 | |
---|
1015 | def setUp(self): |
---|
1016 | super(ComboCardExporterTest, self).setUp() |
---|
1017 | self.setup_for_export() |
---|
1018 | return |
---|
1019 | |
---|
1020 | def create_passport_img(self, student): |
---|
1021 | # create some passport file for `student` |
---|
1022 | storage = getUtility(IExtFileStore) |
---|
1023 | image_path = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
1024 | self.image_contents = open(image_path, 'rb').read() |
---|
1025 | file_id = IFileStoreNameChooser(student).chooseName( |
---|
1026 | attr='passport.jpg') |
---|
1027 | storage.createFile(file_id, StringIO(self.image_contents)) |
---|
1028 | |
---|
1029 | def test_export_all(self): |
---|
1030 | self.setup_student(self.student) |
---|
1031 | self.create_passport_img(self.student) |
---|
1032 | exporter = ComboCardDataExporter() |
---|
1033 | exporter.export_all(self.app, self.outfile) |
---|
1034 | result = open(self.outfile, 'rb').read() |
---|
1035 | self.assertTrue( |
---|
1036 | 'display_fullname,student_id,matric_number,certificate,faculty,' |
---|
1037 | 'department,passport_path\r\nAnna M. Tester,A111111,234,' |
---|
1038 | 'Unnamed Certificate,Faculty of Unnamed Faculty (NA),' |
---|
1039 | 'Department of Unnamed Department (NA),' |
---|
1040 | 'students/00110/A111111/passport_A111111.jpg\r\n' |
---|
1041 | in result |
---|
1042 | ) |
---|
1043 | return |
---|