[12109] | 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 | |
---|
[9044] | 17 | import datetime |
---|
| 18 | from zope.component import queryUtility |
---|
| 19 | from zope.interface.verify import verifyObject, verifyClass |
---|
[12108] | 20 | from hurry.workflow.interfaces import IWorkflowState |
---|
[9044] | 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 |
---|
[10757] | 26 | from kofacustom.nigeria.students.export import ( |
---|
[12875] | 27 | NigeriaStudentExporter, NigeriaStudentPaymentExporter, |
---|
[16195] | 28 | ClearanceRequestedStudentExporter, NigeriaDataForBursaryExporter, |
---|
| 29 | NigeriaTrimmedDataExporter) |
---|
[9044] | 30 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
| 31 | |
---|
[15045] | 32 | curr_year = datetime.datetime.now().year |
---|
[9044] | 33 | |
---|
[12080] | 34 | class NigeriaStudentExporterTest(StudentImportExportSetup): |
---|
[9044] | 35 | |
---|
| 36 | layer = FunctionalLayer |
---|
| 37 | |
---|
| 38 | def setUp(self): |
---|
[12080] | 39 | super(NigeriaStudentExporterTest, self).setUp() |
---|
[9044] | 40 | self.setup_for_export() |
---|
| 41 | result_entry = ResultEntry( |
---|
[11780] | 42 | sorted(NigeriaKofaUtils.EXAM_SUBJECTS_DICT.keys())[0], |
---|
| 43 | sorted(NigeriaKofaUtils.EXAM_GRADES)[0][0] |
---|
[9044] | 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 |
---|
[12080] | 55 | obj = NigeriaStudentExporter() |
---|
[9044] | 56 | verifyObject(ICSVExporter, obj) |
---|
[12080] | 57 | verifyClass(ICSVExporter, NigeriaStudentExporter) |
---|
[9044] | 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) |
---|
[12080] | 65 | exporter = NigeriaStudentExporter() |
---|
[9044] | 66 | exporter.export_all(self.app, self.outfile) |
---|
| 67 | result = open(self.outfile, 'rb').read() |
---|
[9562] | 68 | self.assertMatches( |
---|
[13109] | 69 | 'adm_code,alr_date,alr_fname,alr_no,alr_results,' |
---|
[12120] | 70 | 'clr_code,date_of_birth,def_adm,disabled,email,emp2_end,' |
---|
[9046] | 71 | 'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,' |
---|
[13620] | 72 | 'emp_reason,emp_start,employer,employer2,' |
---|
[17866] | 73 | 'final_clearance_date,finally_cleared_by,' |
---|
[13620] | 74 | 'financial_clearance_date,financially_cleared_by,' |
---|
[13712] | 75 | 'firstname,flash_notice,former_matric,' |
---|
[9046] | 76 | 'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,' |
---|
| 77 | 'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,' |
---|
[9562] | 78 | 'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,' |
---|
| 79 | 'hq_school,hq_session,hq_type,is_staff,lastname,lga,' |
---|
| 80 | 'marit_stat,matric_number,middlename,nationality,' |
---|
[9567] | 81 | 'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,' |
---|
[15651] | 82 | 'nysc_lga,nysc_location,nysc_year,officer_comment,parents_email,' |
---|
[14274] | 83 | 'perm_address,personal_updated,phone,physical_clearance_date,' |
---|
| 84 | 'provisionally_cleared,reg_number,' |
---|
[9562] | 85 | 'religion,scd_sit_date,scd_sit_fname,scd_sit_no,' |
---|
| 86 | 'scd_sit_results,scd_sit_type,sex,student_id,' |
---|
[9704] | 87 | 'suspended,suspended_comment,password,state,history,certcode,is_postgrad,' |
---|
[9562] | 88 | 'current_level,current_session\r\nmy adm code,,,,' |
---|
[13109] | 89 | '"[(\'accounts\', \'A\')]",my clr code,1981-02-04#,,,' |
---|
[17866] | 90 | 'anna@sample.com,,,,,,,,,,,,,,,Anna,,,,,,"[(\'accounts\', \'A\')]"' |
---|
[15651] | 91 | ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,,' |
---|
[14274] | 92 | '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,' |
---|
[11780] | 93 | '"[(\'accounts\', \'A\')]",,f,A111111,0,,,created,' |
---|
[9562] | 94 | '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],' |
---|
| 95 | 'CERT1,0,200,2012\r\n', |
---|
| 96 | result |
---|
[9044] | 97 | ) |
---|
| 98 | return |
---|
| 99 | |
---|
[12875] | 100 | class NigeriaStudentPaymentExporterTest(StudentImportExportSetup): |
---|
[9044] | 101 | |
---|
[10757] | 102 | layer = FunctionalLayer |
---|
| 103 | |
---|
| 104 | def setUp(self): |
---|
[12875] | 105 | super(NigeriaStudentPaymentExporterTest, self).setUp() |
---|
[10757] | 106 | self.setup_for_export() |
---|
| 107 | return |
---|
| 108 | |
---|
| 109 | def test_ifaces(self): |
---|
| 110 | # make sure we fullfill interface contracts |
---|
[12875] | 111 | obj = NigeriaStudentPaymentExporter() |
---|
[10757] | 112 | verifyObject(ICSVExporter, obj) |
---|
[12875] | 113 | verifyClass(ICSVExporter, NigeriaStudentPaymentExporter) |
---|
[10757] | 114 | return |
---|
| 115 | |
---|
| 116 | def test_export_all(self): |
---|
| 117 | # we can really export students |
---|
| 118 | # set values we can expect in export file |
---|
| 119 | self.setup_student(self.student) |
---|
[15045] | 120 | self.student['payments']['my-payment'].r_company = 'interswitch' |
---|
[10757] | 121 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
[12875] | 122 | exporter = NigeriaStudentPaymentExporter() |
---|
[10757] | 123 | exporter.export_all(self.app, self.outfile) |
---|
| 124 | result = open(self.outfile, 'rb').read() |
---|
| 125 | self.assertMatches( |
---|
[17246] | 126 | 'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_currency,p_current,' |
---|
[16483] | 127 | 'p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,payment_date,provider_amt,' |
---|
[10757] | 128 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
[17242] | 129 | 'r_pay_reference,r_payment_link,thirdparty_amt,student_id,state,' |
---|
[10757] | 130 | 'current_session\r\n' |
---|
[17246] | 131 | '666,12.12,2012-04-01 13:12:01#,,,schoolfee,[],,1,my-id,p-item,' |
---|
[16483] | 132 | '100,,%s,,paid,2012-04-01 14:12:01#,,12.12,' |
---|
[17242] | 133 | '789,r-code,interswitch,,,,,A111111,created,2012\r\n' % (curr_year-6), |
---|
[10757] | 134 | result |
---|
| 135 | ) |
---|
| 136 | return |
---|
[12108] | 137 | |
---|
| 138 | class ClearanceRequestedStudentExporterTest(StudentImportExportSetup): |
---|
| 139 | |
---|
| 140 | layer = FunctionalLayer |
---|
| 141 | |
---|
| 142 | def setUp(self): |
---|
| 143 | super(ClearanceRequestedStudentExporterTest, self).setUp() |
---|
| 144 | self.setup_for_export() |
---|
| 145 | return |
---|
| 146 | |
---|
| 147 | def test_ifaces(self): |
---|
| 148 | # make sure we fullfill interface contracts |
---|
| 149 | obj = ClearanceRequestedStudentExporter() |
---|
| 150 | verifyObject(ICSVExporter, obj) |
---|
| 151 | verifyClass(ICSVExporter, ClearanceRequestedStudentExporter) |
---|
| 152 | return |
---|
| 153 | |
---|
| 154 | def test_export_all(self): |
---|
| 155 | # we can really export students |
---|
| 156 | # set values we can expect in export file |
---|
| 157 | self.setup_student(self.student) |
---|
[12120] | 158 | self.student.physical_clearance_date = 'Come soon' |
---|
[12108] | 159 | IWorkflowState(self.student).setState('clearance requested') |
---|
| 160 | exporter = ClearanceRequestedStudentExporter() |
---|
| 161 | exporter.export_all(self.app, self.outfile) |
---|
| 162 | result = open(self.outfile, 'rb').read() |
---|
| 163 | self.assertMatches( |
---|
| 164 | 'student_id,reg_number,display_fullname,state,current_session,' |
---|
[12392] | 165 | 'history,physical_clearance_date,email,phone\r\n' |
---|
[12108] | 166 | 'A111111,123,Anna M. Tester,clearance requested,' |
---|
| 167 | '2012,2014-12-02 07:17:02 WAT - Record created by system,' |
---|
[12392] | 168 | 'Come soon,anna@sample.com,+234-123-12345\r\n', |
---|
[12108] | 169 | result |
---|
| 170 | ) |
---|
| 171 | return |
---|
[15351] | 172 | |
---|
| 173 | class BursaryDataExporterTest(StudentImportExportSetup): |
---|
| 174 | |
---|
| 175 | layer = FunctionalLayer |
---|
| 176 | |
---|
| 177 | def setUp(self): |
---|
| 178 | super(BursaryDataExporterTest, self).setUp() |
---|
| 179 | self.setup_for_export() |
---|
| 180 | return |
---|
| 181 | |
---|
| 182 | def test_export_all(self): |
---|
| 183 | # we can really export all payments |
---|
| 184 | # set values we can expect in export file |
---|
| 185 | self.setup_student(self.student) |
---|
| 186 | exporter = NigeriaDataForBursaryExporter() |
---|
| 187 | exporter.export_all(self.app, self.outfile) |
---|
| 188 | result = open(self.outfile, 'rb').read() |
---|
| 189 | self.assertEqual( |
---|
| 190 | result, |
---|
[15731] | 191 | 'ac,amount_auth,creation_date,formatted_p_date,gateway_amt,net_amt,' |
---|
[17246] | 192 | 'p_category,p_combi,p_currency,p_current,p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,' |
---|
[15351] | 193 | 'payment_date,provider_amt,r_amount_approved,r_card_num,r_code,' |
---|
[17242] | 194 | 'r_company,r_desc,r_pay_reference,r_payment_link,thirdparty_amt,student_id,' |
---|
[16334] | 195 | 'matric_number,reg_number,firstname,middlename,lastname,sex,state,' |
---|
[15351] | 196 | 'current_session,entry_session,entry_mode,faccode,depcode,certcode,lga\r\n' |
---|
| 197 | |
---|
[17246] | 198 | '666,12.12,%s-04-01 13:12:01#,,,,schoolfee,[],,1,my-id,p-item,' |
---|
[17242] | 199 | '100,,%s,,paid,%s-04-01 14:12:01#,,12.12,,r-code,,,,,,A111111,' |
---|
[16334] | 200 | '234,123,Anna,M.,Tester,f,created,2012,2010,ug_ft,NA,NA,CERT1,\r\n' |
---|
[15351] | 201 | % (curr_year-6, curr_year-6, curr_year-6) |
---|
| 202 | ) |
---|
| 203 | return |
---|
[16195] | 204 | |
---|
| 205 | class NigeriaStudentTrimmedDataExporterTest(StudentImportExportSetup): |
---|
| 206 | |
---|
| 207 | layer = FunctionalLayer |
---|
| 208 | |
---|
| 209 | std_csv_entry = ( |
---|
| 210 | 'my adm code,my clr code,1981-02-04#,anna@sample.com,,' |
---|
| 211 | 'Anna,,Tester,234,M.,NG,,,"Studentroad 21\nLagos 123456\n",,' |
---|
| 212 | '+234-123-12345#,123,f,A111111,0,,,created' |
---|
| 213 | ) |
---|
| 214 | |
---|
| 215 | def setUp(self): |
---|
| 216 | super(NigeriaStudentTrimmedDataExporterTest, self).setUp() |
---|
| 217 | self.setup_for_export() |
---|
| 218 | self.student.lga = 'abia_aba_north' |
---|
| 219 | return |
---|
| 220 | |
---|
| 221 | def test_export_all(self): |
---|
| 222 | # we can really export students |
---|
| 223 | # set values we can expect in export file |
---|
| 224 | self.setup_student(self.student) |
---|
| 225 | exporter = NigeriaTrimmedDataExporter() |
---|
| 226 | exporter.export_all(self.app, self.outfile) |
---|
| 227 | result = open(self.outfile, 'rb').read() |
---|
| 228 | self.assertTrue( |
---|
| 229 | 'student_id,matric_number,reg_number,firstname,middlename,' |
---|
| 230 | 'lastname,sex,email,phone,nationality,date_of_birth,state,' |
---|
| 231 | 'current_mode,certcode,faccode,depcode,current_level,' |
---|
| 232 | 'current_session,current_verdict,entry_session,lg_state,lg_area\r\n' |
---|
| 233 | 'A111111,234,123,Anna,M.,Tester,f,anna@sample.com,+234-123-12345#,' |
---|
| 234 | 'NG,1981-02-04#,created,ug_ft,CERT1,NA,NA,200,2012,0,2010,' |
---|
| 235 | 'abia,aba-north' |
---|
| 236 | in result |
---|
| 237 | ) |
---|
| 238 | return |
---|