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

Last change on this file since 14972 was 14958, checked in by Henrik Bettermann, 7 years ago

Use verdict 'C' for probation or extension levels.

  • Property svn:keywords set to Id
File size: 12.6 KB
Line 
1## $Id: test_utils.py 14958 2018-03-02 11:04: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.aaue.testing import FunctionalLayer
25
26class StudentsUtilsTests(StudentsFullSetup):
27
28    layer = FunctionalLayer
29
30    def test_get_returning_data(self):
31        # Student is in level 100, session 2004 with verdict A
32        utils = getUtility(IStudentsUtils)
33        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
34        self.student['studycourse'].current_verdict = 'C'
35        self.assertEqual(utils.getReturningData(self.student),(2005, 110))
36        self.student['studycourse'].current_verdict = 'NER'
37        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
38        return
39
40    def test_no_clearance_ac_code_created(self):
41        payment = createObject('waeup.StudentOnlinePayment')
42        payment.p_category = 'clearance'
43        self.student['payments']['any_id'] = payment
44        payment.approveStudentPayment()
45        # No activation code created.
46        self.assertEqual(payment.ac, None)
47
48    def test_set_payment_details(self):
49        self.app['configuration']['2004'].gown_fee = 150.0
50        self.app['configuration']['2004'].transfer_fee = 90.0
51        self.app['configuration']['2004'].booking_fee = 150.0
52        self.app['configuration']['2004'].maint_fee = 180.0
53        self.app['configuration']['2004'].clearance_fee_pg = 1234.0
54        self.app['configuration']['2004'].clearance_fee_fp = 3456.0
55        self.student['studycourse'].certificate.school_fee_1 = 6666.0
56        self.student['studycourse'].certificate.school_fee_2 = 7777.0
57        self.student['studycourse'].certificate.school_fee_3 = 8888.0
58        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
59        self.student.nationality = u'NG'
60        self.student.lga = 'ebonyi_ukaba'
61        utils = getUtility(IStudentsUtils)
62
63        configuration = createObject('waeup.SessionConfiguration')
64        configuration.academic_session = 2005
65        self.app['configuration'].addSessionConfiguration(configuration)
66
67        error, payment = utils.setPaymentDetails('schoolfee',self.student)
68        self.assertEqual(payment, None)
69        self.assertEqual(error, u'Wrong state.')
70        IWorkflowState(self.student).setState('cleared')
71        # School fee can be set.
72        error, payment = utils.setPaymentDetails('schoolfee',self.student)
73        self.assertEqual(payment.p_level, 100)
74        self.assertEqual(payment.p_session, 2004)
75        # 20000 Naira non-indigenous fee added
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 = 2017
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        self.app['configuration']['2004'].restitution_fee = 1111.0
151        error, payment = utils.setPaymentDetails('restitution',self.student)
152        self.assertEqual(payment.p_level, 100)
153        self.assertEqual(payment.p_session, 2004)
154        self.assertEqual(payment.amount_auth, 1111.0)
155        self.assertEqual(payment.p_item, u'')
156        self.assertEqual(error, None)
157
158        error, payment = utils.setPaymentDetails('clearance',self.student, 2004, 100)
159        self.assertEqual(error, 'This is not a previous session.')
160        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
161        self.assertEqual(payment.p_level, 100)
162        self.assertEqual(payment.p_session, 2004)
163        self.assertEqual(payment.amount_auth, 6666.0)
164        self.assertEqual(payment.p_item, u'CERT1')
165        self.assertEqual(error, None)
166        return
167
168    def test_maxCreditsExceeded(self):
169        # non-final-year student
170        students_utils = getUtility(IStudentsUtils)
171        studylevel = grok.Container()
172        studylevel.total_credits = 30
173        studylevel.level = 100
174        self.student['studycourse']['100'] = studylevel
175        course = grok.Model()
176        course.credits = 18
177        warning = students_utils.warnCreditsOOR(studylevel, course)
178        self.assertEqual(warning, None)
179        course.credits = 19
180        warning = students_utils.warnCreditsOOR(studylevel, course)
181        self.assertEqual(warning, 'Maximum credits exceeded.')
182        return
183
184    def test_setMatricNumber(self):
185        IWorkflowState(self.student).setState('school fee paid')
186        site = grok.getSite()
187        utils = getUtility(IStudentsUtils)
188        site['configuration'].next_matric_integer = 1
189        site['configuration'].next_matric_integer_2 = 1
190        site['configuration'].next_matric_integer_3 = 1
191        site['configuration'].next_matric_integer_4 = 1
192        self.student.matric_number = None
193        #msg, mnumber = utils.setMatricNumber(self.student)
194        #self.assertEqual(msg, 'Matriculation number cannot be set.')
195        #payment = createObject('waeup.StudentOnlinePayment')
196        #payment.p_category = u'concessional'
197        #payment.p_id = u'anyid'
198        #payment.p_state = u'paid'
199        #self.student['payments']['anykey'] = payment
200        # Regular ft students have a matric number without leading constant.
201        msg, mnumber = utils.setMatricNumber(self.student)
202        self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
203        self.assertEqual(msg, None)
204        # Part time have an extended matric number with leading 'PTP'
205        # and a different counter which is next_matric_integer.
206        self.student.matric_number = None
207        self.student['studycourse'].certificate.study_mode = 'ug_pt'
208        msg, mnumber = utils.setMatricNumber(self.student)
209        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
210        self.assertEqual(site['configuration'].next_matric_integer, 2)
211        # Students in faculty FBM get an extended matric number with leading 'CMS'
212        # and the regular counter which is next_matric_integer_2.
213        self.app['faculties']['fac1'].code = 'FBM'
214        self.student['studycourse'].certificate.study_mode = 'ug_ft'
215        self.student.matric_number = None
216        msg, mnumber = utils.setMatricNumber(self.student)
217        self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002')
218        self.assertEqual(site['configuration'].next_matric_integer_2, 3)
219        # PG Students get an extended matric number with leading 'AAU/SPS'
220        # and the pg  counter which is next_matric_integer_3.
221        self.app['faculties']['fac1'].code = 'ABC'
222        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
223        self.student.matric_number = None
224        self.certificate.degree = 'AGRB'
225        msg, mnumber = utils.setMatricNumber(self.student)
226        self.assertEqual(self.student.matric_number, 'AAU/SPS/ABC/dep1/04/AGRB/00001')
227        self.assertEqual(site['configuration'].next_matric_integer_3, 2)
228        self.student.matric_number = None
229        # students in IOE don't have a department
230        self.app['faculties']['fac1'].code = 'IOE'
231        msg, mnumber = utils.setMatricNumber(self.student)
232        self.assertEqual(self.student.matric_number, 'AAU/SPS/IOE/04/AGRB/00002')
233        # Diploma Students get a matric number with leading 'IOS'
234        # and the dp counter which is next_matric_integer_3.
235        self.student['studycourse'].certificate.study_mode = 'dp_ft'
236        self.student.matric_number = None
237        msg, mnumber = utils.setMatricNumber(self.student)
238        self.assertEqual(self.student.matric_number, 'IOE/DIP/04/00001')
239        self.assertEqual(site['configuration'].next_matric_integer_4, 2)
240        # Foundation programme students don't get matric number.
241        self.student.matric_number = None
242        self.student['studycourse'].certificate.study_mode = 'found'
243        msg, mnumber = utils.setMatricNumber(self.student)
244        self.assertEqual(msg, 'Matriculation number cannot be set.')
245        self.assertEqual(mnumber, None)
246        # Certificate must be set.
247        self.student.matric_number = None
248        self.student['studycourse'].certificate = None
249        msg, mnumber = utils.setMatricNumber(self.student)
250        self.assertEqual(msg, 'No certificate assigned.')
251        return
Note: See TracBrowser for help on using the repository browser.