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

Last change on this file since 8472 was 8429, checked in by Henrik Bettermann, 13 years ago

Add response description payment which displays the user id of the person who approved a payment.

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