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