source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_export.py @ 17671

Last change on this file since 17671 was 17289, checked in by Henrik Bettermann, 2 years ago

Adjust to base package.

  • Property svn:keywords set to Id
File size: 9.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.schoolgrades import ResultEntry
6from waeup.kofa.students.tests.test_batching import (
7    StudentImportExportSetup, curr_year)
8from waeup.aaue.utils.utils import CustomKofaUtils
9from waeup.aaue.students.export import (
10    CustomStudentExporter, CustomStudentPaymentExporter,
11    CustomStudentStudyLevelExporter,
12    CustomCourseTicketExporter,
13    LevelReportDataExporter,
14    CustomStudentStudyCourseExporter,
15    OutstandingCourses2Exporter)
16from waeup.aaue.testing import FunctionalLayer
17
18
19class CustomStudentExporterTest(StudentImportExportSetup):
20
21    layer = FunctionalLayer
22
23    def setUp(self):
24        super(CustomStudentExporterTest, self).setUp()
25        self.setup_for_export()
26        result_entry = ResultEntry(
27            CustomKofaUtils.EXAM_SUBJECTS_DICT.keys()[0],
28            CustomKofaUtils.EXAM_GRADES[0][0]
29            )
30        self.student.alr_results = [
31            result_entry]
32        self.student.fst_sit_results = [
33            result_entry]
34        self.student.scd_sit_results = [
35            result_entry]
36        return
37
38    def test_ifaces(self):
39        # make sure we fullfill interface contracts
40        obj = CustomStudentExporter()
41        verifyObject(ICSVExporter, obj)
42        verifyClass(ICSVExporter, CustomStudentExporter)
43        return
44
45
46    def disabled_test_export_all(self):
47        # we can really export students
48        # set values we can expect in export file
49        self.setup_student(self.student)
50        exporter = CustomStudentExporter()
51        exporter.export_all(self.app, self.outfile)
52        result = open(self.outfile, 'rb').read()
53        self.assertMatches(
54            'adm_code,alr_date,alr_fname,alr_no,alr_results,'
55            'application_number,clr_code,'
56            'date_of_birth,def_adm,disabled,email,emp2_end,emp2_position,'
57            'emp2_reason,emp2_start,emp_end,emp_position,emp_reason,'
58            'emp_start,employer,employer2,father_address,father_name,'
59            'father_phone,father_work,'
60            'financial_clearance_date,financially_cleared_by,'
61            'firstname,flash_notice,former_matric,fst_sit_date,'
62            'fst_sit_fname,fst_sit_no,fst_sit_results,fst_sit_type,hq2_degree,'
63            'hq2_disc,hq2_matric_no,hq2_school,hq2_session,hq2_type,'
64            'hq_degree,hq_disc,hq_fname,hq_matric_no,hq_school,hq_session,'
65            'hq_type,is_staff,lastname,lga,marit_stat,matric_number,'
66            'middlename,mother_address,mother_name,mother_phone,'
67            'mother_work,nationality,next_kin_address,next_kin_name,'
68            'next_kin_phone,next_kin_relation,nysc_lga,nysc_location,'
69            'nysc_year,officer_comment,perm_address,personal_updated,'
70            'phone,phone_personal,physical_clearance_date,reg_number,'
71            'religion,sc_pin,sc_serial_number,scd_sit_date,'
72            'scd_sit_fname,scd_sit_no,scd_sit_results,'
73            'scd_sit_type,sex,student_id,suspended,suspended_comment,password,'
74            'state,history,certcode,is_postgrad,current_level,current_session'
75            '\r\n'
76            'my adm code,,,,"[(\'printing_craft_practice\', \'A1\')]",,'
77            'my clr code,1981-02-04#,,,anna@sample.com,,,,,,,,,,,,,,,,,Anna,,,,,,'
78            '"[(\'printing_craft_practice\', \'A1\')]",,,,,,,,,,,,,,,,Tester,,,'
79            '234,M.,,,,,NG,,,,,,,,,"Studentroad 21\nLagos 123456\n",,'
80            '+234-123-12345#,,,123,,,,,,,'
81            '"[(\'printing_craft_practice\', \'A1\')]",,f,A111111,0,,,'
82            'created,[u\'2015-10-26 17:45:56 WAT - Record created by system\'],'
83            'CERT1,0,200,2012\r\n',
84            result
85            )
86        return
87
88class CustomStudentPaymentExporterTest(StudentImportExportSetup):
89
90    layer = FunctionalLayer
91
92    def setUp(self):
93        super(CustomStudentPaymentExporterTest, self).setUp()
94        self.setup_for_export()
95        return
96
97    def test_ifaces(self):
98        # make sure we fullfill interface contracts
99        obj = CustomStudentPaymentExporter()
100        verifyObject(ICSVExporter, obj)
101        verifyClass(ICSVExporter, CustomStudentPaymentExporter)
102        return
103
104    def test_export_all(self):
105        # we can really export students
106        # set values we can expect in export file
107        self.setup_student(self.student)
108        self.student['payments']['my-payment'].r_company = 'interswatch'
109        self.student['payments']['my-payment'].r_card_num = '789'
110        exporter = CustomStudentPaymentExporter()
111        exporter.export_all(self.app, self.outfile)
112        result = open(self.outfile, 'rb').read()
113        self.assertMatches(
114            'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_currency,p_current,'
115            'p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,payment_date,provider_amt,'
116            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
117            'r_pay_reference,r_payment_link,thirdparty_amt,student_id,state,'
118            'current_session\r\n'
119            '666,12.12,%s-04-01 13:12:01#,,,schoolfee,[],,1,my-id,p-item,'
120            '100,,%s,,paid,%s-04-01 14:12:01#,,12.12,'
121            '789,r-code,interswatch,,,,,A111111,created,2012\r\n'
122            % (curr_year-6, curr_year-6, curr_year-6), result
123            )
124        return
125
126class CustomStudentStudyCourseExporterTest(StudentImportExportSetup):
127
128    layer = FunctionalLayer
129
130    def setUp(self):
131        super(CustomStudentStudyCourseExporterTest, self).setUp()
132        self.setup_for_export()
133        return
134
135    def test_export_all(self):
136        self.setup_student(self.student)
137        exporter = CustomStudentStudyCourseExporter()
138        exporter.export_all(self.app, self.outfile)
139        result = open(self.outfile, 'rb').read()
140        self.assertEqual(
141            result,
142            'certificate,current_level,current_session,current_verdict,'
143            'entry_mode,entry_session,imported_cgpa,previous_verdict,'
144            'matric_number,state,student_id\r\n'
145            'CERT1,200,2012,0,ug_ft,2010,,0,234,created,A111111\r\n'
146            )
147        return
148
149
150class CustomStudentStudyLevelExporterTest(StudentImportExportSetup):
151
152    layer = FunctionalLayer
153
154    def setUp(self):
155        super(CustomStudentStudyLevelExporterTest, self).setUp()
156        self.setup_for_export()
157        return
158
159    def test_export_all(self):
160        # we can really export study levels
161        # set values we can expect in export file
162        self.setup_student(self.student)
163        exporter = CustomStudentStudyLevelExporter()
164        exporter.export_all(self.app, self.outfile)
165        result = open(self.outfile, 'rb').read()
166        self.assertEqual(
167            result,
168            'gpa,imported_cgpa,imported_gpa,'
169            'level,level_session,level_verdict,total_credits,'
170            'total_credits_s1,total_credits_s2,transcript_remark,'
171            'validated_by,validation_date,'
172            'student_id,matric_number,number_of_tickets,certcode,cgpa\r\n'
173            '0.00,,,100,2012,A,100,,,,,,A111111,234,1,CERT1,0.0\r\n'
174            )
175        return
176
177class CustomCourseTicketExporterTest(StudentImportExportSetup):
178
179    layer = FunctionalLayer
180
181    def setUp(self):
182        super(CustomCourseTicketExporterTest, self).setUp()
183        self.setup_for_export()
184        return
185
186    def test_export_all(self):
187        # we can really export all course tickets
188        # set values we can expect in export file
189        self.setup_student(self.student)
190        exporter = CustomCourseTicketExporter()
191        exporter.export_all(self.app, self.outfile)
192        result = open(self.outfile, 'rb').read()
193        self.assertEqual(
194            result,
195            'automatic,ca,carry_over,code,course_category,credits,dcode,fcode,imported_ts,level,level_session,'
196            'mandatory,outstanding,passmark,score,semester,ticket_session,title,student_id,certcode,'
197            'display_fullname,matric_number,state,grade,total_score,total_credits,previous\r\n'
198            '1,,1,CRS1,,100,DEP1,FAC1,,100,2012,0,0,100,,2,,Course 1,A111111,CERT1,'
199            '"TESTER, Anna M.",234,created,,,100,0\r\n'
200            )
201        return
202
203class LevelReportDataExporterTest(StudentImportExportSetup):
204
205    layer = FunctionalLayer
206
207    def setUp(self):
208        super(LevelReportDataExporterTest, self).setUp()
209        self.setup_for_export()
210        return
211
212    def test_export_all(self):
213        # we can really export study levels
214        # set values we can expect in export file
215        self.setup_student(self.student)
216        exporter = LevelReportDataExporter()
217        exporter.export_all(self.app, self.outfile)
218        result = open(self.outfile, 'rb').read()
219        self.assertEqual(
220            result,
221            'matric_number,display_fullname,level,level_session,'
222            'credits_counted,credits_passed,'
223            'level_gpa,failed_courses,not_taken_courses,cum_credits_taken,'
224            'cum_credits_passed,cgpa,remark\r\n'
225            '234,"TESTER, Anna M.",100,2012,0,0,0.000,,CRS1 ,0,0,0.000,\r\n'
226            )
227        return
228
229class OutstandingCourses2ExporterTest(StudentImportExportSetup):
230
231    layer = FunctionalLayer
232
233    def setUp(self):
234        super(OutstandingCourses2ExporterTest, self).setUp()
235        self.setup_for_export()
236        return
237
238    def test_export_all(self):
239        # we can really export all course tickets
240        # set values we can expect in export file
241        self.setup_student(self.student)
242        self.student['studycourse']['100']['CRS1'].course_category = 'C'
243        exporter = OutstandingCourses2Exporter()
244        exporter.export_all(self.app, self.outfile)
245        result = open(self.outfile, 'rb').read()
246        self.assertEqual(
247            result,
248            'student_id,matric_number,certcode,display_fullname,code,'
249            'course_category,remark\r\n'
250            'A111111,234,CERT1,"TESTER, Anna M.",CRS1,C,nottaken\r\n'
251            )
252        return
253
254
Note: See TracBrowser for help on using the repository browser.