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