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

Last change on this file since 12777 was 12392, checked in by Henrik Bettermann, 10 years ago

Export email address and phone number.

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