1 | ## $Id: test_export.py 15203 2018-10-28 17:30:45Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | |
---|
19 | import os |
---|
20 | import grok |
---|
21 | import datetime |
---|
22 | from cStringIO import StringIO |
---|
23 | from zope.component import queryUtility, getUtility |
---|
24 | from zope.event import notify |
---|
25 | from zope.interface.verify import verifyObject, verifyClass |
---|
26 | from waeup.kofa.interfaces import ( |
---|
27 | ICSVExporter, IExtFileStore, IFileStoreNameChooser) |
---|
28 | from waeup.kofa.students.catalog import StudentsQuery |
---|
29 | from waeup.kofa.students.export import ( |
---|
30 | StudentExporter, StudentStudyCourseExporter, StudentStudyLevelExporter, |
---|
31 | CourseTicketExporter, StudentPaymentExporter, BedTicketExporter, |
---|
32 | SchoolFeePaymentsOverviewExporter, StudentStudyLevelsOverviewExporter, |
---|
33 | ComboCardDataExporter, DataForBursaryExporter, |
---|
34 | StudentUnpaidPaymentExporter, SessionPaymentsOverviewExporter, |
---|
35 | get_students,) |
---|
36 | from waeup.kofa.students.accommodation import BedTicket |
---|
37 | from waeup.kofa.students.interfaces import ICSVStudentExporter |
---|
38 | from waeup.kofa.students.payments import StudentOnlinePayment |
---|
39 | from waeup.kofa.students.student import Student |
---|
40 | from waeup.kofa.students.studycourse import StudentStudyCourse |
---|
41 | from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket |
---|
42 | from waeup.kofa.students.tests.test_batching import StudentImportExportSetup |
---|
43 | from waeup.kofa.testing import FunctionalLayer |
---|
44 | |
---|
45 | curr_year = datetime.datetime.now().year |
---|
46 | year_range = range(curr_year - 11, curr_year + 1) |
---|
47 | year_range_str = ','.join([str(i) for i in year_range]) |
---|
48 | |
---|
49 | class ExportHelperTests(StudentImportExportSetup): |
---|
50 | layer = FunctionalLayer |
---|
51 | def setUp(self): |
---|
52 | super(ExportHelperTests, self).setUp() |
---|
53 | student = Student() |
---|
54 | self.app['students'].addStudent(student) |
---|
55 | student = self.setup_student(student) |
---|
56 | notify(grok.ObjectModifiedEvent(student)) |
---|
57 | self.student = self.app['students'][student.student_id] |
---|
58 | return |
---|
59 | |
---|
60 | def test_get_students_plain(self): |
---|
61 | # without a filter we get all students |
---|
62 | result = get_students(self.app) |
---|
63 | self.assertEqual(len(list(result)), 1) |
---|
64 | return |
---|
65 | |
---|
66 | def test_get_students_by_session(self): |
---|
67 | # we can filter out students of a certain session |
---|
68 | my_filter1 = StudentsQuery(current_session=2012) |
---|
69 | result = get_students(self.app, stud_filter=my_filter1) |
---|
70 | self.assertEqual(len(list(result)), 1) |
---|
71 | |
---|
72 | my_filter2 = StudentsQuery(current_session=1964) |
---|
73 | result = get_students(self.app, stud_filter=my_filter2) |
---|
74 | self.assertEqual(len(list(result)), 0) |
---|
75 | return |
---|
76 | |
---|
77 | def test_get_students_by_level(self): |
---|
78 | # we can filter out students of a certain level |
---|
79 | my_filter1 = StudentsQuery(current_level=200) |
---|
80 | result = get_students(self.app, stud_filter=my_filter1) |
---|
81 | self.assertEqual(len(list(result)), 1) |
---|
82 | |
---|
83 | my_filter2 = StudentsQuery(current_level=300) |
---|
84 | result = get_students(self.app, stud_filter=my_filter2) |
---|
85 | self.assertEqual(len(list(result)), 0) |
---|
86 | return |
---|
87 | |
---|
88 | def test_get_students_by_deptcode(self): |
---|
89 | # we can filter out students of a certain dept. |
---|
90 | my_filter1 = StudentsQuery(depcode='NA') |
---|
91 | result = get_students(self.app, stud_filter=my_filter1) |
---|
92 | self.assertEqual(len(list(result)), 1) |
---|
93 | |
---|
94 | my_filter2 = StudentsQuery(depcode='NOTEXISTING') |
---|
95 | result = get_students(self.app, stud_filter=my_filter2) |
---|
96 | self.assertEqual(len(list(result)), 0) |
---|
97 | return |
---|
98 | |
---|
99 | def test_get_students_by_faccode(self): |
---|
100 | # we can filter out students of a certain faculty. |
---|
101 | my_filter1 = StudentsQuery(faccode='NA') |
---|
102 | result = get_students(self.app, stud_filter=my_filter1) |
---|
103 | self.assertEqual(len(list(result)), 1) |
---|
104 | |
---|
105 | my_filter2 = StudentsQuery(faccode='NOTEXISTING') |
---|
106 | result = get_students(self.app, stud_filter=my_filter2) |
---|
107 | self.assertEqual(len(list(result)), 0) |
---|
108 | return |
---|
109 | |
---|
110 | def test_get_students_by_current_mode(self): |
---|
111 | # we can filter out students in a certain mode. |
---|
112 | my_filter1 = StudentsQuery(current_mode='ug_ft') |
---|
113 | result = get_students(self.app, stud_filter=my_filter1) |
---|
114 | self.assertEqual(len(list(result)), 1) |
---|
115 | |
---|
116 | my_filter2 = StudentsQuery(current_mode='NOTEXISTING') |
---|
117 | result = get_students(self.app, stud_filter=my_filter2) |
---|
118 | self.assertEqual(len(list(result)), 0) |
---|
119 | return |
---|
120 | |
---|
121 | |
---|
122 | class StudentExporterTest(StudentImportExportSetup): |
---|
123 | |
---|
124 | layer = FunctionalLayer |
---|
125 | |
---|
126 | std_csv_entry = ( |
---|
127 | 'my adm code,my clr code,1981-02-04#,anna@sample.com,,' |
---|
128 | 'Anna,,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,' |
---|
129 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
130 | ) |
---|
131 | |
---|
132 | def setUp(self): |
---|
133 | super(StudentExporterTest, self).setUp() |
---|
134 | self.setup_for_export() |
---|
135 | return |
---|
136 | |
---|
137 | def test_ifaces(self): |
---|
138 | # make sure we fullfill interface contracts |
---|
139 | obj = StudentExporter() |
---|
140 | verifyObject(ICSVStudentExporter, obj) |
---|
141 | verifyClass(ICSVStudentExporter, StudentExporter) |
---|
142 | return |
---|
143 | |
---|
144 | def test_get_as_utility(self): |
---|
145 | # we can get an student exporter as utility |
---|
146 | result = queryUtility(ICSVExporter, name="students") |
---|
147 | self.assertTrue(result is not None) |
---|
148 | return |
---|
149 | |
---|
150 | def test_export(self): |
---|
151 | # we can really export students |
---|
152 | # set values we can expect in export file |
---|
153 | self.setup_student(self.student) |
---|
154 | exporter = StudentExporter() |
---|
155 | exporter.export([self.student], self.outfile) |
---|
156 | result = open(self.outfile, 'rb').read() |
---|
157 | self.assertTrue( |
---|
158 | 'adm_code,clr_code,date_of_birth,email,' |
---|
159 | 'employer,firstname,flash_notice,lastname,matric_number,middlename,' |
---|
160 | 'nationality,officer_comment,perm_address,personal_updated,' |
---|
161 | 'phone,reg_number,sex,student_id,suspended,suspended_comment,' |
---|
162 | 'password,state,history,' |
---|
163 | 'certcode,is_postgrad,current_level,current_session\r\n' |
---|
164 | 'my adm code,my clr code,' |
---|
165 | '1981-02-04#,anna@sample.com,,Anna,,Tester,234,M.,NG,,' |
---|
166 | '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,123,f,' |
---|
167 | 'A111111,0,,,created' |
---|
168 | in result |
---|
169 | ) |
---|
170 | return |
---|
171 | |
---|
172 | def test_export_all(self): |
---|
173 | # we can really export students |
---|
174 | # set values we can expect in export file |
---|
175 | self.setup_student(self.student) |
---|
176 | exporter = StudentExporter() |
---|
177 | exporter.export_all(self.app, self.outfile) |
---|
178 | result = open(self.outfile, 'rb').read() |
---|
179 | self.assertTrue( |
---|
180 | 'adm_code,clr_code,date_of_birth,email,' |
---|
181 | 'employer,firstname,flash_notice,lastname,matric_number,middlename,' |
---|
182 | 'nationality,officer_comment,perm_address,personal_updated,' |
---|
183 | 'phone,reg_number,sex,student_id,suspended,suspended_comment,' |
---|
184 | 'password,state,history,certcode,' |
---|
185 | 'is_postgrad,current_level,current_session\r\n' |
---|
186 | 'my adm code,my clr code,1981-02-04#,anna@sample.com,,' |
---|
187 | 'Anna,,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n"' |
---|
188 | ',,+234-123-12345#,123,f,A111111,0,,,created' |
---|
189 | in result |
---|
190 | ) |
---|
191 | return |
---|
192 | |
---|
193 | def test_export_student(self): |
---|
194 | # we can export a single student |
---|
195 | self.setup_student(self.student) |
---|
196 | exporter = StudentExporter() |
---|
197 | exporter.export_student(self.student, self.outfile) |
---|
198 | result = open(self.outfile, 'rb').read() |
---|
199 | self.assertTrue( |
---|
200 | 'adm_code,clr_code,date_of_birth,email,' |
---|
201 | 'employer,firstname,flash_notice,lastname,matric_number,middlename,' |
---|
202 | 'nationality,officer_comment,perm_address,personal_updated,' |
---|
203 | 'phone,reg_number,sex,student_id,suspended,suspended_comment,' |
---|
204 | 'password,state,history,certcode,' |
---|
205 | 'is_postgrad,current_level,current_session\r\n' |
---|
206 | 'my adm code,my clr code,1981-02-04#,anna@sample.com,,' |
---|
207 | 'Anna,,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n"' |
---|
208 | ',,+234-123-12345#,123,f,A111111,0,,,created' |
---|
209 | in result |
---|
210 | ) |
---|
211 | return |
---|
212 | |
---|
213 | def test_export_filtered(self): |
---|
214 | # we can export a filtered set of students (filtered by session/level) |
---|
215 | self.setup_student(self.student) |
---|
216 | self.app['students'].addStudent(self.student) |
---|
217 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
218 | exporter = StudentExporter() |
---|
219 | |
---|
220 | exporter.export_filtered( |
---|
221 | self.app, self.outfile, |
---|
222 | current_session=None, current_level=None) |
---|
223 | result1 = open(self.outfile, 'rb').read() |
---|
224 | exporter.export_filtered( |
---|
225 | self.app, self.outfile, |
---|
226 | current_session=2012, current_level=None) |
---|
227 | result2 = open(self.outfile, 'rb').read() |
---|
228 | # current_level and current_session can be both a string ... |
---|
229 | exporter.export_filtered( |
---|
230 | self.app, self.outfile, |
---|
231 | current_session='2012', current_level=u'200') |
---|
232 | result3 = open(self.outfile, 'rb').read() |
---|
233 | exporter.export_filtered( |
---|
234 | self.app, self.outfile, |
---|
235 | current_session=2011, current_level=None) |
---|
236 | result4 = open(self.outfile, 'rb').read() |
---|
237 | # ... and an integer |
---|
238 | exporter.export_filtered( |
---|
239 | self.app, self.outfile, |
---|
240 | current_session=None, current_level=100) |
---|
241 | result5 = open(self.outfile, 'rb').read() |
---|
242 | # Also students at probating levels are being exported ... |
---|
243 | self.student['studycourse'].current_level = 210 |
---|
244 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
245 | exporter.export_filtered( |
---|
246 | self.app, self.outfile, |
---|
247 | current_session=None, current_level=200) |
---|
248 | result6 = open(self.outfile, 'rb').read() |
---|
249 | # ... but not in the wrong level range. |
---|
250 | self.student['studycourse'].current_level = 310 |
---|
251 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
252 | exporter.export_filtered( |
---|
253 | self.app, self.outfile, |
---|
254 | current_session=None, current_level=200) |
---|
255 | result7 = open(self.outfile, 'rb').read() |
---|
256 | self.assertTrue(self.std_csv_entry in result1) |
---|
257 | self.assertTrue(self.std_csv_entry in result2) |
---|
258 | self.assertTrue(self.std_csv_entry in result3) |
---|
259 | self.assertFalse(self.std_csv_entry in result4) |
---|
260 | self.assertFalse(self.std_csv_entry in result5) |
---|
261 | self.assertTrue(self.std_csv_entry in result6) |
---|
262 | self.assertFalse(self.std_csv_entry in result7) |
---|
263 | return |
---|
264 | |
---|
265 | def test_export_selected(self): |
---|
266 | # we can export a filtered set of students (filtered by session/level) |
---|
267 | self.setup_student(self.student) |
---|
268 | self.app['students'].addStudent(self.student) |
---|
269 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
270 | exporter = StudentExporter() |
---|
271 | exporter.export_selected( |
---|
272 | self.app, self.outfile, selected=['A111111']) |
---|
273 | result1 = open(self.outfile, 'rb').read() |
---|
274 | exporter.export_selected( |
---|
275 | self.app, self.outfile, selected=[]) |
---|
276 | result2 = open(self.outfile, 'rb').read() |
---|
277 | self.assertTrue(self.std_csv_entry in result1) |
---|
278 | self.assertFalse(self.std_csv_entry in result2) |
---|
279 | return |
---|
280 | |
---|
281 | def test_export_filtered_by_dept(self): |
---|
282 | # we can export a set of students filtered by department |
---|
283 | self.setup_student(self.student) |
---|
284 | self.app['students'].addStudent(self.student) |
---|
285 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
286 | exporter = StudentExporter() |
---|
287 | # current_session can be both a string ... |
---|
288 | exporter.export_filtered( |
---|
289 | self.app, self.outfile, |
---|
290 | current_session='2012', current_level=u'200', depcode='NA') |
---|
291 | result1 = open(self.outfile, 'rb').read() |
---|
292 | # ... and an integer |
---|
293 | exporter.export_filtered( |
---|
294 | self.app, self.outfile, |
---|
295 | current_session=2012, current_level=200, depcode='NODEPT') |
---|
296 | result2 = open(self.outfile, 'rb').read() |
---|
297 | self.assertTrue(self.std_csv_entry in result1) |
---|
298 | self.assertTrue(self.std_csv_entry not in result2) |
---|
299 | return |
---|
300 | |
---|
301 | def test_export_filtered_by_faculty(self): |
---|
302 | # we can export a set of students filtered by faculty |
---|
303 | self.setup_student(self.student) |
---|
304 | self.app['students'].addStudent(self.student) |
---|
305 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
306 | exporter = StudentExporter() |
---|
307 | |
---|
308 | exporter.export_filtered( |
---|
309 | self.app, self.outfile, |
---|
310 | current_session=2012, current_level='200', faccode='NA') |
---|
311 | result1 = open(self.outfile, 'rb').read() |
---|
312 | exporter.export_filtered( |
---|
313 | self.app, self.outfile, |
---|
314 | current_session=2012, current_level=200, faccode='NOFAC') |
---|
315 | result2 = open(self.outfile, 'rb').read() |
---|
316 | self.assertTrue(self.std_csv_entry in result1) |
---|
317 | self.assertTrue(self.std_csv_entry not in result2) |
---|
318 | return |
---|
319 | |
---|
320 | class StudentStudyCourseExporterTest(StudentImportExportSetup): |
---|
321 | |
---|
322 | layer = FunctionalLayer |
---|
323 | |
---|
324 | def setUp(self): |
---|
325 | super(StudentStudyCourseExporterTest, self).setUp() |
---|
326 | self.setup_for_export() |
---|
327 | return |
---|
328 | |
---|
329 | def test_ifaces(self): |
---|
330 | # make sure we fullfill interface contracts |
---|
331 | obj = StudentStudyCourseExporter() |
---|
332 | verifyObject(ICSVStudentExporter, obj) |
---|
333 | verifyClass(ICSVStudentExporter, StudentStudyCourseExporter) |
---|
334 | return |
---|
335 | |
---|
336 | def test_get_as_utility(self): |
---|
337 | # we can get an student exporter as utility |
---|
338 | result = queryUtility(ICSVExporter, name="studentstudycourses") |
---|
339 | self.assertTrue(result is not None) |
---|
340 | return |
---|
341 | |
---|
342 | def test_export_empty(self): |
---|
343 | # we can export a nearly empty study course |
---|
344 | study_course = StudentStudyCourse() |
---|
345 | exporter = StudentStudyCourseExporter() |
---|
346 | exporter.export([study_course], self.outfile) |
---|
347 | result = open(self.outfile, 'rb').read() |
---|
348 | self.assertEqual( |
---|
349 | result, |
---|
350 | 'certificate,current_level,current_session,current_verdict,' |
---|
351 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
352 | |
---|
353 | ',,,0,,,0,\r\n' |
---|
354 | ) |
---|
355 | return |
---|
356 | |
---|
357 | def test_export(self): |
---|
358 | # we can really export study courses. |
---|
359 | # set values we can expect in export file |
---|
360 | self.setup_student(self.student) |
---|
361 | study_course = self.student.get('studycourse') |
---|
362 | exporter = StudentStudyCourseExporter() |
---|
363 | exporter.export([study_course], self.outfile) |
---|
364 | result = open(self.outfile, 'rb').read() |
---|
365 | self.assertEqual( |
---|
366 | result, |
---|
367 | 'certificate,current_level,current_session,current_verdict,' |
---|
368 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
369 | |
---|
370 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
371 | ) |
---|
372 | return |
---|
373 | |
---|
374 | def test_export_all(self): |
---|
375 | # we can really export students |
---|
376 | # set values we can expect in export file |
---|
377 | self.setup_student(self.student) |
---|
378 | exporter = StudentStudyCourseExporter() |
---|
379 | exporter.export_all(self.app, self.outfile) |
---|
380 | result = open(self.outfile, 'rb').read() |
---|
381 | self.assertEqual( |
---|
382 | result, |
---|
383 | 'certificate,current_level,current_session,current_verdict,' |
---|
384 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
385 | |
---|
386 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
387 | ) |
---|
388 | return |
---|
389 | |
---|
390 | def test_export_student(self): |
---|
391 | # we can export studycourse of a certain student |
---|
392 | self.setup_student(self.student) |
---|
393 | exporter = StudentStudyCourseExporter() |
---|
394 | exporter.export_student(self.student, self.outfile) |
---|
395 | result = open(self.outfile, 'rb').read() |
---|
396 | self.assertEqual( |
---|
397 | result, |
---|
398 | 'certificate,current_level,current_session,current_verdict,' |
---|
399 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
400 | |
---|
401 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
402 | ) |
---|
403 | return |
---|
404 | |
---|
405 | def test_export_filtered(self): |
---|
406 | # we can export studycourses of a filtered set of students |
---|
407 | self.setup_student(self.student) |
---|
408 | self.app['students'].addStudent(self.student) |
---|
409 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
410 | |
---|
411 | exporter = StudentStudyCourseExporter() |
---|
412 | exporter.export_filtered( |
---|
413 | self.student, self.outfile, current_session=2012) |
---|
414 | result = open(self.outfile, 'rb').read() |
---|
415 | self.assertEqual( |
---|
416 | result, |
---|
417 | 'certificate,current_level,current_session,current_verdict,' |
---|
418 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
419 | |
---|
420 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
421 | ) |
---|
422 | return |
---|
423 | |
---|
424 | def test_export_selected_student_id(self): |
---|
425 | # we can export a filtered set of students (filtered by session/level) |
---|
426 | self.setup_student(self.student) |
---|
427 | self.app['students'].addStudent(self.student) |
---|
428 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
429 | exporter = StudentStudyCourseExporter() |
---|
430 | exporter.export_selected( |
---|
431 | self.app, self.outfile, selected=['A111111']) |
---|
432 | result = open(self.outfile, 'rb').read() |
---|
433 | self.assertEqual( |
---|
434 | result, |
---|
435 | 'certificate,current_level,current_session,current_verdict,' |
---|
436 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
437 | |
---|
438 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
439 | ) |
---|
440 | return |
---|
441 | |
---|
442 | def test_export_selected_matric_number(self): |
---|
443 | # we can export a filtered set of students (filtered by session/level) |
---|
444 | self.setup_student(self.student) |
---|
445 | self.app['students'].addStudent(self.student) |
---|
446 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
447 | exporter = StudentStudyCourseExporter() |
---|
448 | exporter.export_selected( |
---|
449 | self.app, self.outfile, selected=['234']) |
---|
450 | result = open(self.outfile, 'rb').read() |
---|
451 | self.assertEqual( |
---|
452 | result, |
---|
453 | 'certificate,current_level,current_session,current_verdict,' |
---|
454 | 'entry_mode,entry_session,previous_verdict,student_id\r\n' |
---|
455 | |
---|
456 | 'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n' |
---|
457 | ) |
---|
458 | return |
---|
459 | |
---|
460 | |
---|
461 | class StudentStudyLevelExporterTest(StudentImportExportSetup): |
---|
462 | |
---|
463 | layer = FunctionalLayer |
---|
464 | |
---|
465 | def setUp(self): |
---|
466 | super(StudentStudyLevelExporterTest, self).setUp() |
---|
467 | self.setup_for_export() |
---|
468 | return |
---|
469 | |
---|
470 | def test_ifaces(self): |
---|
471 | # make sure we fullfill interface contracts |
---|
472 | obj = StudentStudyLevelExporter() |
---|
473 | verifyObject(ICSVStudentExporter, obj) |
---|
474 | verifyClass(ICSVStudentExporter, StudentStudyLevelExporter) |
---|
475 | return |
---|
476 | |
---|
477 | def test_get_as_utility(self): |
---|
478 | # we can get an student exporter as utility |
---|
479 | result = queryUtility(ICSVExporter, name="studentstudylevels") |
---|
480 | self.assertTrue(result is not None) |
---|
481 | return |
---|
482 | |
---|
483 | def test_export_empty(self): |
---|
484 | # we can export a nearly empty study level |
---|
485 | study_level = StudentStudyLevel() |
---|
486 | exporter = StudentStudyLevelExporter() |
---|
487 | exporter.export([study_level], self.outfile) |
---|
488 | result = open(self.outfile, 'rb').read() |
---|
489 | self.assertEqual( |
---|
490 | result, |
---|
491 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
492 | 'validated_by,validation_date,' |
---|
493 | 'student_id,number_of_tickets,certcode\r\n' |
---|
494 | '0.00,,,0,0,,,,0,\r\n' |
---|
495 | ) |
---|
496 | return |
---|
497 | |
---|
498 | def test_export(self): |
---|
499 | # we can really export study levels. |
---|
500 | # set values we can expect in export file |
---|
501 | self.setup_student(self.student) |
---|
502 | study_course = self.student.get('studycourse') |
---|
503 | study_level = study_course[study_course.keys()[0]] |
---|
504 | exporter = StudentStudyLevelExporter() |
---|
505 | exporter.export([study_level], self.outfile) |
---|
506 | result = open(self.outfile, 'rb').read() |
---|
507 | self.assertEqual( |
---|
508 | result, |
---|
509 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
510 | 'validated_by,validation_date,' |
---|
511 | 'student_id,number_of_tickets,certcode\r\n' |
---|
512 | '0.00,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
513 | ) |
---|
514 | return |
---|
515 | |
---|
516 | def test_export_all(self): |
---|
517 | # we can really export study levels |
---|
518 | # set values we can expect in export file |
---|
519 | self.setup_student(self.student) |
---|
520 | exporter = StudentStudyLevelExporter() |
---|
521 | exporter.export_all(self.app, self.outfile) |
---|
522 | result = open(self.outfile, 'rb').read() |
---|
523 | self.assertEqual( |
---|
524 | result, |
---|
525 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
526 | 'validated_by,validation_date,' |
---|
527 | 'student_id,number_of_tickets,certcode\r\n' |
---|
528 | '0.00,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
529 | ) |
---|
530 | return |
---|
531 | |
---|
532 | def test_export_student(self): |
---|
533 | # we can really export study levels of a certain student |
---|
534 | self.setup_student(self.student) |
---|
535 | exporter = StudentStudyLevelExporter() |
---|
536 | exporter.export_student(self.student, self.outfile) |
---|
537 | result = open(self.outfile, 'rb').read() |
---|
538 | self.assertEqual( |
---|
539 | result, |
---|
540 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
541 | 'validated_by,validation_date,' |
---|
542 | 'student_id,number_of_tickets,certcode\r\n' |
---|
543 | '0.00,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
544 | ) |
---|
545 | return |
---|
546 | |
---|
547 | def test_export_filtered(self): |
---|
548 | # we can export studylevels of a filtered set of students |
---|
549 | self.setup_student(self.student) |
---|
550 | self.app['students'].addStudent(self.student) |
---|
551 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
552 | |
---|
553 | exporter = StudentStudyLevelExporter() |
---|
554 | exporter.export_filtered( |
---|
555 | self.student, self.outfile) |
---|
556 | result = open(self.outfile, 'rb').read() |
---|
557 | self.assertEqual( |
---|
558 | result, |
---|
559 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
560 | 'validated_by,validation_date,' |
---|
561 | 'student_id,number_of_tickets,certcode\r\n' |
---|
562 | '0.00,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
563 | ) |
---|
564 | return |
---|
565 | |
---|
566 | def test_export_selected(self): |
---|
567 | # we can export studylevels of a filtered set of students |
---|
568 | self.setup_student(self.student) |
---|
569 | self.app['students'].addStudent(self.student) |
---|
570 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
571 | |
---|
572 | exporter = StudentStudyLevelExporter() |
---|
573 | exporter.export_selected( |
---|
574 | self.app, self.outfile, selected=['A111111']) |
---|
575 | result = open(self.outfile, 'rb').read() |
---|
576 | self.assertEqual( |
---|
577 | result, |
---|
578 | 'gpa,level,level_session,level_verdict,total_credits,' |
---|
579 | 'validated_by,validation_date,' |
---|
580 | 'student_id,number_of_tickets,certcode\r\n' |
---|
581 | '0.00,100,2012,A,100,,,A111111,1,CERT1\r\n' |
---|
582 | ) |
---|
583 | return |
---|
584 | |
---|
585 | class CourseTicketExporterTest(StudentImportExportSetup): |
---|
586 | |
---|
587 | layer = FunctionalLayer |
---|
588 | |
---|
589 | def setUp(self): |
---|
590 | super(CourseTicketExporterTest, self).setUp() |
---|
591 | self.setup_for_export() |
---|
592 | return |
---|
593 | |
---|
594 | def test_ifaces(self): |
---|
595 | # make sure we fullfill interface contracts |
---|
596 | obj = CourseTicketExporter() |
---|
597 | verifyObject(ICSVStudentExporter, obj) |
---|
598 | verifyClass(ICSVStudentExporter, CourseTicketExporter) |
---|
599 | return |
---|
600 | |
---|
601 | def test_get_as_utility(self): |
---|
602 | # we can get an student exporter as utility |
---|
603 | result = queryUtility(ICSVExporter, name="coursetickets") |
---|
604 | self.assertTrue(result is not None) |
---|
605 | return |
---|
606 | |
---|
607 | def test_export_empty(self): |
---|
608 | # we can export a nearly empty course ticket |
---|
609 | ticket = CourseTicket() |
---|
610 | exporter = CourseTicketExporter() |
---|
611 | exporter.export([ticket], self.outfile) |
---|
612 | result = open(self.outfile, 'rb').read() |
---|
613 | self.assertEqual( |
---|
614 | result, |
---|
615 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
616 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
617 | 'display_fullname\r\n' |
---|
618 | '0,0,,,,,,,,0,0,,,,,,,,\r\n' |
---|
619 | ) |
---|
620 | return |
---|
621 | |
---|
622 | def test_export(self): |
---|
623 | # we can really export course tickets. |
---|
624 | # set values we can expect in export file |
---|
625 | self.setup_student(self.student) |
---|
626 | study_course = self.student.get('studycourse') |
---|
627 | study_level = study_course[study_course.keys()[0]] |
---|
628 | ticket = study_level['CRS1'] |
---|
629 | exporter = CourseTicketExporter() |
---|
630 | exporter.export([ticket], self.outfile) |
---|
631 | result = open(self.outfile, 'rb').read() |
---|
632 | self.assertEqual( |
---|
633 | result, |
---|
634 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
635 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
636 | 'display_fullname\r\n' |
---|
637 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
638 | 'Anna M. Tester\r\n' |
---|
639 | ) |
---|
640 | return |
---|
641 | |
---|
642 | def test_export_all(self): |
---|
643 | # we can really export all course tickets |
---|
644 | # set values we can expect in export file |
---|
645 | self.setup_student(self.student) |
---|
646 | exporter = CourseTicketExporter() |
---|
647 | exporter.export_all(self.app, self.outfile) |
---|
648 | result = open(self.outfile, 'rb').read() |
---|
649 | self.assertEqual( |
---|
650 | result, |
---|
651 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
652 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
653 | 'display_fullname\r\n' |
---|
654 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
655 | 'Anna M. Tester\r\n' |
---|
656 | ) |
---|
657 | return |
---|
658 | |
---|
659 | def test_export_student(self): |
---|
660 | # we can really export all course tickets of a certain student |
---|
661 | self.setup_student(self.student) |
---|
662 | exporter = CourseTicketExporter() |
---|
663 | exporter.export_student(self.student, self.outfile) |
---|
664 | result = open(self.outfile, 'rb').read() |
---|
665 | self.assertEqual( |
---|
666 | result, |
---|
667 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
668 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
669 | 'display_fullname\r\n' |
---|
670 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
671 | 'Anna M. Tester\r\n' |
---|
672 | ) |
---|
673 | return |
---|
674 | |
---|
675 | def test_export_filtered(self): |
---|
676 | # we can export course tickets of a filtered set of students |
---|
677 | self.setup_student(self.student) |
---|
678 | self.app['students'].addStudent(self.student) |
---|
679 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
680 | |
---|
681 | exporter = CourseTicketExporter() |
---|
682 | exporter.export_filtered(self.student, self.outfile) |
---|
683 | result = open(self.outfile, 'rb').read() |
---|
684 | self.assertEqual( |
---|
685 | result, |
---|
686 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
687 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
688 | 'display_fullname\r\n' |
---|
689 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
690 | 'Anna M. Tester\r\n' |
---|
691 | ) |
---|
692 | # We can set the course tickets level and level_session without code |
---|
693 | # (used in the datacenter) |
---|
694 | notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1'])) |
---|
695 | exporter.export_filtered(self.student, self.outfile, ct_level='100', |
---|
696 | ct_session='2012') |
---|
697 | result = open(self.outfile, 'rb').read() |
---|
698 | self.assertEqual( |
---|
699 | result, |
---|
700 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
701 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
702 | 'display_fullname\r\n' |
---|
703 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
704 | 'Anna M. Tester\r\n' |
---|
705 | ) |
---|
706 | # 'all' does select all |
---|
707 | notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1'])) |
---|
708 | exporter.export_filtered(self.student, self.outfile, ct_level='all', |
---|
709 | ct_session='2012') |
---|
710 | result = open(self.outfile, 'rb').read() |
---|
711 | self.assertEqual( |
---|
712 | result, |
---|
713 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
714 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
715 | 'display_fullname\r\n' |
---|
716 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
717 | 'Anna M. Tester\r\n' |
---|
718 | ) |
---|
719 | # Level 200 tickets do not exist. |
---|
720 | notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1'])) |
---|
721 | exporter.export_filtered(self.student, self.outfile, ct_level='200') |
---|
722 | result = open(self.outfile, 'rb').read() |
---|
723 | self.assertEqual( |
---|
724 | result, |
---|
725 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
726 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
727 | 'display_fullname\r\n' |
---|
728 | ) |
---|
729 | # Session 2013 tickets do not exist. |
---|
730 | notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1'])) |
---|
731 | exporter.export_filtered(self.student, self.outfile, |
---|
732 | ct_level='all', ct_session='2013') |
---|
733 | result = open(self.outfile, 'rb').read() |
---|
734 | self.assertEqual( |
---|
735 | result, |
---|
736 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
737 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
738 | 'display_fullname\r\n' |
---|
739 | ) |
---|
740 | # If the coursetickets catalog is used to filter students |
---|
741 | # and (course) code is not None |
---|
742 | # only course tickets which belong to this course are exported |
---|
743 | exporter.export_filtered( |
---|
744 | self.student, self.outfile, catalog='coursetickets', code='CRS1') |
---|
745 | result = open(self.outfile, 'rb').read() |
---|
746 | self.assertEqual( |
---|
747 | result, |
---|
748 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
749 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
750 | 'display_fullname\r\n' |
---|
751 | '1,1,CRS1,,100,DEP1,FAC1,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
752 | 'Anna M. Tester\r\n' |
---|
753 | ) |
---|
754 | exporter.export_filtered( |
---|
755 | self.student, self.outfile, catalog='coursetickets', code='any code') |
---|
756 | result = open(self.outfile, 'rb').read() |
---|
757 | self.assertEqual( |
---|
758 | result, |
---|
759 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
760 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
761 | 'display_fullname\r\n' |
---|
762 | ) |
---|
763 | # Also tickets in probating levels are exported. Therefore |
---|
764 | # we change the level attribute to fake a 110 level. |
---|
765 | self.student['studycourse']['100'].level = 110 |
---|
766 | notify(grok.ObjectModifiedEvent(self.student['studycourse']['100']['CRS1'])) |
---|
767 | exporter.export_filtered( |
---|
768 | self.student, self.outfile, catalog='coursetickets', code='CRS1', level='100') |
---|
769 | result = open(self.outfile, 'rb').read() |
---|
770 | self.assertEqual( |
---|
771 | result, |
---|
772 | 'automatic,carry_over,code,course_category,credits,dcode,fcode,level,level_session,' |
---|
773 | 'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,' |
---|
774 | 'display_fullname\r\n' |
---|
775 | '1,1,CRS1,,100,DEP1,FAC1,110,2012,0,0,100,,2,,Course 1,A111111,CERT1,' |
---|
776 | 'Anna M. Tester\r\n' |
---|
777 | ) |
---|
778 | return |
---|
779 | |
---|
780 | class StudentPaymentExporterTest(StudentImportExportSetup): |
---|
781 | |
---|
782 | layer = FunctionalLayer |
---|
783 | |
---|
784 | def setUp(self): |
---|
785 | super(StudentPaymentExporterTest, self).setUp() |
---|
786 | self.setup_for_export() |
---|
787 | return |
---|
788 | |
---|
789 | def test_ifaces(self): |
---|
790 | # make sure we fullfill interface contracts |
---|
791 | obj = StudentPaymentExporter() |
---|
792 | verifyObject(ICSVStudentExporter, obj) |
---|
793 | verifyClass(ICSVStudentExporter, StudentPaymentExporter) |
---|
794 | return |
---|
795 | |
---|
796 | def test_get_as_utility(self): |
---|
797 | # we can get a payments exporter as utility |
---|
798 | result = queryUtility(ICSVExporter, name="studentpayments") |
---|
799 | self.assertTrue(result is not None) |
---|
800 | return |
---|
801 | |
---|
802 | def test_export_empty(self): |
---|
803 | # we can export a nearly empty payment |
---|
804 | payment = StudentOnlinePayment() |
---|
805 | payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1) |
---|
806 | exporter = StudentPaymentExporter() |
---|
807 | exporter.export([payment], self.outfile) |
---|
808 | result = open(self.outfile, 'rb').read() |
---|
809 | self.assertEqual( |
---|
810 | result, |
---|
811 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
812 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
813 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
814 | |
---|
815 | ',0.0,2012-04-01 13:12:01#,,1,,,,,unpaid,,0.0,,,,,\r\n' |
---|
816 | ) |
---|
817 | return |
---|
818 | |
---|
819 | def test_export(self): |
---|
820 | # we can really export student payments. |
---|
821 | # set values we can expect in export file |
---|
822 | self.setup_student(self.student) |
---|
823 | payment = self.student['payments']['my-payment'] |
---|
824 | exporter = StudentPaymentExporter() |
---|
825 | exporter.export([payment], self.outfile) |
---|
826 | result = open(self.outfile, 'rb').read() |
---|
827 | self.assertEqual( |
---|
828 | result, |
---|
829 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
830 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
831 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
832 | |
---|
833 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,' |
---|
834 | 'p-item,100,%s,paid,%s-04-01 14:12:01#,12.12,' |
---|
835 | 'r-code,,A111111,created,2012\r\n' |
---|
836 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
837 | ) |
---|
838 | return |
---|
839 | |
---|
840 | def test_export_all(self): |
---|
841 | # we can really export all payments |
---|
842 | # set values we can expect in export file |
---|
843 | self.setup_student(self.student) |
---|
844 | exporter = StudentPaymentExporter() |
---|
845 | exporter.export_all(self.app, self.outfile) |
---|
846 | result = open(self.outfile, 'rb').read() |
---|
847 | self.assertEqual( |
---|
848 | result, |
---|
849 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
850 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
851 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
852 | |
---|
853 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,' |
---|
854 | 'p-item,100,%s,paid,%s-04-01 14:12:01#,12.12,' |
---|
855 | 'r-code,,A111111,created,2012\r\n' |
---|
856 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
857 | ) |
---|
858 | return |
---|
859 | |
---|
860 | def test_export_student(self): |
---|
861 | # we can really export all payments of a certain student |
---|
862 | # set values we can expect in export file |
---|
863 | self.setup_student(self.student) |
---|
864 | exporter = StudentPaymentExporter() |
---|
865 | exporter.export_student(self.student, self.outfile) |
---|
866 | result = open(self.outfile, 'rb').read() |
---|
867 | self.assertEqual( |
---|
868 | result, |
---|
869 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
870 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
871 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
872 | |
---|
873 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,' |
---|
874 | 'p-item,100,%s,paid,%s-04-01 14:12:01#,12.12,' |
---|
875 | 'r-code,,A111111,created,2012\r\n' |
---|
876 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
877 | ) |
---|
878 | return |
---|
879 | |
---|
880 | def test_export_filtered(self): |
---|
881 | # we can export payments of a filtered set of students |
---|
882 | self.setup_student(self.student) |
---|
883 | self.app['students'].addStudent(self.student) |
---|
884 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
885 | |
---|
886 | exporter = StudentPaymentExporter() |
---|
887 | exporter.export_filtered( |
---|
888 | self.student, self.outfile, current_level=200) |
---|
889 | result = open(self.outfile, 'rb').read() |
---|
890 | self.assertEqual( |
---|
891 | result, |
---|
892 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
893 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
894 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
895 | |
---|
896 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,' |
---|
897 | 'p-item,100,%s,paid,%s-04-01 14:12:01#,12.12,' |
---|
898 | 'r-code,,A111111,created,2012\r\n' |
---|
899 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
900 | ) |
---|
901 | return |
---|
902 | |
---|
903 | def test_export_filtered_by_date(self): |
---|
904 | # payments_start and payments_end are being ignored |
---|
905 | self.setup_student(self.student) |
---|
906 | self.app['students'].addStudent(self.student) |
---|
907 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
908 | exporter = StudentPaymentExporter() |
---|
909 | # A key xxx does not exist |
---|
910 | self.assertRaises( |
---|
911 | KeyError, exporter.export_filtered, self.app, self.outfile, |
---|
912 | current_session=None, |
---|
913 | current_level=None, xxx='nonsense') |
---|
914 | # payments_start and payments_end do exist but must match format '%Y-%m-%d' |
---|
915 | self.assertRaises( |
---|
916 | ValueError, exporter.export_filtered, self.app, self.outfile, |
---|
917 | current_session=None, current_level=None, |
---|
918 | payments_start='nonsense', payments_end='nonsense') |
---|
919 | # If they match the format they are ignored by get_filtered and the |
---|
920 | # exporter works properly. |
---|
921 | # Attention: End day is included! |
---|
922 | exporter.export_filtered( |
---|
923 | self.app, self.outfile, |
---|
924 | current_session=None, current_level=None, |
---|
925 | payments_start='01/04/%s' % (curr_year-6), |
---|
926 | payments_end='01/04/%s' % (curr_year-6)) |
---|
927 | result = open(self.outfile, 'rb').read() |
---|
928 | self.assertEqual( |
---|
929 | result, |
---|
930 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
931 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
932 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
933 | |
---|
934 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,' |
---|
935 | 'p-item,100,%s,paid,%s-04-01 14:12:01#,12.12,' |
---|
936 | 'r-code,,A111111,created,2012\r\n' |
---|
937 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
938 | ) |
---|
939 | # Payment date is 2012-04-01, 14:12:01. |
---|
940 | # No results if payment_date is outside the given period. |
---|
941 | exporter.export_filtered( |
---|
942 | self.app, self.outfile, |
---|
943 | current_session=None, current_level=None, |
---|
944 | payments_start='30/03/2012', payments_end='31/03/2012') |
---|
945 | result = open(self.outfile, 'rb').read() |
---|
946 | self.assertEqual( |
---|
947 | result, |
---|
948 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
949 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
950 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
951 | ) |
---|
952 | exporter.export_filtered( |
---|
953 | self.app, self.outfile, |
---|
954 | current_session=None, current_level=None, |
---|
955 | payments_start='02/04/2012', payments_end='03/04/2012') |
---|
956 | result = open(self.outfile, 'rb').read() |
---|
957 | self.assertEqual( |
---|
958 | result, |
---|
959 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
960 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
961 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
962 | ) |
---|
963 | # No results if payment_date is not set |
---|
964 | self.payment.payment_date = None |
---|
965 | exporter.export_filtered( |
---|
966 | self.app, self.outfile, |
---|
967 | current_session=None, current_level=None, |
---|
968 | payments_start='31/03/2012', payments_end='02/04/2012') |
---|
969 | result = open(self.outfile, 'rb').read() |
---|
970 | self.assertEqual( |
---|
971 | result, |
---|
972 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
973 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
974 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
975 | ) |
---|
976 | return |
---|
977 | |
---|
978 | class StudentUnpaidPaymentExporterTest(StudentImportExportSetup): |
---|
979 | |
---|
980 | layer = FunctionalLayer |
---|
981 | |
---|
982 | def setUp(self): |
---|
983 | super(StudentUnpaidPaymentExporterTest, self).setUp() |
---|
984 | self.setup_for_export() |
---|
985 | return |
---|
986 | |
---|
987 | def test_export_all(self): |
---|
988 | # we can really export all payments |
---|
989 | # set values we can expect in export file |
---|
990 | self.setup_student(self.student) |
---|
991 | exporter = StudentUnpaidPaymentExporter() |
---|
992 | exporter.export_all(self.app, self.outfile) |
---|
993 | result = open(self.outfile, 'rb').read() |
---|
994 | # No unpaid ticket exists |
---|
995 | self.assertEqual( |
---|
996 | result, |
---|
997 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
998 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
999 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
1000 | ) |
---|
1001 | # Make ticket unpaid |
---|
1002 | self.payment.p_state = 'unpaid' |
---|
1003 | exporter.export_all(self.app, self.outfile) |
---|
1004 | result = open(self.outfile, 'rb').read() |
---|
1005 | self.assertEqual( |
---|
1006 | result, |
---|
1007 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
1008 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
1009 | 'r_code,r_desc,student_id,state,current_session\r\n' |
---|
1010 | |
---|
1011 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,' |
---|
1012 | 'p-item,100,%s,unpaid,%s-04-01 14:12:01#,12.12,' |
---|
1013 | 'r-code,,A111111,created,2012\r\n' |
---|
1014 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
1015 | ) |
---|
1016 | return |
---|
1017 | |
---|
1018 | class BursaryDataExporterTest(StudentImportExportSetup): |
---|
1019 | |
---|
1020 | layer = FunctionalLayer |
---|
1021 | |
---|
1022 | def setUp(self): |
---|
1023 | super(BursaryDataExporterTest, self).setUp() |
---|
1024 | self.setup_for_export() |
---|
1025 | return |
---|
1026 | |
---|
1027 | def test_export_all(self): |
---|
1028 | # we can really export all payments |
---|
1029 | # set values we can expect in export file |
---|
1030 | self.setup_student(self.student) |
---|
1031 | exporter = DataForBursaryExporter() |
---|
1032 | exporter.export_all(self.app, self.outfile) |
---|
1033 | result = open(self.outfile, 'rb').read() |
---|
1034 | self.assertEqual( |
---|
1035 | result, |
---|
1036 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,p_item,' |
---|
1037 | 'p_level,p_session,p_state,payment_date,r_amount_approved,r_code,' |
---|
1038 | 'r_desc,student_id,matric_number,reg_number,firstname,middlename,lastname,' |
---|
1039 | 'state,current_session,entry_session,entry_mode,faccode,depcode,certcode\r\n' |
---|
1040 | |
---|
1041 | '666,12.12,%s-04-01 13:12:01#,schoolfee,1,my-id,p-item,100,%s,' |
---|
1042 | 'paid,%s-04-01 14:12:01#,12.12,r-code,,A111111,234,123,' |
---|
1043 | 'Anna,M.,Tester,created,2012,2010,ug_ft,NA,NA,CERT1\r\n' |
---|
1044 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
1045 | ) |
---|
1046 | return |
---|
1047 | |
---|
1048 | class BedTicketExporterTest(StudentImportExportSetup): |
---|
1049 | |
---|
1050 | layer = FunctionalLayer |
---|
1051 | |
---|
1052 | def setUp(self): |
---|
1053 | super(BedTicketExporterTest, self).setUp() |
---|
1054 | self.setup_for_export() |
---|
1055 | return |
---|
1056 | |
---|
1057 | def test_ifaces(self): |
---|
1058 | # make sure we fullfill interface contracts |
---|
1059 | obj = BedTicketExporter() |
---|
1060 | verifyObject(ICSVStudentExporter, obj) |
---|
1061 | verifyClass(ICSVStudentExporter, BedTicketExporter) |
---|
1062 | return |
---|
1063 | |
---|
1064 | def test_get_as_utility(self): |
---|
1065 | # we can get a bedtickets exporter as utility |
---|
1066 | result = queryUtility(ICSVExporter, name="bedtickets") |
---|
1067 | self.assertTrue(result is not None) |
---|
1068 | return |
---|
1069 | |
---|
1070 | def test_export_empty(self): |
---|
1071 | # we can export a nearly empty bedticket |
---|
1072 | bedticket = BedTicket() |
---|
1073 | bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] |
---|
1074 | bedticket.bed = bed |
---|
1075 | exporter = BedTicketExporter() |
---|
1076 | exporter.export([bedticket], self.outfile) |
---|
1077 | result = open(self.outfile, 'rb').read() |
---|
1078 | self.assertMatches( |
---|
1079 | result, |
---|
1080 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
1081 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
1082 | 'hall-1_A_101_A,,,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>#,,,regular_male_fr\r\n' |
---|
1083 | ) |
---|
1084 | return |
---|
1085 | |
---|
1086 | def test_export(self): |
---|
1087 | # we can really export student bedtickets. |
---|
1088 | # set values we can expect in export file |
---|
1089 | self.setup_student(self.student) |
---|
1090 | bedticket = self.student['accommodation']['2004'] |
---|
1091 | exporter = BedTicketExporter() |
---|
1092 | exporter.export([bedticket], self.outfile) |
---|
1093 | result = open(self.outfile, 'rb').read() |
---|
1094 | self.assertMatches( |
---|
1095 | result, |
---|
1096 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
1097 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
1098 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>#,2004,' |
---|
1099 | 'A111111,regular_male_fr\r\n' |
---|
1100 | ) |
---|
1101 | return |
---|
1102 | |
---|
1103 | def test_export_all(self): |
---|
1104 | # we can really export all bedtickets |
---|
1105 | # set values we can expect in export file |
---|
1106 | self.setup_student(self.student) |
---|
1107 | exporter = BedTicketExporter() |
---|
1108 | exporter.export_all(self.app, self.outfile) |
---|
1109 | result = open(self.outfile, 'rb').read() |
---|
1110 | self.assertMatches( |
---|
1111 | result, |
---|
1112 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
1113 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
1114 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>#,2004,' |
---|
1115 | 'A111111,regular_male_fr\r\n' |
---|
1116 | ) |
---|
1117 | return |
---|
1118 | |
---|
1119 | def test_export_student(self): |
---|
1120 | # we can really export all bedtickets of a certain student |
---|
1121 | # set values we can expect in export file |
---|
1122 | self.setup_student(self.student) |
---|
1123 | exporter = BedTicketExporter() |
---|
1124 | exporter.export_student(self.student, self.outfile) |
---|
1125 | result = open(self.outfile, 'rb').read() |
---|
1126 | self.assertMatches( |
---|
1127 | result, |
---|
1128 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
1129 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
1130 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>#,2004,' |
---|
1131 | 'A111111,regular_male_fr\r\n' |
---|
1132 | ) |
---|
1133 | return |
---|
1134 | |
---|
1135 | def test_export_filtered(self): |
---|
1136 | # we can export payments of a filtered set of students |
---|
1137 | self.setup_student(self.student) |
---|
1138 | self.app['students'].addStudent(self.student) |
---|
1139 | notify(grok.ObjectModifiedEvent(self.student)) |
---|
1140 | |
---|
1141 | exporter = BedTicketExporter() |
---|
1142 | exporter.export_filtered( |
---|
1143 | self.student, self.outfile, current_level=200) |
---|
1144 | result = open(self.outfile, 'rb').read() |
---|
1145 | self.assertMatches( |
---|
1146 | result, |
---|
1147 | 'bed,bed_coordinates,bed_type,booking_code,booking_date,' |
---|
1148 | 'booking_session,student_id,actual_bed_type\r\n' |
---|
1149 | 'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>#,' |
---|
1150 | '2004,A111111,regular_male_fr\r\n') |
---|
1151 | return |
---|
1152 | |
---|
1153 | |
---|
1154 | class SchoolFeePaymentsOverviewExporterTest(StudentImportExportSetup): |
---|
1155 | |
---|
1156 | layer = FunctionalLayer |
---|
1157 | |
---|
1158 | def setUp(self): |
---|
1159 | super(SchoolFeePaymentsOverviewExporterTest, self).setUp() |
---|
1160 | self.setup_for_export() |
---|
1161 | return |
---|
1162 | |
---|
1163 | def test_ifaces(self): |
---|
1164 | # make sure we fullfill interface contracts |
---|
1165 | obj = SchoolFeePaymentsOverviewExporter() |
---|
1166 | verifyObject(ICSVStudentExporter, obj) |
---|
1167 | verifyClass(ICSVStudentExporter, SchoolFeePaymentsOverviewExporter) |
---|
1168 | return |
---|
1169 | |
---|
1170 | def test_get_as_utility(self): |
---|
1171 | # we can get a payments exporter as utility |
---|
1172 | result = queryUtility(ICSVExporter, name="sfpaymentsoverview") |
---|
1173 | self.assertTrue(result is not None) |
---|
1174 | return |
---|
1175 | |
---|
1176 | def test_export(self): |
---|
1177 | self.setup_student(self.student) |
---|
1178 | exporter = SchoolFeePaymentsOverviewExporter() |
---|
1179 | exporter.export([self.student], self.outfile) |
---|
1180 | result = open(self.outfile, 'rb').read() |
---|
1181 | self.assertTrue( |
---|
1182 | 'student_id,matric_number,display_fullname,state,certcode,' |
---|
1183 | 'faccode,depcode,is_postgrad,' |
---|
1184 | 'current_level,current_session,current_mode,entry_session,' |
---|
1185 | 'reg_number,%s\r\n' |
---|
1186 | 'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,' |
---|
1187 | '200,2012,ug_ft,2010,' |
---|
1188 | % year_range_str in result |
---|
1189 | ) |
---|
1190 | return |
---|
1191 | |
---|
1192 | def test_export_all(self): |
---|
1193 | # we can really export students |
---|
1194 | # set values we can expect in export file |
---|
1195 | self.setup_student(self.student) |
---|
1196 | # We add successful payments. |
---|
1197 | payment_2 = StudentOnlinePayment() |
---|
1198 | payment_2.p_id = 'my-id' |
---|
1199 | payment_2.p_session = curr_year - 5 |
---|
1200 | payment_2.amount_auth = 13.13 |
---|
1201 | payment_2.p_state = 'paid' |
---|
1202 | payment_2.p_category = u'schoolfee' |
---|
1203 | self.student['payments']['my-2ndpayment'] = payment_2 |
---|
1204 | # This one could be a balance payment. |
---|
1205 | # The amount is being added. |
---|
1206 | payment_3 = StudentOnlinePayment() |
---|
1207 | payment_3.p_id = 'my-id_2' |
---|
1208 | payment_3.p_session = curr_year - 5 |
---|
1209 | payment_3.amount_auth = 1.01 |
---|
1210 | payment_3.p_state = 'paid' |
---|
1211 | payment_3.p_category = u'schoolfee' |
---|
1212 | self.student['payments']['my-3rdpayment'] = payment_3 |
---|
1213 | # One session school fee has been waived |
---|
1214 | payment_4 = StudentOnlinePayment() |
---|
1215 | payment_4.p_id = 'my-id_2' |
---|
1216 | payment_4.p_session = curr_year - 4 |
---|
1217 | payment_4.amount_auth = 1.01 |
---|
1218 | payment_4.p_state = 'waived' |
---|
1219 | payment_4.p_category = u'schoolfee' |
---|
1220 | self.student['payments']['my-4thpayment'] = payment_4 |
---|
1221 | exporter = SchoolFeePaymentsOverviewExporter() |
---|
1222 | exporter.export_all(self.app, self.outfile) |
---|
1223 | result = open(self.outfile, 'rb').read() |
---|
1224 | self.assertTrue( |
---|
1225 | 'student_id,matric_number,display_fullname,state,' |
---|
1226 | 'certcode,faccode,depcode,is_postgrad,' |
---|
1227 | 'current_level,current_session,current_mode,entry_session,' |
---|
1228 | 'reg_number,%s\r\nA111111,234,Anna M. Tester,created,CERT1,NA,NA,0,' |
---|
1229 | '200,2012,ug_ft,2010,123,,,,,,12.12,14.14,waived,,,,\r\n' |
---|
1230 | % year_range_str in result |
---|
1231 | ) |
---|
1232 | return |
---|
1233 | |
---|
1234 | class SessionPaymentsOverviewExporterTest(StudentImportExportSetup): |
---|
1235 | |
---|
1236 | layer = FunctionalLayer |
---|
1237 | |
---|
1238 | def setUp(self): |
---|
1239 | super(SessionPaymentsOverviewExporterTest, self).setUp() |
---|
1240 | self.setup_for_export() |
---|
1241 | grok.getSite()['configuration'].current_academic_session = curr_year - 4 |
---|
1242 | return |
---|
1243 | |
---|
1244 | def test_ifaces(self): |
---|
1245 | # make sure we fullfill interface contracts |
---|
1246 | obj = SessionPaymentsOverviewExporter() |
---|
1247 | verifyObject(ICSVStudentExporter, obj) |
---|
1248 | verifyClass(ICSVStudentExporter, SessionPaymentsOverviewExporter) |
---|
1249 | return |
---|
1250 | |
---|
1251 | def test_get_as_utility(self): |
---|
1252 | # we can get a payments exporter as utility |
---|
1253 | result = queryUtility(ICSVExporter, name="sessionpaymentsoverview") |
---|
1254 | self.assertTrue(result is not None) |
---|
1255 | return |
---|
1256 | |
---|
1257 | def test_export(self): |
---|
1258 | self.setup_student(self.student) |
---|
1259 | exporter = SessionPaymentsOverviewExporter() |
---|
1260 | exporter.export([self.student], self.outfile) |
---|
1261 | result = open(self.outfile, 'rb').read() |
---|
1262 | self.assertTrue( |
---|
1263 | 'student_id,matric_number,display_fullname,state,certcode,' |
---|
1264 | 'faccode,depcode,is_postgrad,current_level,current_session,' |
---|
1265 | 'current_mode,entry_session,reg_number,schoolfee12,' |
---|
1266 | 'schoolfee13,schoolfee14,clearance12,clearance13,clearance14,' |
---|
1267 | 'gown12,gown13,gown14,transcript12,transcript13,transcript14\r\n' |
---|
1268 | 'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,' |
---|
1269 | '2012,ug_ft,2010,123,' |
---|
1270 | '12.12,,,,,,,,,,,\r\n' in result |
---|
1271 | ) |
---|
1272 | return |
---|
1273 | |
---|
1274 | def test_export_all(self): |
---|
1275 | self.setup_student(self.student) |
---|
1276 | # We add successful payments. |
---|
1277 | payment_2 = StudentOnlinePayment() |
---|
1278 | payment_2.p_id = 'my-id' |
---|
1279 | payment_2.p_session = curr_year - 5 |
---|
1280 | payment_2.amount_auth = 13.13 |
---|
1281 | payment_2.p_state = 'paid' |
---|
1282 | payment_2.p_category = u'schoolfee' |
---|
1283 | self.student['payments']['my-2ndpayment'] = payment_2 |
---|
1284 | # This one could be a balance payment. |
---|
1285 | # The amount is being added. |
---|
1286 | payment_3 = StudentOnlinePayment() |
---|
1287 | payment_3.p_id = 'my-id_2' |
---|
1288 | payment_3.p_session = curr_year - 5 |
---|
1289 | payment_3.amount_auth = 1.01 |
---|
1290 | payment_3.p_state = 'paid' |
---|
1291 | payment_3.p_category = u'schoolfee' |
---|
1292 | self.student['payments']['my-3rdpayment'] = payment_3 |
---|
1293 | # One session school fee has been waived |
---|
1294 | payment_4 = StudentOnlinePayment() |
---|
1295 | payment_4.p_id = 'my-id_2' |
---|
1296 | payment_4.p_session = curr_year - 4 |
---|
1297 | payment_4.amount_auth = 1.01 |
---|
1298 | payment_4.p_state = 'waived' |
---|
1299 | payment_4.p_category = u'schoolfee' |
---|
1300 | self.student['payments']['my-4thpayment'] = payment_4 |
---|
1301 | exporter = SessionPaymentsOverviewExporter() |
---|
1302 | exporter.export_all(self.app, self.outfile) |
---|
1303 | result = open(self.outfile, 'rb').read() |
---|
1304 | self.assertTrue( |
---|
1305 | 'student_id,matric_number,display_fullname,state,certcode,faccode,' |
---|
1306 | 'depcode,is_postgrad,current_level,current_session,' |
---|
1307 | 'current_mode,entry_session,reg_number,' |
---|
1308 | 'schoolfee12,schoolfee13,schoolfee14,' |
---|
1309 | 'clearance12,clearance13,clearance14,' |
---|
1310 | 'gown12,gown13,gown14,' |
---|
1311 | 'transcript12,transcript13,transcript14\r\n' |
---|
1312 | 'A111111,234,Anna M. Tester,created,CERT1,NA,NA,0,200,2012,ug_ft,' |
---|
1313 | '2010,123,' |
---|
1314 | '12.12,14.14,1.01,,,,,,,,,\r\n' |
---|
1315 | in result |
---|
1316 | ) |
---|
1317 | return |
---|
1318 | |
---|
1319 | class StudentStudyLevelsOverviewExporterTest(StudentImportExportSetup): |
---|
1320 | |
---|
1321 | layer = FunctionalLayer |
---|
1322 | |
---|
1323 | def setUp(self): |
---|
1324 | super(StudentStudyLevelsOverviewExporterTest, self).setUp() |
---|
1325 | self.setup_for_export() |
---|
1326 | return |
---|
1327 | |
---|
1328 | def test_ifaces(self): |
---|
1329 | obj = StudentStudyLevelsOverviewExporter() |
---|
1330 | verifyObject(ICSVStudentExporter, obj) |
---|
1331 | verifyClass(ICSVStudentExporter, StudentStudyLevelsOverviewExporter) |
---|
1332 | return |
---|
1333 | |
---|
1334 | def test_get_as_utility(self): |
---|
1335 | result = queryUtility(ICSVExporter, name="studylevelsoverview") |
---|
1336 | self.assertTrue(result is not None) |
---|
1337 | return |
---|
1338 | |
---|
1339 | def test_export(self): |
---|
1340 | self.setup_student(self.student) |
---|
1341 | exporter = StudentStudyLevelsOverviewExporter() |
---|
1342 | exporter.export([self.student], self.outfile) |
---|
1343 | result = open(self.outfile, 'rb').read() |
---|
1344 | self.assertEqual( |
---|
1345 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
1346 | 'entry_session,current_level,current_session,' |
---|
1347 | '0,10,100,110,120,200,210,220,300,310,320,400,410,420,500,' |
---|
1348 | '510,520,600,610,620,700,710,720,800,810,820,900,910,920,999\r\n' |
---|
1349 | 'A111111,created,CERT1,NA,NA,0,2010,200,2012,,,2012' |
---|
1350 | ',,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n', |
---|
1351 | result |
---|
1352 | ) |
---|
1353 | return |
---|
1354 | |
---|
1355 | def test_export_all(self): |
---|
1356 | self.setup_student(self.student) |
---|
1357 | exporter = StudentStudyLevelsOverviewExporter() |
---|
1358 | exporter.export_all(self.app, self.outfile) |
---|
1359 | result = open(self.outfile, 'rb').read() |
---|
1360 | self.assertEqual( |
---|
1361 | 'student_id,state,certcode,faccode,depcode,is_postgrad,' |
---|
1362 | 'entry_session,current_level,current_session,' |
---|
1363 | '0,10,100,110,120,200,210,220,300,310,320,400,410,420,500,' |
---|
1364 | '510,520,600,610,620,700,710,720,800,810,820,900,910,920,999\r\n' |
---|
1365 | 'A111111,created,CERT1,NA,NA,0,2010,200,2012,,,2012' |
---|
1366 | ',,,,,,,,,,,,,,,,,,,,,,,,,,,\r\n', |
---|
1367 | result |
---|
1368 | ) |
---|
1369 | return |
---|
1370 | |
---|
1371 | class ComboCardExporterTest(StudentImportExportSetup): |
---|
1372 | |
---|
1373 | layer = FunctionalLayer |
---|
1374 | |
---|
1375 | def setUp(self): |
---|
1376 | super(ComboCardExporterTest, self).setUp() |
---|
1377 | self.setup_for_export() |
---|
1378 | return |
---|
1379 | |
---|
1380 | def create_passport_img(self, student): |
---|
1381 | # create some passport file for `student` |
---|
1382 | storage = getUtility(IExtFileStore) |
---|
1383 | image_path = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
1384 | self.image_contents = open(image_path, 'rb').read() |
---|
1385 | file_id = IFileStoreNameChooser(student).chooseName( |
---|
1386 | attr='passport.jpg') |
---|
1387 | storage.createFile(file_id, StringIO(self.image_contents)) |
---|
1388 | |
---|
1389 | def test_export_all(self): |
---|
1390 | self.setup_student(self.student) |
---|
1391 | self.create_passport_img(self.student) |
---|
1392 | exporter = ComboCardDataExporter() |
---|
1393 | exporter.export_all(self.app, self.outfile) |
---|
1394 | result = open(self.outfile, 'rb').read() |
---|
1395 | self.assertTrue( |
---|
1396 | 'display_fullname,student_id,matric_number,certificate,faculty,' |
---|
1397 | 'department,passport_path\r\nAnna M. Tester,A111111,234,' |
---|
1398 | 'Unnamed Certificate,Faculty of Unnamed Faculty (NA),' |
---|
1399 | 'Department of Unnamed Department (NA),' |
---|
1400 | 'students/00110/A111111/passport_A111111.jpg\r\n' |
---|
1401 | in result |
---|
1402 | ) |
---|
1403 | return |
---|