source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_utils.py @ 16041

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

Configure School Fees Returning Students (> 2014)

  • Property svn:keywords set to Id
File size: 14.0 KB
Line 
1## $Id: test_utils.py 15871 2019-12-09 09:19:16Z 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##
18import grok
19from hurry.workflow.interfaces import IWorkflowState
20from zope.component import getUtility, createObject
21from waeup.kofa.students.studylevel import StudentStudyLevel
22from waeup.kofa.students.tests.test_browser import StudentsFullSetup
23from waeup.kofa.students.interfaces import IStudentsUtils
24from waeup.kofa.students.studylevel import StudentStudyLevel
25from waeup.aaue.testing import FunctionalLayer
26
27class 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, 26666.0)
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, 6765.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',self.student)
94        self.assertEqual(payment.p_level, 200)
95        self.assertEqual(payment.p_session, 2005)
96        self.assertEqual(payment.amount_auth, 8976.0)
97        self.assertEqual(payment.p_item, u'CERT1')
98        self.assertEqual(error, None)
99
100        configuration = createObject('waeup.SessionConfiguration')
101        configuration.academic_session = 2016
102        self.app['configuration'].addSessionConfiguration(configuration)
103        configuration = createObject('waeup.SessionConfiguration')
104        configuration.academic_session = 2017
105        self.app['configuration'].addSessionConfiguration(configuration)
106        configuration = createObject('waeup.SessionConfiguration')
107        configuration.academic_session = 2018
108        self.app['configuration'].addSessionConfiguration(configuration)
109        self.student['studycourse'].current_session = 2017
110        self.student['studycourse'].entry_session = 2015
111        error, payment = utils.setPaymentDetails('schoolfee',self.student)
112        self.assertEqual(payment.p_level, 200)
113        self.assertEqual(payment.p_session, 2018)
114        self.assertEqual(payment.amount_auth, 7777.0)
115        self.assertEqual(payment.p_item, u'CERT1')
116        self.assertEqual(error, None)
117        self.student['studycourse'].entry_session = 2014
118        error, payment = utils.setPaymentDetails('schoolfee',self.student)
119        self.assertEqual(payment.p_level, 200)
120        self.assertEqual(payment.p_session, 2018)
121        self.assertEqual(payment.amount_auth, 8888.0)
122        self.assertEqual(payment.p_item, u'CERT1')
123        self.assertEqual(error, None)
124
125        self.student['studycourse'].current_session = 2004
126        self.student['studycourse'].entry_session = 2004
127        error, payment = utils.setPaymentDetails('clearance',self.student)
128        self.assertEqual(error, 'Acceptance Fee payments not allowed.')
129        IWorkflowState(self.student).setState('cleared')
130        error, payment = utils.setPaymentDetails('clearance_incl',self.student)
131        self.assertEqual(error, 'No additional fees required.')
132        error, payment = utils.setPaymentDetails('clearance',self.student)
133        self.assertEqual(payment.p_level, 100)
134        self.assertEqual(payment.p_session, 2004)
135        self.assertEqual(payment.amount_auth, 1234.0)
136        self.assertEqual(payment.p_item, u'CERT1')
137        self.assertEqual(error, None)
138
139        self.app['faculties']['fac1'].code = u'FP'
140        error, payment = utils.setPaymentDetails('clearance',self.student)
141        self.assertEqual(payment.p_level, 100)
142        self.assertEqual(payment.p_session, 2004)
143        self.assertEqual(payment.amount_auth, 3456.0)
144        self.assertEqual(payment.p_item, u'CERT1')
145        self.assertEqual(error, None)
146
147        error, payment = utils.setPaymentDetails('restitution',self.student)
148        self.assertEqual(error, 'Restitution fee payment not required.')
149        self.student['studycourse'].certificate.study_mode = 'ug_ft'
150        configuration = createObject('waeup.SessionConfiguration')
151        self.app['configuration']['2016'].restitution_fee = 1111.0
152        self.student['studycourse'].current_session = 2016
153        error, payment = utils.setPaymentDetails('restitution',self.student)
154        self.assertEqual(payment.p_level, 100)
155        self.assertEqual(payment.p_session, 2016)
156        self.assertEqual(payment.amount_auth, 1111.0)
157        self.assertEqual(payment.p_item, u'')
158        self.assertEqual(error, None)
159
160        self.student['studycourse'].current_session = 2004
161        error, payment = utils.setPaymentDetails('clearance',self.student, 2004, 100)
162        self.assertEqual(error, 'This is not a previous session.')
163        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
164        self.assertEqual(payment.p_level, 100)
165        self.assertEqual(payment.p_session, 2004)
166        self.assertEqual(payment.amount_auth, 6666.0)
167        self.assertEqual(payment.p_item, u'CERT1')
168        self.assertEqual(error, None)
169        return
170
171    def test_maxCreditsExceeded(self):
172        # non-final-year student
173        students_utils = getUtility(IStudentsUtils)
174        studylevel = grok.Container()
175        studylevel.total_credits = 30
176        studylevel.level = 100
177        self.student['studycourse']['100'] = studylevel
178        course = grok.Model()
179        course.credits = 18
180        warning = students_utils.warnCreditsOOR(studylevel, course)
181        self.assertEqual(warning, None)
182        course.credits = 19
183        warning = students_utils.warnCreditsOOR(studylevel, course)
184        self.assertEqual(warning, 'Maximum credits exceeded.')
185        return
186
187    def test_setMatricNumber(self):
188        IWorkflowState(self.student).setState('school fee paid')
189        site = grok.getSite()
190        utils = getUtility(IStudentsUtils)
191        site['configuration'].next_matric_integer = 1
192        site['configuration'].next_matric_integer_2 = 1
193        site['configuration'].next_matric_integer_3 = 1
194        site['configuration'].next_matric_integer_4 = 1
195        self.student.matric_number = None
196        #msg, mnumber = utils.setMatricNumber(self.student)
197        #self.assertEqual(msg, 'Matriculation number cannot be set.')
198        #payment = createObject('waeup.StudentOnlinePayment')
199        #payment.p_category = u'concessional'
200        #payment.p_id = u'anyid'
201        #payment.p_state = u'paid'
202        #self.student['payments']['anykey'] = payment
203        # Regular ft students have a matric number without leading constant.
204        msg, mnumber = utils.setMatricNumber(self.student)
205        self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
206        self.assertEqual(msg, None)
207        # Part time have an extended matric number with leading 'PTP'
208        # and a different counter which is next_matric_integer.
209        self.student.matric_number = None
210        self.student['studycourse'].certificate.study_mode = 'ug_pt'
211        msg, mnumber = utils.setMatricNumber(self.student)
212        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
213        self.assertEqual(site['configuration'].next_matric_integer, 2)
214        # DSH have an extended matric number with leading 'DSH'
215        # and same counter as PTP.
216        self.student.matric_number = None
217        self.student['studycourse'].certificate.study_mode = 'ug_dsh'
218        msg, mnumber = utils.setMatricNumber(self.student)
219        self.assertEqual(self.student.matric_number, 'DSH/fac1/dep1/04/00002')
220        self.assertEqual(site['configuration'].next_matric_integer, 3)
221        # Students in faculty FBM get an extended matric number with leading 'CMS'
222        # and the regular counter which is next_matric_integer_2.
223        self.app['faculties']['fac1'].code = 'FBM'
224        self.student['studycourse'].certificate.study_mode = 'ug_ft'
225        self.student.matric_number = None
226        msg, mnumber = utils.setMatricNumber(self.student)
227        self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002')
228        self.assertEqual(site['configuration'].next_matric_integer_2, 3)
229        # PG Students get an extended matric number with leading 'AAU/SPS'
230        # and the pg  counter which is next_matric_integer_3.
231        self.app['faculties']['fac1'].code = 'ABC'
232        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
233        self.student.matric_number = None
234        self.certificate.degree = 'AGRB'
235        msg, mnumber = utils.setMatricNumber(self.student)
236        self.assertEqual(self.student.matric_number, 'AAU/SPS/ABC/dep1/04/AGRB/00001')
237        self.assertEqual(site['configuration'].next_matric_integer_3, 2)
238        self.student.matric_number = None
239        # students in IOE don't have a department
240        self.app['faculties']['fac1'].code = 'IOE'
241        msg, mnumber = utils.setMatricNumber(self.student)
242        self.assertEqual(self.student.matric_number, 'AAU/SPS/IOE/04/AGRB/00002')
243        # Diploma Students get a matric number with leading 'IOS'
244        # and the dp counter which is next_matric_integer_3.
245        self.student['studycourse'].certificate.study_mode = 'dp_ft'
246        self.student.matric_number = None
247        msg, mnumber = utils.setMatricNumber(self.student)
248        self.assertEqual(self.student.matric_number, 'IOE/DIP/04/00001')
249        self.assertEqual(site['configuration'].next_matric_integer_4, 2)
250        # Foundation programme students don't get matric number.
251        self.student.matric_number = None
252        self.student['studycourse'].certificate.study_mode = 'found'
253        msg, mnumber = utils.setMatricNumber(self.student)
254        self.assertEqual(msg, 'Matriculation number cannot be set.')
255        self.assertEqual(mnumber, None)
256        # Certificate must be set.
257        self.student.matric_number = None
258        self.student['studycourse'].certificate = None
259        msg, mnumber = utils.setMatricNumber(self.student)
260        self.assertEqual(msg, 'No certificate assigned.')
261        return
262
263    def test_getClassFromCGPA(self):
264        site = grok.getSite()
265        utils = getUtility(IStudentsUtils)
266        gpaclass, gpaboundary = utils.getClassFromCGPA(4.6, self.student)
267        self.assertEqual(gpaclass, 5)
268        self.assertEqual(gpaboundary, '1st Class Honours')
269        self.certificate.study_mode = 'dp_ft'
270        gpaclass, gpaboundary = utils.getClassFromCGPA(4.6, self.student)
271        self.assertEqual(gpaclass, 4)
272        self.assertEqual(gpaboundary, 'Distinction')
273        studylevel = StudentStudyLevel()
274        studylevel.level = 520
275        self.student['studycourse'].addStudentStudyLevel(self.certificate,
276            studylevel)
277        gpaclass, gpaboundary = utils.getClassFromCGPA(4.6, self.student)
278        self.assertEqual(gpaclass, 1)
279        self.assertEqual(gpaboundary, 'Pass')
Note: See TracBrowser for help on using the repository browser.