source: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py @ 14682

Last change on this file since 14682 was 14642, checked in by Henrik Bettermann, 8 years ago

Add course_category attribute to course tickets. In the base package,
this attribute is omitted from display and manage pages.

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