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