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