source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/students/tests/test_export.py @ 17936

Last change on this file since 17936 was 17866, checked in by Henrik Bettermann, 3 months ago

Implement final clearance.

  • Property svn:keywords set to Id
File size: 10.0 KB
Line 
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
17import datetime
18from zope.component import queryUtility
19from zope.interface.verify import verifyObject, verifyClass
20from hurry.workflow.interfaces import IWorkflowState
21from waeup.kofa.interfaces import ICSVExporter
22from waeup.kofa.schoolgrades import ResultEntry
23from waeup.kofa.students.tests.test_batching import StudentImportExportSetup
24
25from kofacustom.nigeria.utils.utils import NigeriaKofaUtils
26from kofacustom.nigeria.students.export import (
27    NigeriaStudentExporter, NigeriaStudentPaymentExporter,
28    ClearanceRequestedStudentExporter, NigeriaDataForBursaryExporter,
29    NigeriaTrimmedDataExporter)
30from kofacustom.nigeria.testing import FunctionalLayer
31
32curr_year = datetime.datetime.now().year
33
34class 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            'final_clearance_date,finally_cleared_by,'
74            'financial_clearance_date,financially_cleared_by,'
75            'firstname,flash_notice,former_matric,'
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,'
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,'
81            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
82            'nysc_lga,nysc_location,nysc_year,officer_comment,parents_email,'
83            'perm_address,personal_updated,phone,physical_clearance_date,'
84            'provisionally_cleared,reg_number,'
85            'religion,scd_sit_date,scd_sit_fname,scd_sit_no,'
86            'scd_sit_results,scd_sit_type,sex,student_id,'
87            'suspended,suspended_comment,password,state,history,certcode,is_postgrad,'
88            'current_level,current_session\r\nmy adm code,,,,'
89            '"[(\'accounts\', \'A\')]",my clr code,1981-02-04#,,,'
90            'anna@sample.com,,,,,,,,,,,,,,,Anna,,,,,,"[(\'accounts\', \'A\')]"'
91            ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,,'
92            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,'
93            '"[(\'accounts\', \'A\')]",,f,A111111,0,,,created,'
94            '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],'
95            'CERT1,0,200,2012\r\n',
96            result
97            )
98        return
99
100class NigeriaStudentPaymentExporterTest(StudentImportExportSetup):
101
102    layer = FunctionalLayer
103
104    def setUp(self):
105        super(NigeriaStudentPaymentExporterTest, self).setUp()
106        self.setup_for_export()
107        return
108
109    def test_ifaces(self):
110        # make sure we fullfill interface contracts
111        obj = NigeriaStudentPaymentExporter()
112        verifyObject(ICSVExporter, obj)
113        verifyClass(ICSVExporter, NigeriaStudentPaymentExporter)
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)
120        self.student['payments']['my-payment'].r_company = 'interswitch'
121        self.student['payments']['my-payment'].r_card_num = '789'
122        exporter = NigeriaStudentPaymentExporter()
123        exporter.export_all(self.app, self.outfile)
124        result = open(self.outfile, 'rb').read()
125        self.assertMatches(
126            'ac,amount_auth,creation_date,gateway_amt,net_amt,p_category,p_combi,p_currency,p_current,'
127            'p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,payment_date,provider_amt,'
128            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
129            'r_pay_reference,r_payment_link,thirdparty_amt,student_id,state,'
130            'current_session\r\n'
131            '666,12.12,2012-04-01 13:12:01#,,,schoolfee,[],,1,my-id,p-item,'
132            '100,,%s,,paid,2012-04-01 14:12:01#,,12.12,'
133            '789,r-code,interswitch,,,,,A111111,created,2012\r\n' % (curr_year-6),
134            result
135            )
136        return
137
138class 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)
158        self.student.physical_clearance_date = 'Come soon'
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,'
165            'history,physical_clearance_date,email,phone\r\n'
166            'A111111,123,Anna M. Tester,clearance requested,'
167            '2012,2014-12-02 07:17:02 WAT - Record created by system,'
168            'Come soon,anna@sample.com,+234-123-12345\r\n',
169            result
170            )
171        return
172
173class 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,
191            'ac,amount_auth,creation_date,formatted_p_date,gateway_amt,net_amt,'
192            'p_category,p_combi,p_currency,p_current,p_id,p_item,p_level,p_option,p_session,p_split_data,p_state,'
193            'payment_date,provider_amt,r_amount_approved,r_card_num,r_code,'
194            'r_company,r_desc,r_pay_reference,r_payment_link,thirdparty_amt,student_id,'
195            'matric_number,reg_number,firstname,middlename,lastname,sex,state,'
196            'current_session,entry_session,entry_mode,faccode,depcode,certcode,lga\r\n'
197
198            '666,12.12,%s-04-01 13:12:01#,,,,schoolfee,[],,1,my-id,p-item,'
199            '100,,%s,,paid,%s-04-01 14:12:01#,,12.12,,r-code,,,,,,A111111,'
200            '234,123,Anna,M.,Tester,f,created,2012,2010,ug_ft,NA,NA,CERT1,\r\n'
201            % (curr_year-6, curr_year-6, curr_year-6)
202            )
203        return
204
205class 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
Note: See TracBrowser for help on using the repository browser.