1 | ## $Id: test_utils.py 17511 2023-07-23 21:55:42Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from hurry.workflow.interfaces import IWorkflowState |
---|
20 | from zope.component import getUtility, createObject |
---|
21 | from waeup.kofa.students.studylevel import StudentStudyLevel |
---|
22 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
23 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
24 | from waeup.kofa.students.studylevel import StudentStudyLevel |
---|
25 | from waeup.aaue.testing import FunctionalLayer |
---|
26 | |
---|
27 | class StudentsUtilsTests(StudentsFullSetup): |
---|
28 | |
---|
29 | layer = FunctionalLayer |
---|
30 | |
---|
31 | def test_get_returning_data(self): |
---|
32 | # Student is in level 100, session 2004 with verdict A |
---|
33 | utils = getUtility(IStudentsUtils) |
---|
34 | self.assertEqual(utils.getReturningData(self.student),(2005, 200)) |
---|
35 | self.student['studycourse'].current_verdict = 'C' |
---|
36 | self.assertEqual(utils.getReturningData(self.student),(2005, 110)) |
---|
37 | self.student['studycourse'].current_verdict = 'NER' |
---|
38 | self.assertEqual(utils.getReturningData(self.student),(2005, 100)) |
---|
39 | return |
---|
40 | |
---|
41 | def test_no_clearance_ac_code_created(self): |
---|
42 | payment = createObject('waeup.StudentOnlinePayment') |
---|
43 | payment.p_category = 'clearance' |
---|
44 | self.student['payments']['any_id'] = payment |
---|
45 | payment.approveStudentPayment() |
---|
46 | # No activation code created. |
---|
47 | self.assertEqual(payment.ac, None) |
---|
48 | |
---|
49 | def test_set_payment_details(self): |
---|
50 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
51 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
52 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
53 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
54 | #self.app['configuration']['2004'].clearance_fee_pg = 1234.0 |
---|
55 | #self.app['configuration']['2004'].clearance_fee_fp = 3456.0 |
---|
56 | #self.student['studycourse'].certificate.school_fee_1 = 6666.0 |
---|
57 | #self.student['studycourse'].certificate.school_fee_2 = 7777.0 |
---|
58 | #self.student['studycourse'].certificate.school_fee_3 = 8888.0 |
---|
59 | self.student['studycourse'].certificate.study_mode = 'special_pg_ft' |
---|
60 | self.student.nationality = u'NG' |
---|
61 | self.student.lga = 'ebonyi_ukaba' |
---|
62 | utils = getUtility(IStudentsUtils) |
---|
63 | |
---|
64 | configuration = createObject('waeup.SessionConfiguration') |
---|
65 | configuration.academic_session = 2005 |
---|
66 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
67 | |
---|
68 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
69 | self.assertEqual(payment, None) |
---|
70 | self.assertEqual(error, u'Wrong state.') |
---|
71 | IWorkflowState(self.student).setState('cleared') |
---|
72 | # School fee can be set. |
---|
73 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
74 | self.assertEqual(payment.p_level, 100) |
---|
75 | self.assertEqual(payment.p_session, 2004) |
---|
76 | self.assertEqual(payment.amount_auth, 204000.0) # tuition plus penalty |
---|
77 | self.assertEqual(payment.p_item, u'CERT1') |
---|
78 | self.assertEqual(error, None) |
---|
79 | # Add penalty fee ... |
---|
80 | # ... for cleared |
---|
81 | self.app['configuration']['2004'].penalty_pg = 99.0 |
---|
82 | # ... for returning |
---|
83 | self.app['configuration']['2005'].penalty_pg = 88.0 |
---|
84 | self.student.lga = 'edo_afuze' |
---|
85 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
86 | self.assertEqual(payment.amount_auth, 184099.0) |
---|
87 | IWorkflowState(self.student).setState('returning') |
---|
88 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
89 | self.assertEqual(error, u'Personal data form is not properly filled.') |
---|
90 | self.student.father_name = u'Rudolf' |
---|
91 | #error, payment = utils.setPaymentDetails('schoolfee_incl',self.student) |
---|
92 | #self.assertEqual(error, 'No additional fees required.') |
---|
93 | error, payment = utils.setPaymentDetails('schoolfee_incl',self.student) |
---|
94 | self.assertEqual(payment.p_level, 200) |
---|
95 | self.assertEqual(payment.p_session, 2005) |
---|
96 | self.assertEqual(payment.amount_auth, 240588.0) |
---|
97 | self.assertEqual(payment.p_item, u'CERT1') |
---|
98 | self.assertEqual(error, None) |
---|
99 | |
---|
100 | self.student['studycourse'].current_session = 2004 |
---|
101 | self.student['studycourse'].entry_session = 2004 |
---|
102 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
103 | self.assertEqual(error, 'Acceptance Fee payments not allowed.') |
---|
104 | IWorkflowState(self.student).setState('cleared') |
---|
105 | error, payment = utils.setPaymentDetails('clearance_incl',self.student) |
---|
106 | self.assertEqual(error, 'No additional fees required.') |
---|
107 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
108 | self.assertEqual(payment.p_level, 100) |
---|
109 | self.assertEqual(payment.p_session, 2004) |
---|
110 | self.assertEqual(payment.amount_auth, 14000.0) |
---|
111 | self.assertEqual(payment.p_item, u'CERT1') |
---|
112 | self.assertEqual(error, None) |
---|
113 | |
---|
114 | self.student['studycourse'].current_session = 2004 |
---|
115 | error, payment = utils.setPaymentDetails('clearance',self.student, 2004, 100) |
---|
116 | self.assertEqual(error, 'This is not a previous session.') |
---|
117 | error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100) |
---|
118 | self.assertEqual(payment.p_level, 100) |
---|
119 | self.assertEqual(payment.p_session, 2004) |
---|
120 | self.assertEqual(payment.amount_auth, 184099.0) |
---|
121 | self.assertEqual(payment.p_item, u'CERT1') |
---|
122 | self.assertEqual(error, None) |
---|
123 | return |
---|
124 | |
---|
125 | def test_maxCreditsExceeded(self): |
---|
126 | # non-final-year student |
---|
127 | students_utils = getUtility(IStudentsUtils) |
---|
128 | studylevel = grok.Container() |
---|
129 | studylevel.total_credits = 30 |
---|
130 | studylevel.level = 100 |
---|
131 | self.student['studycourse']['100'] = studylevel |
---|
132 | course = grok.Model() |
---|
133 | course.credits = 18 |
---|
134 | warning = students_utils.warnCreditsOOR(studylevel, course) |
---|
135 | self.assertEqual(warning, None) |
---|
136 | course.credits = 19 |
---|
137 | warning = students_utils.warnCreditsOOR(studylevel, course) |
---|
138 | self.assertEqual(warning, 'Maximum credits exceeded.') |
---|
139 | return |
---|
140 | |
---|
141 | def test_setMatricNumber(self): |
---|
142 | IWorkflowState(self.student).setState('school fee paid') |
---|
143 | site = grok.getSite() |
---|
144 | utils = getUtility(IStudentsUtils) |
---|
145 | site['configuration'].next_matric_integer = 1 |
---|
146 | site['configuration'].next_matric_integer_2 = 1 |
---|
147 | site['configuration'].next_matric_integer_3 = 1 |
---|
148 | site['configuration'].next_matric_integer_4 = 1 |
---|
149 | self.student.matric_number = None |
---|
150 | #msg, mnumber = utils.setMatricNumber(self.student) |
---|
151 | #self.assertEqual(msg, 'Matriculation number cannot be set.') |
---|
152 | #payment = createObject('waeup.StudentOnlinePayment') |
---|
153 | #payment.p_category = u'concessional' |
---|
154 | #payment.p_id = u'anyid' |
---|
155 | #payment.p_state = u'paid' |
---|
156 | #self.student['payments']['anykey'] = payment |
---|
157 | # Regular ft students have a matric number without leading constant. |
---|
158 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
159 | self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001') |
---|
160 | self.assertEqual(msg, None) |
---|
161 | # Part time have an extended matric number with leading 'PTP' |
---|
162 | # and a different counter which is next_matric_integer. |
---|
163 | self.student.matric_number = None |
---|
164 | self.student['studycourse'].certificate.study_mode = 'ug_pt' |
---|
165 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
166 | self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001') |
---|
167 | self.assertEqual(site['configuration'].next_matric_integer, 2) |
---|
168 | # DSH have an extended matric number with leading 'DSH' |
---|
169 | # and same counter as PTP. |
---|
170 | self.student.matric_number = None |
---|
171 | self.student['studycourse'].certificate.study_mode = 'ug_dsh' |
---|
172 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
173 | self.assertEqual(self.student.matric_number, 'DSH/fac1/dep1/04/00002') |
---|
174 | self.assertEqual(site['configuration'].next_matric_integer, 3) |
---|
175 | # Students in faculty FBM get an extended matric number with leading 'CMS' |
---|
176 | # and the regular counter which is next_matric_integer_2. |
---|
177 | self.app['faculties']['fac1'].code = 'FBM' |
---|
178 | self.student['studycourse'].certificate.study_mode = 'ug_ft' |
---|
179 | self.student.matric_number = None |
---|
180 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
181 | self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002') |
---|
182 | self.assertEqual(site['configuration'].next_matric_integer_2, 3) |
---|
183 | # PG Students get an extended matric number with leading 'AAU/SPS' |
---|
184 | # and the pg counter which is next_matric_integer_3. |
---|
185 | self.app['faculties']['fac1'].code = 'ABC' |
---|
186 | self.student['studycourse'].certificate.study_mode = 'special_pg_ft' |
---|
187 | self.student.matric_number = None |
---|
188 | self.certificate.degree = 'AGRB' |
---|
189 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
190 | self.assertEqual(self.student.matric_number, 'AAU/SPS/ABC/dep1/04/AGRB/00001') |
---|
191 | self.assertEqual(site['configuration'].next_matric_integer_3, 2) |
---|
192 | self.student.matric_number = None |
---|
193 | # students in IOE don't have a department |
---|
194 | self.app['faculties']['fac1'].code = 'IOE' |
---|
195 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
196 | self.assertEqual(self.student.matric_number, 'AAU/SPS/IOE/04/AGRB/00002') |
---|
197 | # Diploma Students get a matric number with leading 'IOS' |
---|
198 | # and the dp counter which is next_matric_integer_3. |
---|
199 | self.student['studycourse'].certificate.study_mode = 'dp_ft' |
---|
200 | self.student.matric_number = None |
---|
201 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
202 | self.assertEqual(self.student.matric_number, 'IOE/DIP/04/00001') |
---|
203 | self.assertEqual(site['configuration'].next_matric_integer_4, 2) |
---|
204 | # Foundation programme students don't get matric number. |
---|
205 | self.student.matric_number = None |
---|
206 | self.student['studycourse'].certificate.study_mode = 'found' |
---|
207 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
208 | self.assertEqual(msg, 'Matriculation number cannot be set.') |
---|
209 | self.assertEqual(mnumber, None) |
---|
210 | # Certificate must be set. |
---|
211 | self.student.matric_number = None |
---|
212 | self.student['studycourse'].certificate = None |
---|
213 | msg, mnumber = utils.setMatricNumber(self.student) |
---|
214 | self.assertEqual(msg, 'No certificate assigned.') |
---|
215 | return |
---|
216 | |
---|
217 | def test_getClassFromCGPA(self): |
---|
218 | site = grok.getSite() |
---|
219 | utils = getUtility(IStudentsUtils) |
---|
220 | gpaclass, gpaboundary = utils.getClassFromCGPA(4.6, self.student) |
---|
221 | self.assertEqual(gpaclass, 5) |
---|
222 | self.assertEqual(gpaboundary, '1st Class Honours') |
---|
223 | self.certificate.study_mode = 'dp_ft' |
---|
224 | gpaclass, gpaboundary = utils.getClassFromCGPA(4.6, self.student) |
---|
225 | self.assertEqual(gpaclass, 4) |
---|
226 | self.assertEqual(gpaboundary, 'Distinction') |
---|
227 | studylevel = StudentStudyLevel() |
---|
228 | studylevel.level = 520 |
---|
229 | self.student['studycourse'].addStudentStudyLevel(self.certificate, |
---|
230 | studylevel) |
---|
231 | gpaclass, gpaboundary = utils.getClassFromCGPA(4.6, self.student) |
---|
232 | self.assertEqual(gpaclass, 1) |
---|
233 | self.assertEqual(gpaboundary, 'Pass') |
---|