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

Last change on this file since 15240 was 15194, checked in by Henrik Bettermann, 6 years ago

See AAUE #513.

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