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

Last change on this file since 8341 was 8341, checked in by uli, 13 years ago
  • Avoid repetitive code using methods from ImportExportSetup?.
  • Add tests for course ticket exporter.
  • Property svn:keywords set to Id
File size: 9.7 KB
Line 
1from zope.component import queryUtility
2from zope.interface.verify import verifyObject, verifyClass
3from waeup.kofa.interfaces import ICSVExporter
4from waeup.kofa.students.export import (
5    StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
6    CourseTicketExporter)
7from waeup.kofa.students.student import StudentStudyCourse
8from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
9from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
10from waeup.kofa.testing import FunctionalLayer
11
12class StudentsExporterTest(StudentImportExportSetup):
13
14    layer = FunctionalLayer
15
16    def setUp(self):
17        super(StudentsExporterTest, self).setUp()
18        self.setup_for_export()
19        return
20
21    def test_ifaces(self):
22        # make sure we fullfill interface contracts
23        obj = StudentsExporter()
24        verifyObject(ICSVExporter, obj)
25        verifyClass(ICSVExporter, StudentsExporter)
26        return
27
28    def test_get_as_utility(self):
29        # we can get an student exporter as utility
30        result = queryUtility(ICSVExporter, name="students")
31        self.assertTrue(result is not None)
32        return
33
34    def test_export(self):
35        # we can really export students
36        # set values we can expect in export file
37        self.setup_student(self.student)
38        exporter = StudentsExporter()
39        exporter.export([self.student], self.outfile)
40        result = open(self.outfile, 'rb').read()
41        self.assertEqual(
42            result,
43            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
44            'firstname,lastname,matric_number,middlename,nationality,'
45            'perm_address,phone,reg_number,sex,student_id\r\n'
46
47            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,Anna,'
48            'Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",'
49            '+234-123-12345,123456,f,A111111\r\n'
50            )
51        return
52
53    def test_export_all(self):
54        # we can really export students
55        # set values we can expect in export file
56        self.setup_student(self.student)
57        exporter = StudentsExporter()
58        exporter.export_all(self.app, self.outfile)
59        result = open(self.outfile, 'rb').read()
60        self.assertEqual(
61            result,
62            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
63            'firstname,lastname,matric_number,middlename,nationality,'
64            'perm_address,phone,reg_number,sex,student_id\r\n'
65
66            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,Anna,'
67            'Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",'
68            '+234-123-12345,123456,f,A111111\r\n'
69            )
70        return
71
72class StudentStudyCourseExporterTest(StudentImportExportSetup):
73
74    layer = FunctionalLayer
75
76    def setUp(self):
77        super(StudentStudyCourseExporterTest, self).setUp()
78        self.setup_for_export()
79        return
80
81    def test_ifaces(self):
82        # make sure we fullfill interface contracts
83        obj = StudentStudyCourseExporter()
84        verifyObject(ICSVExporter, obj)
85        verifyClass(ICSVExporter, StudentStudyCourseExporter)
86        return
87
88    def test_get_as_utility(self):
89        # we can get an student exporter as utility
90        result = queryUtility(ICSVExporter, name="studentstudycourses")
91        self.assertTrue(result is not None)
92        return
93
94    def test_export_empty(self):
95        # we can export a nearly empty study course
96        study_course = StudentStudyCourse()
97        exporter = StudentStudyCourseExporter()
98        exporter.export([study_course], self.outfile)
99        result = open(self.outfile, 'rb').read()
100        self.assertEqual(
101            result,
102            'certificate,current_level,current_session,current_verdict,'
103            'entry_mode,entry_session,previous_verdict\r\n'
104
105            ',,,0,,,0\r\n'
106            )
107        return
108
109    def test_export(self):
110        # we can really export study courses.
111        # set values we can expect in export file
112        self.setup_student(self.student)
113        study_course = self.student.get('studycourse')
114        exporter = StudentStudyCourseExporter()
115        exporter.export([study_course], self.outfile)
116        result = open(self.outfile, 'rb').read()
117        self.assertEqual(
118            result,
119            'certificate,current_level,current_session,current_verdict,'
120            'entry_mode,entry_session,previous_verdict\r\n'
121
122            'CERT1,200,2012,0,ug_ft,2010,0\r\n'
123            )
124        return
125
126    def test_export_all(self):
127        # we can really export students
128        # set values we can expect in export file
129        self.setup_student(self.student)
130        exporter = StudentStudyCourseExporter()
131        exporter.export_all(self.app, self.outfile)
132        result = open(self.outfile, 'rb').read()
133        self.assertEqual(
134            result,
135            'certificate,current_level,current_session,current_verdict,'
136            'entry_mode,entry_session,previous_verdict\r\n'
137
138            'CERT1,200,2012,0,ug_ft,2010,0\r\n'
139            )
140        return
141
142class StudentStudyLevelExporterTest(StudentImportExportSetup):
143
144    layer = FunctionalLayer
145
146    def setUp(self):
147        super(StudentStudyLevelExporterTest, self).setUp()
148        self.setup_for_export()
149        return
150
151    def test_ifaces(self):
152        # make sure we fullfill interface contracts
153        obj = StudentStudyLevelExporter()
154        verifyObject(ICSVExporter, obj)
155        verifyClass(ICSVExporter, StudentStudyLevelExporter)
156        return
157
158    def test_get_as_utility(self):
159        # we can get an student exporter as utility
160        result = queryUtility(ICSVExporter, name="studentstudylevels")
161        self.assertTrue(result is not None)
162        return
163
164    def test_export_empty(self):
165        # we can export a nearly empty study level
166        study_level = StudentStudyLevel()
167        exporter = StudentStudyLevelExporter()
168        exporter.export([study_level], self.outfile)
169        result = open(self.outfile, 'rb').read()
170        self.assertEqual(
171            result,
172            'level,level_session,level_verdict,matric_number,reg_number\r\n'
173            ',,0,,\r\n'
174            )
175        return
176
177    def test_export(self):
178        # we can really export study levels.
179        # set values we can expect in export file
180        self.setup_student(self.student)
181        study_course = self.student.get('studycourse')
182        study_level = study_course[study_course.keys()[0]]
183        exporter = StudentStudyLevelExporter()
184        exporter.export([study_level], self.outfile)
185        result = open(self.outfile, 'rb').read()
186        self.assertEqual(
187            result,
188            'level,level_session,level_verdict,matric_number,reg_number\r\n'
189            '100,2012,A,M123456,123456\r\n'
190            )
191        return
192
193    def test_export_all(self):
194        # we can really export study levels
195        # set values we can expect in export file
196        self.setup_student(self.student)
197        exporter = StudentStudyLevelExporter()
198        exporter.export_all(self.app, self.outfile)
199        result = open(self.outfile, 'rb').read()
200        self.assertEqual(
201            result,
202            'level,level_session,level_verdict,matric_number,reg_number\r\n'
203            '100,2012,A,M123456,123456\r\n'
204            )
205        return
206
207class CourseTicketExporterTest(StudentImportExportSetup):
208
209    layer = FunctionalLayer
210
211    def setUp(self):
212        super(CourseTicketExporterTest, self).setUp()
213        self.setup_for_export()
214        return
215
216    def test_ifaces(self):
217        # make sure we fullfill interface contracts
218        obj = CourseTicketExporter()
219        verifyObject(ICSVExporter, obj)
220        verifyClass(ICSVExporter, CourseTicketExporter)
221        return
222
223    def test_get_as_utility(self):
224        # we can get an student exporter as utility
225        result = queryUtility(ICSVExporter, name="coursetickets")
226        self.assertTrue(result is not None)
227        return
228
229    def test_export_empty(self):
230        # we can export a nearly empty course ticket
231        ticket = CourseTicket()
232        exporter = CourseTicketExporter()
233        exporter.export([ticket], self.outfile)
234        result = open(self.outfile, 'rb').read()
235        self.assertEqual(
236            result,
237            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
238            'matric_number,passmark,reg_number,score,semester,title\r\n'
239            '0,0,,,,,,0,,,,0,,\r\n'
240            )
241        return
242
243    def test_export(self):
244        # we can really export course tickets.
245        # set values we can expect in export file
246        self.setup_student(self.student)
247        study_course = self.student.get('studycourse')
248        study_level = study_course[study_course.keys()[0]]
249        ticket = study_level['CRS1']
250        exporter = CourseTicketExporter()
251        exporter.export([ticket], self.outfile)
252        result = open(self.outfile, 'rb').read()
253        self.assertEqual(
254            result,
255            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
256            'matric_number,passmark,reg_number,score,semester,title\r\n'
257            '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n'
258            )
259        return
260
261    def test_export_all(self):
262        # we can really export all course tickets
263        # set values we can expect in export file
264        self.setup_student(self.student)
265        exporter = CourseTicketExporter()
266        exporter.export_all(self.app, self.outfile)
267        result = open(self.outfile, 'rb').read()
268        self.assertEqual(
269            result,
270            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
271            'matric_number,passmark,reg_number,score,semester,title\r\n'
272            '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n'
273            )
274        return
Note: See TracBrowser for help on using the repository browser.