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

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

Add timestamp to personal data. This timestamp will be checked when students log in. Students sould be remembered to frequently update their personal data.

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