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

Last change on this file since 9726 was 9702, checked in by Henrik Bettermann, 12 years ago

Add field 'suspended_comment'. This attribute will be used to render flash messages for deactivated students. The field is only displayed on the student manage page.

  • Property svn:keywords set to Id
File size: 22.3 KB
Line 
1import datetime
2from zope.component import queryUtility
3from zope.interface.verify import verifyObject, verifyClass
4from waeup.kofa.interfaces import ICSVExporter
5from waeup.kofa.students.export import (
6    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
7    CourseTicketExporter, PaymentsExporter, BedTicketsExporter,
8    StudentPaymentsOverviewExporter)
9from waeup.kofa.students.payments import StudentOnlinePayment
10from waeup.kofa.students.accommodation import BedTicket
11from waeup.kofa.students.studycourse import StudentStudyCourse
12from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
13from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
14from waeup.kofa.testing import FunctionalLayer
15
16curr_year = datetime.datetime.now().year
17year_range = range(curr_year - 9, curr_year + 1)
18year_range_str = ','.join([str(i) for i in year_range])
19
20
21class StudentsExporterTest(StudentImportExportSetup):
22
23    layer = FunctionalLayer
24
25    def setUp(self):
26        super(StudentsExporterTest, self).setUp()
27        self.setup_for_export()
28        return
29
30    def test_ifaces(self):
31        # make sure we fullfill interface contracts
32        obj = StudentsExporter()
33        verifyObject(ICSVExporter, obj)
34        verifyClass(ICSVExporter, StudentsExporter)
35        return
36
37    def test_get_as_utility(self):
38        # we can get an student exporter as utility
39        result = queryUtility(ICSVExporter, name="students")
40        self.assertTrue(result is not None)
41        return
42
43    def test_export(self):
44        # we can really export students
45        # set values we can expect in export file
46        self.setup_student(self.student)
47        exporter = StudentsExporter()
48        exporter.export([self.student], self.outfile)
49        result = open(self.outfile, 'rb').read()
50        self.assertTrue(
51            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
52            'firstname,lastname,matric_number,middlename,nationality,officer_comment,'
53            'perm_address,personal_updated,'
54            'phone,reg_number,sex,student_id,suspended,suspended_comment,password,'
55            'state,history,certcode,is_postgrad,current_level,current_session\r\n'
56
57            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
58            'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,'
59            '+234-123-12345#,123,f,A111111,0,,,created'
60            in result
61            )
62        return
63
64    def test_export_all(self):
65        # we can really export students
66        # set values we can expect in export file
67        self.setup_student(self.student)
68        exporter = StudentsExporter()
69        exporter.export_all(self.app, self.outfile)
70        result = open(self.outfile, 'rb').read()
71        self.assertTrue(
72            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
73            'firstname,lastname,matric_number,middlename,nationality,officer_comment,'
74            'perm_address,personal_updated'
75            ',phone,reg_number,sex,student_id,suspended,suspended_comment,password,'
76            'state,history,certcode,is_postgrad,current_level,current_session\r\n'
77
78            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
79            'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,'
80            '+234-123-12345#,123,f,A111111,0,,,created'
81            in result
82            )
83        return
84
85    def test_export_student(self):
86        # we can export a single student
87        self.setup_student(self.student)
88        exporter = StudentsExporter()
89        exporter.export_student(self.student, self.outfile)
90        result = open(self.outfile, 'rb').read()
91        self.assertTrue(
92            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
93            'firstname,lastname,matric_number,middlename,nationality,officer_comment,'
94            'perm_address,personal_updated'
95            ',phone,reg_number,sex,student_id,suspended,suspended_comment,password,'
96            'state,history,certcode,is_postgrad,current_level,current_session\r\n'
97
98            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
99            'Anna,Tester,234,M.,NG,,"Studentroad 21\nLagos 123456\n",,'
100            '+234-123-12345#,123,f,A111111,0,,,created'
101            in result
102            )
103        return
104
105
106class StudentStudyCourseExporterTest(StudentImportExportSetup):
107
108    layer = FunctionalLayer
109
110    def setUp(self):
111        super(StudentStudyCourseExporterTest, self).setUp()
112        self.setup_for_export()
113        return
114
115    def test_ifaces(self):
116        # make sure we fullfill interface contracts
117        obj = StudentStudyCourseExporter()
118        verifyObject(ICSVExporter, obj)
119        verifyClass(ICSVExporter, StudentStudyCourseExporter)
120        return
121
122    def test_get_as_utility(self):
123        # we can get an student exporter as utility
124        result = queryUtility(ICSVExporter, name="studentstudycourses")
125        self.assertTrue(result is not None)
126        return
127
128    def test_export_empty(self):
129        # we can export a nearly empty study course
130        study_course = StudentStudyCourse()
131        exporter = StudentStudyCourseExporter()
132        exporter.export([study_course], self.outfile)
133        result = open(self.outfile, 'rb').read()
134        self.assertEqual(
135            result,
136            'certificate,current_level,current_session,current_verdict,'
137            'entry_mode,entry_session,previous_verdict,student_id\r\n'
138
139            ',,,0,,,0,\r\n'
140            )
141        return
142
143    def test_export(self):
144        # we can really export study courses.
145        # set values we can expect in export file
146        self.setup_student(self.student)
147        study_course = self.student.get('studycourse')
148        exporter = StudentStudyCourseExporter()
149        exporter.export([study_course], self.outfile)
150        result = open(self.outfile, 'rb').read()
151        self.assertEqual(
152            result,
153            'certificate,current_level,current_session,current_verdict,'
154            'entry_mode,entry_session,previous_verdict,student_id\r\n'
155
156            'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n'
157            )
158        return
159
160    def test_export_all(self):
161        # we can really export students
162        # set values we can expect in export file
163        self.setup_student(self.student)
164        exporter = StudentStudyCourseExporter()
165        exporter.export_all(self.app, self.outfile)
166        result = open(self.outfile, 'rb').read()
167        self.assertEqual(
168            result,
169            'certificate,current_level,current_session,current_verdict,'
170            'entry_mode,entry_session,previous_verdict,student_id\r\n'
171
172            'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n'
173            )
174        return
175
176    def test_export_student(self):
177        # we can export studycourse of a certain student
178        self.setup_student(self.student)
179        exporter = StudentStudyCourseExporter()
180        exporter.export_student(self.student, self.outfile)
181        result = open(self.outfile, 'rb').read()
182        self.assertEqual(
183            result,
184            'certificate,current_level,current_session,current_verdict,'
185            'entry_mode,entry_session,previous_verdict,student_id\r\n'
186
187            'CERT1,200,2012,0,ug_ft,2010,0,A111111\r\n'
188            )
189        return
190
191class StudentStudyLevelExporterTest(StudentImportExportSetup):
192
193    layer = FunctionalLayer
194
195    def setUp(self):
196        super(StudentStudyLevelExporterTest, self).setUp()
197        self.setup_for_export()
198        return
199
200    def test_ifaces(self):
201        # make sure we fullfill interface contracts
202        obj = StudentStudyLevelExporter()
203        verifyObject(ICSVExporter, obj)
204        verifyClass(ICSVExporter, StudentStudyLevelExporter)
205        return
206
207    def test_get_as_utility(self):
208        # we can get an student exporter as utility
209        result = queryUtility(ICSVExporter, name="studentstudylevels")
210        self.assertTrue(result is not None)
211        return
212
213    def test_export_empty(self):
214        # we can export a nearly empty study level
215        study_level = StudentStudyLevel()
216        exporter = StudentStudyLevelExporter()
217        exporter.export([study_level], self.outfile)
218        result = open(self.outfile, 'rb').read()
219        self.assertEqual(
220            result,
221            'gpa,level,level_session,level_verdict,total_credits,'
222            'validated_by,validation_date,'
223            'student_id,number_of_tickets,certcode\r\n'
224            '0.0,,,0,0,,,,0,\r\n'
225            )
226        return
227
228    def test_export(self):
229        # we can really export study levels.
230        # set values we can expect in export file
231        self.setup_student(self.student)
232        study_course = self.student.get('studycourse')
233        study_level = study_course[study_course.keys()[0]]
234        exporter = StudentStudyLevelExporter()
235        exporter.export([study_level], self.outfile)
236        result = open(self.outfile, 'rb').read()
237        self.assertEqual(
238            result,
239            'gpa,level,level_session,level_verdict,total_credits,'
240            'validated_by,validation_date,'
241            'student_id,number_of_tickets,certcode\r\n'
242            '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n'
243            )
244        return
245
246    def test_export_all(self):
247        # we can really export study levels
248        # set values we can expect in export file
249        self.setup_student(self.student)
250        exporter = StudentStudyLevelExporter()
251        exporter.export_all(self.app, self.outfile)
252        result = open(self.outfile, 'rb').read()
253        self.assertEqual(
254            result,
255            'gpa,level,level_session,level_verdict,total_credits,'
256            'validated_by,validation_date,'
257            'student_id,number_of_tickets,certcode\r\n'
258            '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n'
259            )
260        return
261
262    def test_export_student(self):
263        # we can really export study levels of a certain student
264        self.setup_student(self.student)
265        exporter = StudentStudyLevelExporter()
266        exporter.export_student(self.student, self.outfile)
267        result = open(self.outfile, 'rb').read()
268        self.assertEqual(
269            result,
270            'gpa,level,level_session,level_verdict,total_credits,'
271            'validated_by,validation_date,'
272            'student_id,number_of_tickets,certcode\r\n'
273            '0.0,100,2012,A,100,,,A111111,1,CERT1\r\n'
274            )
275        return
276
277class CourseTicketExporterTest(StudentImportExportSetup):
278
279    layer = FunctionalLayer
280
281    def setUp(self):
282        super(CourseTicketExporterTest, self).setUp()
283        self.setup_for_export()
284        return
285
286    def test_ifaces(self):
287        # make sure we fullfill interface contracts
288        obj = CourseTicketExporter()
289        verifyObject(ICSVExporter, obj)
290        verifyClass(ICSVExporter, CourseTicketExporter)
291        return
292
293    def test_get_as_utility(self):
294        # we can get an student exporter as utility
295        result = queryUtility(ICSVExporter, name="coursetickets")
296        self.assertTrue(result is not None)
297        return
298
299    def test_export_empty(self):
300        # we can export a nearly empty course ticket
301        ticket = CourseTicket()
302        exporter = CourseTicketExporter()
303        exporter.export([ticket], self.outfile)
304        result = open(self.outfile, 'rb').read()
305        self.assertEqual(
306            result,
307            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
308            'passmark,score,semester,title,student_id,certcode\r\n'
309            '0,0,,,,,,0,,,,,,\r\n'
310            )
311        return
312
313    def test_export(self):
314        # we can really export course tickets.
315        # set values we can expect in export file
316        self.setup_student(self.student)
317        study_course = self.student.get('studycourse')
318        study_level = study_course[study_course.keys()[0]]
319        ticket = study_level['CRS1']
320        exporter = CourseTicketExporter()
321        exporter.export([ticket], self.outfile)
322        result = open(self.outfile, 'rb').read()
323        self.assertEqual(
324            result,
325            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
326            'passmark,score,semester,title,student_id,certcode\r\n'
327            '1,1,CRS1,100,DEP1,FAC1,100,0,100,,2,Course 1,A111111,CERT1\r\n'
328            )
329        return
330
331    def test_export_all(self):
332        # we can really export all course tickets
333        # set values we can expect in export file
334        self.setup_student(self.student)
335        exporter = CourseTicketExporter()
336        exporter.export_all(self.app, self.outfile)
337        result = open(self.outfile, 'rb').read()
338        self.assertEqual(
339            result,
340            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
341            'passmark,score,semester,title,student_id,certcode\r\n'
342            '1,1,CRS1,100,DEP1,FAC1,100,0,100,,2,Course 1,A111111,CERT1\r\n'
343            )
344        return
345
346    def test_export_student(self):
347        # we can really export all course tickets of a certain student
348        self.setup_student(self.student)
349        exporter = CourseTicketExporter()
350        exporter.export_student(self.student, self.outfile)
351        result = open(self.outfile, 'rb').read()
352        self.assertEqual(
353            result,
354            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
355            'passmark,score,semester,title,student_id,certcode\r\n'
356            '1,1,CRS1,100,DEP1,FAC1,100,0,100,,2,Course 1,A111111,CERT1\r\n'
357            )
358        return
359
360class PaymentsExporterTest(StudentImportExportSetup):
361
362    layer = FunctionalLayer
363
364    def setUp(self):
365        super(PaymentsExporterTest, self).setUp()
366        self.setup_for_export()
367        return
368
369    def test_ifaces(self):
370        # make sure we fullfill interface contracts
371        obj = PaymentsExporter()
372        verifyObject(ICSVExporter, obj)
373        verifyClass(ICSVExporter, PaymentsExporter)
374        return
375
376    def test_get_as_utility(self):
377        # we can get a payments exporter as utility
378        result = queryUtility(ICSVExporter, name="studentpayments")
379        self.assertTrue(result is not None)
380        return
381
382    def test_export_empty(self):
383        # we can export a nearly empty payment
384        payment = StudentOnlinePayment()
385        payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1)
386        exporter = PaymentsExporter()
387        exporter.export([payment], self.outfile)
388        result = open(self.outfile, 'rb').read()
389        self.assertEqual(
390            result,
391            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
392            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
393            'r_code,r_desc,student_id,student_state,current_session\r\n'
394
395            ',0.0,2012-04-01 13:12:01,schoolfee,1,,,,,unpaid,,0.0,,,,,\r\n'
396            )
397        return
398
399    def test_export(self):
400        # we can really export student payments.
401        # set values we can expect in export file
402        self.setup_student(self.student)
403        payment = self.student['payments']['my-payment']
404        exporter = PaymentsExporter()
405        exporter.export([payment], self.outfile)
406        result = open(self.outfile, 'rb').read()
407        self.assertEqual(
408            result,
409            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
410            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
411            'r_code,r_desc,student_id,student_state,current_session\r\n'
412
413            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
414            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
415            'r-code,,A111111,created,2012\r\n'
416            )
417        return
418
419    def test_export_all(self):
420        # we can really export all payments
421        # set values we can expect in export file
422        self.setup_student(self.student)
423        exporter = PaymentsExporter()
424        exporter.export_all(self.app, self.outfile)
425        result = open(self.outfile, 'rb').read()
426        self.assertEqual(
427            result,
428            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
429            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
430            'r_code,r_desc,student_id,student_state,current_session\r\n'
431
432            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
433            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
434            'r-code,,A111111,created,2012\r\n'
435            )
436        return
437
438    def test_export_student(self):
439        # we can really export all payments of a certain student
440        # set values we can expect in export file
441        self.setup_student(self.student)
442        exporter = PaymentsExporter()
443        exporter.export_student(self.student, self.outfile)
444        result = open(self.outfile, 'rb').read()
445        self.assertEqual(
446            result,
447            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
448            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
449            'r_code,r_desc,student_id,student_state,current_session\r\n'
450
451            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
452            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
453            'r-code,,A111111,created,2012\r\n'
454            )
455        return
456
457class BedTicketsExporterTest(StudentImportExportSetup):
458
459    layer = FunctionalLayer
460
461    def setUp(self):
462        super(BedTicketsExporterTest, self).setUp()
463        self.setup_for_export()
464        return
465
466    def test_ifaces(self):
467        # make sure we fullfill interface contracts
468        obj = BedTicketsExporter()
469        verifyObject(ICSVExporter, obj)
470        verifyClass(ICSVExporter, BedTicketsExporter)
471        return
472
473    def test_get_as_utility(self):
474        # we can get a bedtickets exporter as utility
475        result = queryUtility(ICSVExporter, name="bedtickets")
476        self.assertTrue(result is not None)
477        return
478
479    def test_export_empty(self):
480        # we can export a nearly empty bedticket
481        bedticket = BedTicket()
482        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
483        bedticket.bed = bed
484        exporter = BedTicketsExporter()
485        exporter.export([bedticket], self.outfile)
486        result = open(self.outfile, 'rb').read()
487        self.assertMatches(
488            result,
489            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
490            'booking_session,student_id,actual_bed_type\r\n'
491            'hall-1_A_101_A,,,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,,,regular_male_fr\r\n'
492            )
493        return
494
495    def test_export(self):
496        # we can really export student bedtickets.
497        # set values we can expect in export file
498        self.setup_student(self.student)
499        bedticket = self.student['accommodation']['2004']
500        exporter = BedTicketsExporter()
501        exporter.export([bedticket], self.outfile)
502        result = open(self.outfile, 'rb').read()
503        self.assertMatches(
504            result,
505            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
506            'booking_session,student_id,actual_bed_type\r\n'
507            'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,'
508            'A111111,regular_male_fr\r\n'
509            )
510        return
511
512    def test_export_all(self):
513        # we can really export all bedtickets
514        # set values we can expect in export file
515        self.setup_student(self.student)
516        exporter = BedTicketsExporter()
517        exporter.export_all(self.app, self.outfile)
518        result = open(self.outfile, 'rb').read()
519        self.assertMatches(
520            result,
521            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
522            'booking_session,student_id,actual_bed_type\r\n'
523            'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,'
524            'A111111,regular_male_fr\r\n'
525            )
526        return
527
528    def test_export_student(self):
529        # we can really export all bedtickets of a certain student
530        # set values we can expect in export file
531        self.setup_student(self.student)
532        exporter = BedTicketsExporter()
533        exporter.export_student(self.student, self.outfile)
534        result = open(self.outfile, 'rb').read()
535        self.assertMatches(
536            result,
537            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
538            'booking_session,student_id,actual_bed_type\r\n'
539            'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,'
540            'A111111,regular_male_fr\r\n'
541            )
542        return
543
544class StudentPaymentsOverviewExporterTest(StudentImportExportSetup):
545
546    layer = FunctionalLayer
547
548    def setUp(self):
549        super(StudentPaymentsOverviewExporterTest, self).setUp()
550        self.setup_for_export()
551        return
552
553    def test_ifaces(self):
554        # make sure we fullfill interface contracts
555        obj = StudentPaymentsOverviewExporter()
556        verifyObject(ICSVExporter, obj)
557        verifyClass(ICSVExporter, StudentPaymentsOverviewExporter)
558        return
559
560    def test_get_as_utility(self):
561        # we can get a payments exporter as utility
562        result = queryUtility(ICSVExporter, name="paymentsoverview")
563        self.assertTrue(result is not None)
564        return
565
566    def test_export(self):
567        self.setup_student(self.student)
568        exporter = StudentPaymentsOverviewExporter()
569        exporter.export([self.student], self.outfile)
570        result = open(self.outfile, 'rb').read()
571        self.assertEqual(
572            'student_id,state,certcode,faccode,depcode,is_postgrad,'
573            'current_level,current_session,'
574            '%s\r\n'
575            'A111111,created,CERT1,NA,NA,0,200,2012,'
576            ',,,,,,,,,\r\n' % year_range_str,
577            result
578            )
579        return
580
581    def test_export_all(self):
582        # we can really export students
583        # set values we can expect in export file
584        self.setup_student(self.student)
585        # We add successful payments
586        payment = StudentOnlinePayment()
587        payment.p_id = 'my-id'
588        payment.p_session = 2009
589        payment.amount_auth = 12.12
590        payment.p_state = u'paid'
591        self.student['payments']['my-2ndpayment'] = payment
592        exporter = StudentPaymentsOverviewExporter()
593        exporter.export_all(self.app, self.outfile)
594        result = open(self.outfile, 'rb').read()
595        self.assertEqual(
596            'student_id,state,certcode,faccode,depcode,is_postgrad,'
597            'current_level,current_session,'
598            '%s\r\nA111111,created,CERT1,NA,NA,0,'
599            '200,2012,,,,,,,12.12,,,\r\n' % year_range_str,
600            result
601            )
602        return
Note: See TracBrowser for help on using the repository browser.