1 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
2 | ## This program is free software; you can redistribute it and/or modify |
---|
3 | ## it under the terms of the GNU General Public License as published by |
---|
4 | ## the Free Software Foundation; either version 2 of the License, or |
---|
5 | ## (at your option) any later version. |
---|
6 | ## |
---|
7 | ## This program is distributed in the hope that it will be useful, |
---|
8 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
10 | ## GNU General Public License for more details. |
---|
11 | ## |
---|
12 | ## You should have received a copy of the GNU General Public License |
---|
13 | ## along with this program; if not, write to the Free Software |
---|
14 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
15 | ## |
---|
16 | |
---|
17 | import datetime |
---|
18 | from zope.component import queryUtility |
---|
19 | from zope.interface.verify import verifyObject, verifyClass |
---|
20 | from hurry.workflow.interfaces import IWorkflowState |
---|
21 | from waeup.kofa.interfaces import ICSVExporter |
---|
22 | from waeup.kofa.schoolgrades import ResultEntry |
---|
23 | from waeup.kofa.students.tests.test_batching import StudentImportExportSetup |
---|
24 | |
---|
25 | from kofacustom.nigeria.utils.utils import NigeriaKofaUtils |
---|
26 | from kofacustom.nigeria.students.export import ( |
---|
27 | NigeriaStudentExporter, NigeriaStudentPaymentExporter, |
---|
28 | ClearanceRequestedStudentExporter, NigeriaDataForBursaryExporter, |
---|
29 | NigeriaTrimmedDataExporter) |
---|
30 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
31 | |
---|
32 | curr_year = datetime.datetime.now().year |
---|
33 | |
---|
34 | class NigeriaStudentExporterTest(StudentImportExportSetup): |
---|
35 | |
---|
36 | layer = FunctionalLayer |
---|
37 | |
---|
38 | def setUp(self): |
---|
39 | super(NigeriaStudentExporterTest, self).setUp() |
---|
40 | self.setup_for_export() |
---|
41 | result_entry = ResultEntry( |
---|
42 | sorted(NigeriaKofaUtils.EXAM_SUBJECTS_DICT.keys())[0], |
---|
43 | sorted(NigeriaKofaUtils.EXAM_GRADES)[0][0] |
---|
44 | ) |
---|
45 | self.student.alr_results = [ |
---|
46 | result_entry] |
---|
47 | self.student.fst_sit_results = [ |
---|
48 | result_entry] |
---|
49 | self.student.scd_sit_results = [ |
---|
50 | result_entry] |
---|
51 | return |
---|
52 | |
---|
53 | def test_ifaces(self): |
---|
54 | # make sure we fullfill interface contracts |
---|
55 | obj = NigeriaStudentExporter() |
---|
56 | verifyObject(ICSVExporter, obj) |
---|
57 | verifyClass(ICSVExporter, NigeriaStudentExporter) |
---|
58 | return |
---|
59 | |
---|
60 | |
---|
61 | def test_export_all(self): |
---|
62 | # we can really export students |
---|
63 | # set values we can expect in export file |
---|
64 | self.setup_student(self.student) |
---|
65 | exporter = NigeriaStudentExporter() |
---|
66 | exporter.export_all(self.app, self.outfile) |
---|
67 | result = open(self.outfile, 'rb').read() |
---|
68 | self.assertMatches( |
---|
69 | 'adm_code,alr_date,alr_fname,alr_no,alr_results,' |
---|
70 | 'clr_code,date_of_birth,def_adm,disabled,email,emp2_end,' |
---|
71 | 'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,' |
---|
72 | 'emp_reason,emp_start,employer,employer2,' |
---|
73 | 'financial_clearance_date,financially_cleared_by,' |
---|
74 | 'firstname,flash_notice,former_matric,' |
---|
75 | 'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,' |
---|
76 | 'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,' |
---|
77 | 'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,' |
---|
78 | 'hq_school,hq_session,hq_type,is_staff,lastname,lga,' |
---|
79 | 'marit_stat,matric_number,middlename,nationality,' |
---|
80 | 'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,' |
---|
81 | 'nysc_lga,nysc_location,nysc_year,officer_comment,parents_email,' |
---|
82 | 'perm_address,personal_updated,phone,physical_clearance_date,' |
---|
83 | 'provisionally_cleared,reg_number,' |
---|
84 | 'religion,scd_sit_date,scd_sit_fname,scd_sit_no,' |
---|
85 | 'scd_sit_results,scd_sit_type,sex,student_id,' |
---|
86 | 'suspended,suspended_comment,password,state,history,certcode,is_postgrad,' |
---|
87 | 'current_level,current_session\r\nmy adm code,,,,' |
---|
88 | '"[(\'accounts\', \'A\')]",my clr code,1981-02-04#,,,' |
---|
89 | 'anna@sample.com,,,,,,,,,,,,,Anna,,,,,,"[(\'accounts\', \'A\')]"' |
---|
90 | ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,,' |
---|
91 | '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,' |
---|
92 | '"[(\'accounts\', \'A\')]",,f,A111111,0,,,created,' |
---|
93 | '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],' |
---|
94 | 'CERT1,0,200,2012\r\n', |
---|
95 | result |
---|
96 | ) |
---|
97 | return |
---|
98 | |
---|
99 | class NigeriaStudentPaymentExporterTest(StudentImportExportSetup): |
---|
100 | |
---|
101 | layer = FunctionalLayer |
---|
102 | |
---|
103 | def setUp(self): |
---|
104 | super(NigeriaStudentPaymentExporterTest, self).setUp() |
---|
105 | self.setup_for_export() |
---|
106 | return |
---|
107 | |
---|
108 | def test_ifaces(self): |
---|
109 | # make sure we fullfill interface contracts |
---|
110 | obj = NigeriaStudentPaymentExporter() |
---|
111 | verifyObject(ICSVExporter, obj) |
---|
112 | verifyClass(ICSVExporter, NigeriaStudentPaymentExporter) |
---|
113 | return |
---|
114 | |
---|
115 | def test_export_all(self): |
---|
116 | # we can really export students |
---|
117 | # set values we can expect in export file |
---|
118 | self.setup_student(self.student) |
---|
119 | self.student['payments']['my-payment'].r_company = 'interswitch' |
---|
120 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
121 | exporter = NigeriaStudentPaymentExporter() |
---|
122 | exporter.export_all(self.app, self.outfile) |
---|
123 | result = open(self.outfile, 'rb').read() |
---|
124 | self.assertMatches( |
---|
125 | 'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_current,' |
---|
126 | 'p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,payment_date,provider_amt,' |
---|
127 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
128 | 'r_pay_reference,r_payment_link,thirdparty_amt,student_id,state,' |
---|
129 | 'current_session\r\n' |
---|
130 | '666,12.12,2012-04-01 13:12:01#,,,schoolfee,[],1,my-id,p-item,' |
---|
131 | '100,,%s,,paid,2012-04-01 14:12:01#,,12.12,' |
---|
132 | '789,r-code,interswitch,,,,,A111111,created,2012\r\n' % (curr_year-6), |
---|
133 | result |
---|
134 | ) |
---|
135 | return |
---|
136 | |
---|
137 | class ClearanceRequestedStudentExporterTest(StudentImportExportSetup): |
---|
138 | |
---|
139 | layer = FunctionalLayer |
---|
140 | |
---|
141 | def setUp(self): |
---|
142 | super(ClearanceRequestedStudentExporterTest, self).setUp() |
---|
143 | self.setup_for_export() |
---|
144 | return |
---|
145 | |
---|
146 | def test_ifaces(self): |
---|
147 | # make sure we fullfill interface contracts |
---|
148 | obj = ClearanceRequestedStudentExporter() |
---|
149 | verifyObject(ICSVExporter, obj) |
---|
150 | verifyClass(ICSVExporter, ClearanceRequestedStudentExporter) |
---|
151 | return |
---|
152 | |
---|
153 | def test_export_all(self): |
---|
154 | # we can really export students |
---|
155 | # set values we can expect in export file |
---|
156 | self.setup_student(self.student) |
---|
157 | self.student.physical_clearance_date = 'Come soon' |
---|
158 | IWorkflowState(self.student).setState('clearance requested') |
---|
159 | exporter = ClearanceRequestedStudentExporter() |
---|
160 | exporter.export_all(self.app, self.outfile) |
---|
161 | result = open(self.outfile, 'rb').read() |
---|
162 | self.assertMatches( |
---|
163 | 'student_id,reg_number,display_fullname,state,current_session,' |
---|
164 | 'history,physical_clearance_date,email,phone\r\n' |
---|
165 | 'A111111,123,Anna M. Tester,clearance requested,' |
---|
166 | '2012,2014-12-02 07:17:02 WAT - Record created by system,' |
---|
167 | 'Come soon,anna@sample.com,+234-123-12345\r\n', |
---|
168 | result |
---|
169 | ) |
---|
170 | return |
---|
171 | |
---|
172 | class BursaryDataExporterTest(StudentImportExportSetup): |
---|
173 | |
---|
174 | layer = FunctionalLayer |
---|
175 | |
---|
176 | def setUp(self): |
---|
177 | super(BursaryDataExporterTest, self).setUp() |
---|
178 | self.setup_for_export() |
---|
179 | return |
---|
180 | |
---|
181 | def test_export_all(self): |
---|
182 | # we can really export all payments |
---|
183 | # set values we can expect in export file |
---|
184 | self.setup_student(self.student) |
---|
185 | exporter = NigeriaDataForBursaryExporter() |
---|
186 | exporter.export_all(self.app, self.outfile) |
---|
187 | result = open(self.outfile, 'rb').read() |
---|
188 | self.assertEqual( |
---|
189 | result, |
---|
190 | 'ac,amount_auth,creation_date,formatted_p_date,gateway_amt,net_amt,' |
---|
191 | 'p_category,p_combi,p_current,p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,' |
---|
192 | 'payment_date,provider_amt,r_amount_approved,r_card_num,r_code,' |
---|
193 | 'r_company,r_desc,r_pay_reference,r_payment_link,thirdparty_amt,student_id,' |
---|
194 | 'matric_number,reg_number,firstname,middlename,lastname,sex,state,' |
---|
195 | 'current_session,entry_session,entry_mode,faccode,depcode,certcode,lga\r\n' |
---|
196 | |
---|
197 | '666,12.12,%s-04-01 13:12:01#,,,,schoolfee,[],1,my-id,p-item,' |
---|
198 | '100,,%s,,paid,%s-04-01 14:12:01#,,12.12,,r-code,,,,,,A111111,' |
---|
199 | '234,123,Anna,M.,Tester,f,created,2012,2010,ug_ft,NA,NA,CERT1,\r\n' |
---|
200 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
201 | ) |
---|
202 | return |
---|
203 | |
---|
204 | class NigeriaStudentTrimmedDataExporterTest(StudentImportExportSetup): |
---|
205 | |
---|
206 | layer = FunctionalLayer |
---|
207 | |
---|
208 | std_csv_entry = ( |
---|
209 | 'my adm code,my clr code,1981-02-04#,anna@sample.com,,' |
---|
210 | 'Anna,,Tester,234,M.,NG,,,"Studentroad 21\nLagos 123456\n",,' |
---|
211 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
212 | ) |
---|
213 | |
---|
214 | def setUp(self): |
---|
215 | super(NigeriaStudentTrimmedDataExporterTest, self).setUp() |
---|
216 | self.setup_for_export() |
---|
217 | self.student.lga = 'abia_aba_north' |
---|
218 | return |
---|
219 | |
---|
220 | def test_export_all(self): |
---|
221 | # we can really export students |
---|
222 | # set values we can expect in export file |
---|
223 | self.setup_student(self.student) |
---|
224 | exporter = NigeriaTrimmedDataExporter() |
---|
225 | exporter.export_all(self.app, self.outfile) |
---|
226 | result = open(self.outfile, 'rb').read() |
---|
227 | self.assertTrue( |
---|
228 | 'student_id,matric_number,reg_number,firstname,middlename,' |
---|
229 | 'lastname,sex,email,phone,nationality,date_of_birth,state,' |
---|
230 | 'current_mode,certcode,faccode,depcode,current_level,' |
---|
231 | 'current_session,current_verdict,entry_session,lg_state,lg_area\r\n' |
---|
232 | 'A111111,234,123,Anna,M.,Tester,f,anna@sample.com,+234-123-12345#,' |
---|
233 | 'NG,1981-02-04#,created,ug_ft,CERT1,NA,NA,200,2012,0,2010,' |
---|
234 | 'abia,aba-north' |
---|
235 | in result |
---|
236 | ) |
---|
237 | return |
---|