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 | |
---|
17 | import datetime |
---|
18 | from zope.component import queryUtility |
---|
19 | from zope.interface.verify import verifyObject, verifyClass |
---|
20 | from hurry.workflow.interfaces import IWorkflowState |
---|
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 |
---|
26 | from kofacustom.nigeria.students.export import ( |
---|
27 | NigeriaStudentExporter, NigeriaStudentPaymentExporter, |
---|
28 | ClearanceRequestedStudentExporter) |
---|
29 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
30 | |
---|
31 | |
---|
32 | class 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,' |
---|
81 | 'provisionally_cleared,reg_number,' |
---|
82 | 'religion,scd_sit_date,scd_sit_fname,scd_sit_no,' |
---|
83 | 'scd_sit_results,scd_sit_type,sex,student_id,' |
---|
84 | 'suspended,suspended_comment,password,state,history,certcode,is_postgrad,' |
---|
85 | 'current_level,current_session\r\nmy adm code,,,,' |
---|
86 | '"[(\'accounts\', \'A\')]",my clr code,1981-02-04#,,,' |
---|
87 | 'anna@sample.com,,,,,,,,,,,,,Anna,,,,,,"[(\'accounts\', \'A\')]"' |
---|
88 | ',,,,,,,,,,,,,,,,Tester,,,234,M.,NG,,,,,,,,,' |
---|
89 | '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,,,123,,,,,' |
---|
90 | '"[(\'accounts\', \'A\')]",,f,A111111,0,,,created,' |
---|
91 | '[u\'2012-11-06 13:16:41 WAT - Record created by system\'],' |
---|
92 | 'CERT1,0,200,2012\r\n', |
---|
93 | result |
---|
94 | ) |
---|
95 | return |
---|
96 | |
---|
97 | class NigeriaStudentPaymentExporterTest(StudentImportExportSetup): |
---|
98 | |
---|
99 | layer = FunctionalLayer |
---|
100 | |
---|
101 | def setUp(self): |
---|
102 | super(NigeriaStudentPaymentExporterTest, self).setUp() |
---|
103 | self.setup_for_export() |
---|
104 | return |
---|
105 | |
---|
106 | def test_ifaces(self): |
---|
107 | # make sure we fullfill interface contracts |
---|
108 | obj = NigeriaStudentPaymentExporter() |
---|
109 | verifyObject(ICSVExporter, obj) |
---|
110 | verifyClass(ICSVExporter, NigeriaStudentPaymentExporter) |
---|
111 | return |
---|
112 | |
---|
113 | def test_export_all(self): |
---|
114 | # we can really export students |
---|
115 | # set values we can expect in export file |
---|
116 | self.setup_student(self.student) |
---|
117 | self.student['payments']['my-payment'].r_company = 'interswatch' |
---|
118 | self.student['payments']['my-payment'].r_card_num = '789' |
---|
119 | exporter = NigeriaStudentPaymentExporter() |
---|
120 | exporter.export_all(self.app, self.outfile) |
---|
121 | result = open(self.outfile, 'rb').read() |
---|
122 | self.assertMatches( |
---|
123 | 'ac,amount_auth,creation_date,gateway_amt,p_category,p_current,' |
---|
124 | 'p_id,p_item,p_level,p_session,p_state,payment_date,provider_amt,' |
---|
125 | 'r_amount_approved,r_card_num,r_code,r_company,r_desc,' |
---|
126 | 'r_pay_reference,thirdparty_amt,student_id,state,' |
---|
127 | 'current_session\r\n' |
---|
128 | '666,12.12,2012-04-01 13:12:01#,,schoolfee,1,my-id,p-item,' |
---|
129 | '100,2012,paid,2012-04-01 14:12:01#,,12.12,' |
---|
130 | '789,r-code,interswatch,,,,A111111,created,2012\r\n', |
---|
131 | result |
---|
132 | ) |
---|
133 | return |
---|
134 | |
---|
135 | class ClearanceRequestedStudentExporterTest(StudentImportExportSetup): |
---|
136 | |
---|
137 | layer = FunctionalLayer |
---|
138 | |
---|
139 | def setUp(self): |
---|
140 | super(ClearanceRequestedStudentExporterTest, self).setUp() |
---|
141 | self.setup_for_export() |
---|
142 | return |
---|
143 | |
---|
144 | def test_ifaces(self): |
---|
145 | # make sure we fullfill interface contracts |
---|
146 | obj = ClearanceRequestedStudentExporter() |
---|
147 | verifyObject(ICSVExporter, obj) |
---|
148 | verifyClass(ICSVExporter, ClearanceRequestedStudentExporter) |
---|
149 | return |
---|
150 | |
---|
151 | def test_export_all(self): |
---|
152 | # we can really export students |
---|
153 | # set values we can expect in export file |
---|
154 | self.setup_student(self.student) |
---|
155 | self.student.physical_clearance_date = 'Come soon' |
---|
156 | IWorkflowState(self.student).setState('clearance requested') |
---|
157 | exporter = ClearanceRequestedStudentExporter() |
---|
158 | exporter.export_all(self.app, self.outfile) |
---|
159 | result = open(self.outfile, 'rb').read() |
---|
160 | self.assertMatches( |
---|
161 | 'student_id,reg_number,display_fullname,state,current_session,' |
---|
162 | 'history,physical_clearance_date,email,phone\r\n' |
---|
163 | 'A111111,123,Anna M. Tester,clearance requested,' |
---|
164 | '2012,2014-12-02 07:17:02 WAT - Record created by system,' |
---|
165 | 'Come soon,anna@sample.com,+234-123-12345\r\n', |
---|
166 | result |
---|
167 | ) |
---|
168 | return |
---|