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

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

Add StudentPaymentsOverviewExporter?.

  • Property svn:keywords set to Id
File size: 22.1 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,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,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,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            'level,level_session,level_verdict,validated_by,validation_date,'
222            'student_id,number_of_tickets,certcode\r\n'
223            ',,0,,,,0,\r\n'
224            )
225        return
226
227    def test_export(self):
228        # we can really export study levels.
229        # set values we can expect in export file
230        self.setup_student(self.student)
231        study_course = self.student.get('studycourse')
232        study_level = study_course[study_course.keys()[0]]
233        exporter = StudentStudyLevelExporter()
234        exporter.export([study_level], self.outfile)
235        result = open(self.outfile, 'rb').read()
236        self.assertEqual(
237            result,
238            'level,level_session,level_verdict,validated_by,validation_date,'
239            'student_id,number_of_tickets,certcode\r\n'
240            '100,2012,A,,,A111111,1,CERT1\r\n'
241            )
242        return
243
244    def test_export_all(self):
245        # we can really export study levels
246        # set values we can expect in export file
247        self.setup_student(self.student)
248        exporter = StudentStudyLevelExporter()
249        exporter.export_all(self.app, self.outfile)
250        result = open(self.outfile, 'rb').read()
251        self.assertEqual(
252            result,
253            'level,level_session,level_verdict,validated_by,validation_date,'
254            'student_id,number_of_tickets,certcode\r\n'
255            '100,2012,A,,,A111111,1,CERT1\r\n'
256            )
257        return
258
259    def test_export_student(self):
260        # we can really export study levels of a certain student
261        self.setup_student(self.student)
262        exporter = StudentStudyLevelExporter()
263        exporter.export_student(self.student, self.outfile)
264        result = open(self.outfile, 'rb').read()
265        self.assertEqual(
266            result,
267            'level,level_session,level_verdict,validated_by,validation_date,'
268            'student_id,number_of_tickets,certcode\r\n'
269            '100,2012,A,,,A111111,1,CERT1\r\n'
270            )
271        return
272
273class CourseTicketExporterTest(StudentImportExportSetup):
274
275    layer = FunctionalLayer
276
277    def setUp(self):
278        super(CourseTicketExporterTest, self).setUp()
279        self.setup_for_export()
280        return
281
282    def test_ifaces(self):
283        # make sure we fullfill interface contracts
284        obj = CourseTicketExporter()
285        verifyObject(ICSVExporter, obj)
286        verifyClass(ICSVExporter, CourseTicketExporter)
287        return
288
289    def test_get_as_utility(self):
290        # we can get an student exporter as utility
291        result = queryUtility(ICSVExporter, name="coursetickets")
292        self.assertTrue(result is not None)
293        return
294
295    def test_export_empty(self):
296        # we can export a nearly empty course ticket
297        ticket = CourseTicket()
298        exporter = CourseTicketExporter()
299        exporter.export([ticket], self.outfile)
300        result = open(self.outfile, 'rb').read()
301        self.assertEqual(
302            result,
303            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
304            'passmark,score,semester,title,student_id,certcode\r\n'
305            '0,0,,,,,,0,,0,,,,\r\n'
306            )
307        return
308
309    def test_export(self):
310        # we can really export course tickets.
311        # set values we can expect in export file
312        self.setup_student(self.student)
313        study_course = self.student.get('studycourse')
314        study_level = study_course[study_course.keys()[0]]
315        ticket = study_level['CRS1']
316        exporter = CourseTicketExporter()
317        exporter.export([ticket], self.outfile)
318        result = open(self.outfile, 'rb').read()
319        self.assertEqual(
320            result,
321            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
322            'passmark,score,semester,title,student_id,certcode\r\n'
323            '1,1,CRS1,100,DEP1,FAC1,100,0,100,0,2,Course 1,A111111,CERT1\r\n'
324            )
325        return
326
327    def test_export_all(self):
328        # we can really export all course tickets
329        # set values we can expect in export file
330        self.setup_student(self.student)
331        exporter = CourseTicketExporter()
332        exporter.export_all(self.app, self.outfile)
333        result = open(self.outfile, 'rb').read()
334        self.assertEqual(
335            result,
336            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
337            'passmark,score,semester,title,student_id,certcode\r\n'
338            '1,1,CRS1,100,DEP1,FAC1,100,0,100,0,2,Course 1,A111111,CERT1\r\n'
339            )
340        return
341
342    def test_export_student(self):
343        # we can really export all course tickets of a certain student
344        self.setup_student(self.student)
345        exporter = CourseTicketExporter()
346        exporter.export_student(self.student, self.outfile)
347        result = open(self.outfile, 'rb').read()
348        self.assertEqual(
349            result,
350            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
351            'passmark,score,semester,title,student_id,certcode\r\n'
352            '1,1,CRS1,100,DEP1,FAC1,100,0,100,0,2,Course 1,A111111,CERT1\r\n'
353            )
354        return
355
356class PaymentsExporterTest(StudentImportExportSetup):
357
358    layer = FunctionalLayer
359
360    def setUp(self):
361        super(PaymentsExporterTest, self).setUp()
362        self.setup_for_export()
363        return
364
365    def test_ifaces(self):
366        # make sure we fullfill interface contracts
367        obj = PaymentsExporter()
368        verifyObject(ICSVExporter, obj)
369        verifyClass(ICSVExporter, PaymentsExporter)
370        return
371
372    def test_get_as_utility(self):
373        # we can get a payments exporter as utility
374        result = queryUtility(ICSVExporter, name="studentpayments")
375        self.assertTrue(result is not None)
376        return
377
378    def test_export_empty(self):
379        # we can export a nearly empty payment
380        payment = StudentOnlinePayment()
381        payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1)
382        exporter = PaymentsExporter()
383        exporter.export([payment], self.outfile)
384        result = open(self.outfile, 'rb').read()
385        self.assertEqual(
386            result,
387            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
388            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
389            'r_code,r_desc,student_id,student_state,current_session\r\n'
390
391            ',0.0,2012-04-01 13:12:01,schoolfee,1,,,,,unpaid,,0.0,,,,,\r\n'
392            )
393        return
394
395    def test_export(self):
396        # we can really export student payments.
397        # set values we can expect in export file
398        self.setup_student(self.student)
399        payment = self.student['payments']['my-payment']
400        exporter = PaymentsExporter()
401        exporter.export([payment], self.outfile)
402        result = open(self.outfile, 'rb').read()
403        self.assertEqual(
404            result,
405            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
406            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
407            'r_code,r_desc,student_id,student_state,current_session\r\n'
408
409            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
410            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
411            'r-code,,A111111,created,2012\r\n'
412            )
413        return
414
415    def test_export_all(self):
416        # we can really export all payments
417        # set values we can expect in export file
418        self.setup_student(self.student)
419        exporter = PaymentsExporter()
420        exporter.export_all(self.app, self.outfile)
421        result = open(self.outfile, 'rb').read()
422        self.assertEqual(
423            result,
424            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
425            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
426            'r_code,r_desc,student_id,student_state,current_session\r\n'
427
428            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
429            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
430            'r-code,,A111111,created,2012\r\n'
431            )
432        return
433
434    def test_export_student(self):
435        # we can really export all payments of a certain student
436        # set values we can expect in export file
437        self.setup_student(self.student)
438        exporter = PaymentsExporter()
439        exporter.export_student(self.student, self.outfile)
440        result = open(self.outfile, 'rb').read()
441        self.assertEqual(
442            result,
443            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
444            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
445            'r_code,r_desc,student_id,student_state,current_session\r\n'
446
447            '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,'
448            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
449            'r-code,,A111111,created,2012\r\n'
450            )
451        return
452
453class BedTicketsExporterTest(StudentImportExportSetup):
454
455    layer = FunctionalLayer
456
457    def setUp(self):
458        super(BedTicketsExporterTest, self).setUp()
459        self.setup_for_export()
460        return
461
462    def test_ifaces(self):
463        # make sure we fullfill interface contracts
464        obj = BedTicketsExporter()
465        verifyObject(ICSVExporter, obj)
466        verifyClass(ICSVExporter, BedTicketsExporter)
467        return
468
469    def test_get_as_utility(self):
470        # we can get a bedtickets exporter as utility
471        result = queryUtility(ICSVExporter, name="bedtickets")
472        self.assertTrue(result is not None)
473        return
474
475    def test_export_empty(self):
476        # we can export a nearly empty bedticket
477        bedticket = BedTicket()
478        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
479        bedticket.bed = bed
480        exporter = BedTicketsExporter()
481        exporter.export([bedticket], self.outfile)
482        result = open(self.outfile, 'rb').read()
483        self.assertMatches(
484            result,
485            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
486            'booking_session,student_id,actual_bed_type\r\n'
487            'hall-1_A_101_A,,,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,,,regular_male_fr\r\n'
488            )
489        return
490
491    def test_export(self):
492        # we can really export student bedtickets.
493        # set values we can expect in export file
494        self.setup_student(self.student)
495        bedticket = self.student['accommodation']['2004']
496        exporter = BedTicketsExporter()
497        exporter.export([bedticket], self.outfile)
498        result = open(self.outfile, 'rb').read()
499        self.assertMatches(
500            result,
501            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
502            'booking_session,student_id,actual_bed_type\r\n'
503            'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,'
504            'A111111,regular_male_fr\r\n'
505            )
506        return
507
508    def test_export_all(self):
509        # we can really export all bedtickets
510        # set values we can expect in export file
511        self.setup_student(self.student)
512        exporter = BedTicketsExporter()
513        exporter.export_all(self.app, self.outfile)
514        result = open(self.outfile, 'rb').read()
515        self.assertMatches(
516            result,
517            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
518            'booking_session,student_id,actual_bed_type\r\n'
519            'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,'
520            'A111111,regular_male_fr\r\n'
521            )
522        return
523
524    def test_export_student(self):
525        # we can really export all bedtickets of a certain student
526        # set values we can expect in export file
527        self.setup_student(self.student)
528        exporter = BedTicketsExporter()
529        exporter.export_student(self.student, self.outfile)
530        result = open(self.outfile, 'rb').read()
531        self.assertMatches(
532            result,
533            'bed,bed_coordinates,bed_type,booking_code,booking_date,'
534            'booking_session,student_id,actual_bed_type\r\n'
535            'hall-1_A_101_A,,any bed type,,<YYYY-MM-DD hh:mm:ss>.<6-DIGITS>,2004,'
536            'A111111,regular_male_fr\r\n'
537            )
538        return
539
540class StudentPaymentsOverviewExporterTest(StudentImportExportSetup):
541
542    layer = FunctionalLayer
543
544    def setUp(self):
545        super(StudentPaymentsOverviewExporterTest, self).setUp()
546        self.setup_for_export()
547        return
548
549    def test_ifaces(self):
550        # make sure we fullfill interface contracts
551        obj = StudentPaymentsOverviewExporter()
552        verifyObject(ICSVExporter, obj)
553        verifyClass(ICSVExporter, StudentPaymentsOverviewExporter)
554        return
555
556    def test_get_as_utility(self):
557        # we can get a payments exporter as utility
558        result = queryUtility(ICSVExporter, name="paymentsoverview")
559        self.assertTrue(result is not None)
560        return
561
562    def test_export(self):
563        self.setup_student(self.student)
564        exporter = StudentPaymentsOverviewExporter()
565        exporter.export([self.student], self.outfile)
566        result = open(self.outfile, 'rb').read()
567        self.assertEqual(
568            'student_id,state,certcode,faccode,depcode,is_postgrad,'
569            'current_level,current_session,'
570            '%s\r\n'
571            'A111111,created,CERT1,NA,NA,0,200,2012,'
572            ',,,,,,,,,\r\n' % year_range_str,
573            result
574            )
575        return
576
577    def test_export_all(self):
578        # we can really export students
579        # set values we can expect in export file
580        self.setup_student(self.student)
581        # We add successful payments
582        payment = StudentOnlinePayment()
583        payment.p_id = 'my-id'
584        payment.p_session = 2009
585        payment.amount_auth = 12.12
586        payment.p_state = u'paid'
587        self.student['payments']['my-2ndpayment'] = payment
588        exporter = StudentPaymentsOverviewExporter()
589        exporter.export_all(self.app, self.outfile)
590        result = open(self.outfile, 'rb').read()
591        self.assertEqual(
592            'student_id,state,certcode,faccode,depcode,is_postgrad,'
593            'current_level,current_session,'
594            '%s\r\nA111111,created,CERT1,NA,NA,0,'
595            '200,2012,,,,,,,12.12,,,\r\n' % year_range_str,
596            result
597            )
598        return
Note: See TracBrowser for help on using the repository browser.