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

Last change on this file since 14212 was 13712, checked in by Henrik Bettermann, 9 years ago

Hide flash_message on slips.

  • 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, NigeriaStudentPaymentExporter,
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,'
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,'
71            'financial_clearance_date,financially_cleared_by,'
72            'firstname,flash_notice,former_matric,'
73            'fst_sit_date,fst_sit_fname,fst_sit_no,fst_sit_results,'
74            'fst_sit_type,hq2_degree,hq2_disc,hq2_matric_no,hq2_school,'
75            'hq2_session,hq2_type,hq_degree,hq_disc,hq_fname,hq_matric_no,'
76            'hq_school,hq_session,hq_type,is_staff,lastname,lga,'
77            'marit_stat,matric_number,middlename,nationality,'
78            'next_kin_address,next_kin_name,next_kin_phone,next_kin_relation,'
79            'nysc_lga,nysc_location,nysc_year,officer_comment,'
80            'perm_address,personal_updated,phone,physical_clearance_date,reg_number,'
81            'religion,scd_sit_date,scd_sit_fname,scd_sit_no,'
82            'scd_sit_results,scd_sit_type,sex,student_id,'
83            'suspended,suspended_comment,password,state,history,certcode,is_postgrad,'
84            'current_level,current_session\r\nmy adm code,,,,'
85            '"[(\'accounts\', \'A\')]",my clr code,1981-02-04#,,,'
86            'anna@sample.com,,,,,,,,,,,,,Anna,,,,,,"[(\'accounts\', \'A\')]"'
87            ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,'
88            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,123,,,,,'
89            '"[(\'accounts\', \'A\')]",,f,A111111,0,,,created,'
90            '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],'
91            'CERT1,0,200,2012\r\n',
92            result
93            )
94        return
95
96class NigeriaStudentPaymentExporterTest(StudentImportExportSetup):
97
98    layer = FunctionalLayer
99
100    def setUp(self):
101        super(NigeriaStudentPaymentExporterTest, self).setUp()
102        self.setup_for_export()
103        return
104
105    def test_ifaces(self):
106        # make sure we fullfill interface contracts
107        obj = NigeriaStudentPaymentExporter()
108        verifyObject(ICSVExporter, obj)
109        verifyClass(ICSVExporter, NigeriaStudentPaymentExporter)
110        return
111
112    def test_export_all(self):
113        # we can really export students
114        # set values we can expect in export file
115        self.setup_student(self.student)
116        self.student['payments']['my-payment'].r_company = 'interswatch'
117        self.student['payments']['my-payment'].r_card_num = '789'
118        exporter = NigeriaStudentPaymentExporter()
119        exporter.export_all(self.app, self.outfile)
120        result = open(self.outfile, 'rb').read()
121        self.assertMatches(
122            'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,'
123            'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,'
124            'r_amount_approved,r_card_num,r_code,r_company,r_desc,'
125            'r_pay_reference,thirdparty_amt,student_id,state,'
126            'current_session\r\n'
127            '666,12.12,2012-04-01 13:12:01#,,schoolfee,1,my-id,p-item,'
128            '100,2012,paid,2012-04-01 14:12:01#,,12.12,'
129            '789,r-code,interswatch,,,,A111111,created,2012\r\n',
130            result
131            )
132        return
133
134class ClearanceRequestedStudentExporterTest(StudentImportExportSetup):
135
136    layer = FunctionalLayer
137
138    def setUp(self):
139        super(ClearanceRequestedStudentExporterTest, self).setUp()
140        self.setup_for_export()
141        return
142
143    def test_ifaces(self):
144        # make sure we fullfill interface contracts
145        obj = ClearanceRequestedStudentExporter()
146        verifyObject(ICSVExporter, obj)
147        verifyClass(ICSVExporter, ClearanceRequestedStudentExporter)
148        return
149
150    def test_export_all(self):
151        # we can really export students
152        # set values we can expect in export file
153        self.setup_student(self.student)
154        self.student.physical_clearance_date = 'Come soon'
155        IWorkflowState(self.student).setState('clearance requested')
156        exporter = ClearanceRequestedStudentExporter()
157        exporter.export_all(self.app, self.outfile)
158        result = open(self.outfile, 'rb').read()
159        self.assertMatches(
160            'student_id,reg_number,display_fullname,state,current_session,'
161            'history,physical_clearance_date,email,phone\r\n'
162            'A111111,123,Anna M. Tester,clearance requested,'
163            '2012,2014-12-02 07:17:02 WAT - Record created by system,'
164            'Come soon,anna@sample.com,+234-123-12345\r\n',
165            result
166            )
167        return
Note: See TracBrowser for help on using the repository browser.