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

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

Add has to exported phone numbers to avoid confusion with negative numbers.

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