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

Last change on this file since 15665 was 15665, checked in by Henrik Bettermann, 5 years ago

Adjust to base package.

  • Property svn:keywords set to Id
File size: 8.4 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)
29from kofacustom.nigeria.testing import FunctionalLayer
30
31curr_year = datetime.datetime.now().year
32
33class NigeriaStudentExporterTest(StudentImportExportSetup):
34
35    layer = FunctionalLayer
36
37    def setUp(self):
38        super(NigeriaStudentExporterTest, self).setUp()
39        self.setup_for_export()
40        result_entry = ResultEntry(
41            sorted(NigeriaKofaUtils.EXAM_SUBJECTS_DICT.keys())[0],
42            sorted(NigeriaKofaUtils.EXAM_GRADES)[0][0]
43            )
44        self.student.alr_results = [
45            result_entry]
46        self.student.fst_sit_results = [
47            result_entry]
48        self.student.scd_sit_results = [
49            result_entry]
50        return
51
52    def test_ifaces(self):
53        # make sure we fullfill interface contracts
54        obj = NigeriaStudentExporter()
55        verifyObject(ICSVExporter, obj)
56        verifyClass(ICSVExporter, NigeriaStudentExporter)
57        return
58
59
60    def test_export_all(self):
61        # we can really export students
62        # set values we can expect in export file
63        self.setup_student(self.student)
64        exporter = NigeriaStudentExporter()
65        exporter.export_all(self.app, self.outfile)
66        result = open(self.outfile, 'rb').read()
67        self.assertMatches(
68            'adm_code,alr_date,alr_fname,alr_no,alr_results,'
69            'clr_code,date_of_birth,def_adm,disabled,email,emp2_end,'
70            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
71            'emp_reason,emp_start,employer,employer2,'
72            'financial_clearance_date,financially_cleared_by,'
73            'firstname,flash_notice,former_matric,'
74            'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,'
75            'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,'
76            'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,'
77            'hq_school,hq_session,hq_type,is_staff,lastname,lga,'
78            'marit_stat,matric_number,middlename,nationality,'
79            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
80            'nysc_lga,nysc_location,nysc_year,officer_comment,parents_email,'
81            'perm_address,personal_updated,phone,physical_clearance_date,'
82            'provisionally_cleared,reg_number,'
83            'religion,scd_sit_date,scd_sit_fname,scd_sit_no,'
84            'scd_sit_results,scd_sit_type,sex,student_id,'
85            'suspended,suspended_comment,password,state,history,certcode,is_postgrad,'
86            'current_level,current_session\r\nmy adm code,,,,'
87            '"[(\'accounts\', \'A\')]",my clr code,1981-02-04#,,,'
88            'anna@sample.com,,,,,,,,,,,,,Anna,,,,,,"[(\'accounts\', \'A\')]"'
89            ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,,'
90            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,'
91            '"[(\'accounts\', \'A\')]",,f,A111111,0,,,created,'
92            '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],'
93            'CERT1,0,200,2012\r\n',
94            result
95            )
96        return
97
98class NigeriaStudentPaymentExporterTest(StudentImportExportSetup):
99
100    layer = FunctionalLayer
101
102    def setUp(self):
103        super(NigeriaStudentPaymentExporterTest, self).setUp()
104        self.setup_for_export()
105        return
106
107    def test_ifaces(self):
108        # make sure we fullfill interface contracts
109        obj = NigeriaStudentPaymentExporter()
110        verifyObject(ICSVExporter, obj)
111        verifyClass(ICSVExporter, NigeriaStudentPaymentExporter)
112        return
113
114    def test_export_all(self):
115        # we can really export students
116        # set values we can expect in export file
117        self.setup_student(self.student)
118        self.student['payments']['my-payment'].r_company = 'interswitch'
119        self.student['payments']['my-payment'].r_card_num = '789'
120        exporter = NigeriaStudentPaymentExporter()
121        exporter.export_all(self.app, self.outfile)
122        result = open(self.outfile, 'rb').read()
123        self.assertMatches(
124            'ac,amount_auth,creation_date,gateway_amt,p_category,p_combi,p_current,'
125            'p_id,p_item,p_level,p_session,p_split_data,p_state,payment_date,provider_amt,'
126            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
127            'r_pay_reference,thirdparty_amt,student_id,state,'
128            'current_session\r\n'
129            '666,12.12,2012-04-01 13:12:01#,,schoolfee,[],1,my-id,p-item,'
130            '100,%s,,paid,2012-04-01 14:12:01#,,12.12,'
131            '789,r-code,interswitch,,,,A111111,created,2012\r\n' % (curr_year-6),
132            result
133            )
134        return
135
136class ClearanceRequestedStudentExporterTest(StudentImportExportSetup):
137
138    layer = FunctionalLayer
139
140    def setUp(self):
141        super(ClearanceRequestedStudentExporterTest, self).setUp()
142        self.setup_for_export()
143        return
144
145    def test_ifaces(self):
146        # make sure we fullfill interface contracts
147        obj = ClearanceRequestedStudentExporter()
148        verifyObject(ICSVExporter, obj)
149        verifyClass(ICSVExporter, ClearanceRequestedStudentExporter)
150        return
151
152    def test_export_all(self):
153        # we can really export students
154        # set values we can expect in export file
155        self.setup_student(self.student)
156        self.student.physical_clearance_date = 'Come soon'
157        IWorkflowState(self.student).setState('clearance requested')
158        exporter = ClearanceRequestedStudentExporter()
159        exporter.export_all(self.app, self.outfile)
160        result = open(self.outfile, 'rb').read()
161        self.assertMatches(
162            'student_id,reg_number,display_fullname,state,current_session,'
163            'history,physical_clearance_date,email,phone\r\n'
164            'A111111,123,Anna M. Tester,clearance requested,'
165            '2012,2014-12-02 07:17:02 WAT - Record created by system,'
166            'Come soon,anna@sample.com,+234-123-12345\r\n',
167            result
168            )
169        return
170
171class BursaryDataExporterTest(StudentImportExportSetup):
172
173    layer = FunctionalLayer
174
175    def setUp(self):
176        super(BursaryDataExporterTest, self).setUp()
177        self.setup_for_export()
178        return
179
180    def test_export_all(self):
181        # we can really export all payments
182        # set values we can expect in export file
183        self.setup_student(self.student)
184        exporter = NigeriaDataForBursaryExporter()
185        exporter.export_all(self.app, self.outfile)
186        result = open(self.outfile, 'rb').read()
187        self.assertEqual(
188            result,
189            'ac,amount_auth,creation_date,formatted_p_date,gateway_amt,'
190            'p_category,p_combi,p_current,p_id,p_item,p_level,p_session,p_split_data,p_state,'
191            'payment_date,provider_amt,r_amount_approved,r_card_num,r_code,'
192            'r_company,r_desc,r_pay_reference,thirdparty_amt,student_id,'
193            'matric_number,reg_number,firstname,middlename,lastname,state,'
194            'current_session,entry_session,entry_mode,faccode,depcode,certcode,lga\r\n'
195
196            '666,12.12,%s-04-01 13:12:01#,,,schoolfee,[],1,my-id,p-item,'
197            '100,%s,,paid,%s-04-01 14:12:01#,,12.12,,r-code,,,,,A111111,'
198            '234,123,Anna,M.,Tester,created,2012,2010,ug_ft,NA,NA,CERT1,\r\n'
199            % (curr_year-6, curr_year-6, curr_year-6)
200            )
201        return
Note: See TracBrowser for help on using the repository browser.