1 | import datetime |
---|
2 | from zope.component import queryUtility |
---|
3 | from zope.interface.verify import verifyObject, verifyClass |
---|
4 | from waeup.kofa.interfaces import ICSVExporter |
---|
5 | from waeup.kofa.students.export import ( |
---|
6 | StudentsExporter, StudentStudyCourseExporter, StudentStudyLevelExporter, |
---|
7 | CourseTicketExporter, PaymentsExporter) |
---|
8 | from waeup.kofa.students.payments import StudentOnlinePayment |
---|
9 | from waeup.kofa.students.studycourse import StudentStudyCourse |
---|
10 | from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket |
---|
11 | from waeup.kofa.students.tests.test_batching import StudentImportExportSetup |
---|
12 | from waeup.kofa.testing import FunctionalLayer |
---|
13 | |
---|
14 | class 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,suspended,password,' |
---|
47 | 'state,history,certcode,is_postgrad,current_level,current_session\r\n' |
---|
48 | |
---|
49 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
50 | 'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",' |
---|
51 | '+234-123-12345#,123,f,A111111,0,,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,suspended,password,' |
---|
67 | 'state,history,certcode,is_postgrad,current_level,current_session\r\n' |
---|
68 | |
---|
69 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
70 | 'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",' |
---|
71 | '+234-123-12345#,123,f,A111111,0,,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,suspended,password,' |
---|
86 | 'state,history,certcode,is_postgrad,current_level,current_session\r\n' |
---|
87 | |
---|
88 | 'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,' |
---|
89 | 'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",' |
---|
90 | '+234-123-12345#,123,f,A111111,0,,created' |
---|
91 | in result |
---|
92 | ) |
---|
93 | return |
---|
94 | |
---|
95 | |
---|
96 | class 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 | |
---|
181 | class 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,validated_by,validation_date,' |
---|
212 | 'student_id,number_of_tickets,certcode\r\n' |
---|
213 | ',,0,,,,0,\r\n' |
---|
214 | ) |
---|
215 | return |
---|
216 | |
---|
217 | def test_export(self): |
---|
218 | # we can really export study levels. |
---|
219 | # set values we can expect in export file |
---|
220 | self.setup_student(self.student) |
---|
221 | study_course = self.student.get('studycourse') |
---|
222 | study_level = study_course[study_course.keys()[0]] |
---|
223 | exporter = StudentStudyLevelExporter() |
---|
224 | exporter.export([study_level], self.outfile) |
---|
225 | result = open(self.outfile, 'rb').read() |
---|
226 | self.assertEqual( |
---|
227 | result, |
---|
228 | 'level,level_session,level_verdict,validated_by,validation_date,' |
---|
229 | 'student_id,number_of_tickets,certcode\r\n' |
---|
230 | '100,2012,A,,,A111111,1,CERT1\r\n' |
---|
231 | ) |
---|
232 | return |
---|
233 | |
---|
234 | def test_export_all(self): |
---|
235 | # we can really export study levels |
---|
236 | # set values we can expect in export file |
---|
237 | self.setup_student(self.student) |
---|
238 | exporter = StudentStudyLevelExporter() |
---|
239 | exporter.export_all(self.app, self.outfile) |
---|
240 | result = open(self.outfile, 'rb').read() |
---|
241 | self.assertEqual( |
---|
242 | result, |
---|
243 | 'level,level_session,level_verdict,validated_by,validation_date,' |
---|
244 | 'student_id,number_of_tickets,certcode\r\n' |
---|
245 | '100,2012,A,,,A111111,1,CERT1\r\n' |
---|
246 | ) |
---|
247 | return |
---|
248 | |
---|
249 | def test_export_student(self): |
---|
250 | # we can really export study levels of a certain student |
---|
251 | self.setup_student(self.student) |
---|
252 | exporter = StudentStudyLevelExporter() |
---|
253 | exporter.export_student(self.student, self.outfile) |
---|
254 | result = open(self.outfile, 'rb').read() |
---|
255 | self.assertEqual( |
---|
256 | result, |
---|
257 | 'level,level_session,level_verdict,validated_by,validation_date,' |
---|
258 | 'student_id,number_of_tickets,certcode\r\n' |
---|
259 | '100,2012,A,,,A111111,1,CERT1\r\n' |
---|
260 | ) |
---|
261 | return |
---|
262 | |
---|
263 | class CourseTicketExporterTest(StudentImportExportSetup): |
---|
264 | |
---|
265 | layer = FunctionalLayer |
---|
266 | |
---|
267 | def setUp(self): |
---|
268 | super(CourseTicketExporterTest, self).setUp() |
---|
269 | self.setup_for_export() |
---|
270 | return |
---|
271 | |
---|
272 | def test_ifaces(self): |
---|
273 | # make sure we fullfill interface contracts |
---|
274 | obj = CourseTicketExporter() |
---|
275 | verifyObject(ICSVExporter, obj) |
---|
276 | verifyClass(ICSVExporter, CourseTicketExporter) |
---|
277 | return |
---|
278 | |
---|
279 | def test_get_as_utility(self): |
---|
280 | # we can get an student exporter as utility |
---|
281 | result = queryUtility(ICSVExporter, name="coursetickets") |
---|
282 | self.assertTrue(result is not None) |
---|
283 | return |
---|
284 | |
---|
285 | def test_export_empty(self): |
---|
286 | # we can export a nearly empty course ticket |
---|
287 | ticket = CourseTicket() |
---|
288 | exporter = CourseTicketExporter() |
---|
289 | exporter.export([ticket], self.outfile) |
---|
290 | result = open(self.outfile, 'rb').read() |
---|
291 | self.assertEqual( |
---|
292 | result, |
---|
293 | 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' |
---|
294 | 'passmark,score,semester,title,student_id,certcode\r\n' |
---|
295 | '0,0,,,,,,0,,0,,,,\r\n' |
---|
296 | ) |
---|
297 | return |
---|
298 | |
---|
299 | def test_export(self): |
---|
300 | # we can really export course tickets. |
---|
301 | # set values we can expect in export file |
---|
302 | self.setup_student(self.student) |
---|
303 | study_course = self.student.get('studycourse') |
---|
304 | study_level = study_course[study_course.keys()[0]] |
---|
305 | ticket = study_level['CRS1'] |
---|
306 | exporter = CourseTicketExporter() |
---|
307 | exporter.export([ticket], self.outfile) |
---|
308 | result = open(self.outfile, 'rb').read() |
---|
309 | self.assertEqual( |
---|
310 | result, |
---|
311 | 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' |
---|
312 | 'passmark,score,semester,title,student_id,certcode\r\n' |
---|
313 | '1,1,CRS1,100,DEP1,FAC1,100,0,100,0,2,Course 1,A111111,CERT1\r\n' |
---|
314 | ) |
---|
315 | return |
---|
316 | |
---|
317 | def test_export_all(self): |
---|
318 | # we can really export all course tickets |
---|
319 | # set values we can expect in export file |
---|
320 | self.setup_student(self.student) |
---|
321 | exporter = CourseTicketExporter() |
---|
322 | exporter.export_all(self.app, self.outfile) |
---|
323 | result = open(self.outfile, 'rb').read() |
---|
324 | self.assertEqual( |
---|
325 | result, |
---|
326 | 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' |
---|
327 | 'passmark,score,semester,title,student_id,certcode\r\n' |
---|
328 | '1,1,CRS1,100,DEP1,FAC1,100,0,100,0,2,Course 1,A111111,CERT1\r\n' |
---|
329 | ) |
---|
330 | return |
---|
331 | |
---|
332 | def test_export_student(self): |
---|
333 | # we can really export all course tickets of a certain student |
---|
334 | self.setup_student(self.student) |
---|
335 | exporter = CourseTicketExporter() |
---|
336 | exporter.export_student(self.student, self.outfile) |
---|
337 | result = open(self.outfile, 'rb').read() |
---|
338 | self.assertEqual( |
---|
339 | result, |
---|
340 | 'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,' |
---|
341 | 'passmark,score,semester,title,student_id,certcode\r\n' |
---|
342 | '1,1,CRS1,100,DEP1,FAC1,100,0,100,0,2,Course 1,A111111,CERT1\r\n' |
---|
343 | ) |
---|
344 | return |
---|
345 | |
---|
346 | class PaymentsExporterTest(StudentImportExportSetup): |
---|
347 | |
---|
348 | layer = FunctionalLayer |
---|
349 | |
---|
350 | def setUp(self): |
---|
351 | super(PaymentsExporterTest, self).setUp() |
---|
352 | self.setup_for_export() |
---|
353 | return |
---|
354 | |
---|
355 | def test_ifaces(self): |
---|
356 | # make sure we fullfill interface contracts |
---|
357 | obj = PaymentsExporter() |
---|
358 | verifyObject(ICSVExporter, obj) |
---|
359 | verifyClass(ICSVExporter, PaymentsExporter) |
---|
360 | return |
---|
361 | |
---|
362 | def test_get_as_utility(self): |
---|
363 | # we can get a payments exporter as utility |
---|
364 | result = queryUtility(ICSVExporter, name="studentpayments") |
---|
365 | self.assertTrue(result is not None) |
---|
366 | return |
---|
367 | |
---|
368 | def test_export_empty(self): |
---|
369 | # we can export a nearly empty payment |
---|
370 | payment = StudentOnlinePayment() |
---|
371 | payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1) |
---|
372 | exporter = PaymentsExporter() |
---|
373 | exporter.export([payment], self.outfile) |
---|
374 | result = open(self.outfile, 'rb').read() |
---|
375 | self.assertEqual( |
---|
376 | result, |
---|
377 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
378 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
379 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
380 | |
---|
381 | ',0.0,2012-04-01 13:12:01,schoolfee,1,,,,,unpaid,,0.0,,,,,\r\n' |
---|
382 | ) |
---|
383 | return |
---|
384 | |
---|
385 | def test_export(self): |
---|
386 | # we can really export student payments. |
---|
387 | # set values we can expect in export file |
---|
388 | self.setup_student(self.student) |
---|
389 | payment = self.student['payments']['my-payment'] |
---|
390 | exporter = PaymentsExporter() |
---|
391 | exporter.export([payment], self.outfile) |
---|
392 | result = open(self.outfile, 'rb').read() |
---|
393 | self.assertEqual( |
---|
394 | result, |
---|
395 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
396 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
397 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
398 | |
---|
399 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
400 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
401 | 'r-code,,A111111,created,2012\r\n' |
---|
402 | ) |
---|
403 | return |
---|
404 | |
---|
405 | def test_export_all(self): |
---|
406 | # we can really export all payments |
---|
407 | # set values we can expect in export file |
---|
408 | self.setup_student(self.student) |
---|
409 | exporter = PaymentsExporter() |
---|
410 | exporter.export_all(self.app, self.outfile) |
---|
411 | result = open(self.outfile, 'rb').read() |
---|
412 | self.assertEqual( |
---|
413 | result, |
---|
414 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
415 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
416 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
417 | |
---|
418 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
419 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
420 | 'r-code,,A111111,created,2012\r\n' |
---|
421 | ) |
---|
422 | return |
---|
423 | |
---|
424 | def test_export_student(self): |
---|
425 | # we can really export all payments of a certain student |
---|
426 | # set values we can expect in export file |
---|
427 | self.setup_student(self.student) |
---|
428 | exporter = PaymentsExporter() |
---|
429 | exporter.export_student(self.student, self.outfile) |
---|
430 | result = open(self.outfile, 'rb').read() |
---|
431 | self.assertEqual( |
---|
432 | result, |
---|
433 | 'ac,amount_auth,creation_date,p_category,p_current,p_id,' |
---|
434 | 'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,' |
---|
435 | 'r_code,r_desc,student_id,student_state,current_session\r\n' |
---|
436 | |
---|
437 | '666,0.0,2012-04-01 13:12:01,schoolfee,1,my-id,' |
---|
438 | 'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,' |
---|
439 | 'r-code,,A111111,created,2012\r\n' |
---|
440 | ) |
---|
441 | return |
---|