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

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

Final year students maximum credit units = 52

  • Property svn:keywords set to Id
File size: 11.2 KB
Line 
1## $Id: test_utils.py 14733 2017-07-30 07:34:57Z 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, 200))
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        error, payment = utils.setPaymentDetails('clearance',self.student)
101        self.assertEqual(error, 'Acceptance Fee payments not allowed.')
102        IWorkflowState(self.student).setState('cleared')
103        error, payment = utils.setPaymentDetails('clearance_incl',self.student)
104        self.assertEqual(error, 'No additional fees required.')
105        error, payment = utils.setPaymentDetails('clearance',self.student)
106        self.assertEqual(payment.p_level, 100)
107        self.assertEqual(payment.p_session, 2004)
108        self.assertEqual(payment.amount_auth, 1234.0)
109        self.assertEqual(payment.p_item, u'CERT1')
110        self.assertEqual(error, None)
111
112        self.app['faculties']['fac1'].code = u'FP'
113        error, payment = utils.setPaymentDetails('clearance',self.student)
114        self.assertEqual(payment.p_level, 100)
115        self.assertEqual(payment.p_session, 2004)
116        self.assertEqual(payment.amount_auth, 3456.0)
117        self.assertEqual(payment.p_item, u'CERT1')
118        self.assertEqual(error, None)
119
120        error, payment = utils.setPaymentDetails('restitution',self.student)
121        self.assertEqual(error, 'Restitution fee payment not required.')
122        self.student['studycourse'].certificate.study_mode = 'ug_ft'
123        self.app['configuration']['2004'].restitution_fee = 1111.0
124        error, payment = utils.setPaymentDetails('restitution',self.student)
125        self.assertEqual(payment.p_level, 100)
126        self.assertEqual(payment.p_session, 2004)
127        self.assertEqual(payment.amount_auth, 1111.0)
128        self.assertEqual(payment.p_item, u'')
129        self.assertEqual(error, None)
130
131        error, payment = utils.setPaymentDetails('clearance',self.student, 2004, 100)
132        self.assertEqual(error, 'This is not a previous session.')
133        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
134        self.assertEqual(payment.p_level, 100)
135        self.assertEqual(payment.p_session, 2004)
136        self.assertEqual(payment.amount_auth, 6666.0)
137        self.assertEqual(payment.p_item, u'CERT1')
138        self.assertEqual(error, None)
139        return
140
141    def test_maxCreditsExceeded(self):
142        # non-final-year student
143        students_utils = getUtility(IStudentsUtils)
144        studylevel = grok.Container()
145        studylevel.total_credits = 30
146        studylevel.level = 100
147        self.student['studycourse']['100'] = studylevel
148        course = grok.Model()
149        course.credits = 18
150        warning = students_utils.warnCreditsOOR(studylevel, course)
151        self.assertEqual(warning, None)
152        course.credits = 19
153        warning = students_utils.warnCreditsOOR(studylevel, course)
154        self.assertEqual(warning, 'Maximum credits exceeded.')
155        return
156
157    def test_setMatricNumber(self):
158        IWorkflowState(self.student).setState('school fee paid')
159        site = grok.getSite()
160        utils = getUtility(IStudentsUtils)
161        site['configuration'].next_matric_integer = 1
162        site['configuration'].next_matric_integer_2 = 1
163        site['configuration'].next_matric_integer_3 = 1
164        site['configuration'].next_matric_integer_4 = 1
165        self.student.matric_number = None
166        #msg, mnumber = utils.setMatricNumber(self.student)
167        #self.assertEqual(msg, 'Matriculation number cannot be set.')
168        #payment = createObject('waeup.StudentOnlinePayment')
169        #payment.p_category = u'concessional'
170        #payment.p_id = u'anyid'
171        #payment.p_state = u'paid'
172        #self.student['payments']['anykey'] = payment
173        # Regular ft students have a matric number without leading constant.
174        msg, mnumber = utils.setMatricNumber(self.student)
175        self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
176        self.assertEqual(msg, None)
177        # Part time have an extended matric number with leading 'PTP'
178        # and a different counter which is next_matric_integer.
179        self.student.matric_number = None
180        self.student['studycourse'].certificate.study_mode = 'ug_pt'
181        msg, mnumber = utils.setMatricNumber(self.student)
182        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
183        self.assertEqual(site['configuration'].next_matric_integer, 2)
184        # Students in faculty FBM get an extended matric number with leading 'CMS'
185        # and the regular counter which is next_matric_integer_2.
186        self.app['faculties']['fac1'].code = 'FBM'
187        self.student['studycourse'].certificate.study_mode = 'ug_ft'
188        self.student.matric_number = None
189        msg, mnumber = utils.setMatricNumber(self.student)
190        self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002')
191        self.assertEqual(site['configuration'].next_matric_integer_2, 3)
192        # PG Students get an extended matric number with leading 'AAU/SPS'
193        # and the pg  counter which is next_matric_integer_3.
194        self.app['faculties']['fac1'].code = 'ABC'
195        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
196        self.student.matric_number = None
197        self.certificate.degree = 'AGRB'
198        msg, mnumber = utils.setMatricNumber(self.student)
199        self.assertEqual(self.student.matric_number, 'AAU/SPS/ABC/dep1/04/AGRB/00001')
200        self.assertEqual(site['configuration'].next_matric_integer_3, 2)
201        self.student.matric_number = None
202        # students in IOE don't have a department
203        self.app['faculties']['fac1'].code = 'IOE'
204        msg, mnumber = utils.setMatricNumber(self.student)
205        self.assertEqual(self.student.matric_number, 'AAU/SPS/IOE/04/AGRB/00002')
206        # Diploma Students get a matric number with leading 'IOS'
207        # and the dp counter which is next_matric_integer_3.
208        self.student['studycourse'].certificate.study_mode = 'dp_ft'
209        self.student.matric_number = None
210        msg, mnumber = utils.setMatricNumber(self.student)
211        self.assertEqual(self.student.matric_number, 'IOE/DIP/04/00001')
212        self.assertEqual(site['configuration'].next_matric_integer_4, 2)
213        # Foundation programme students don't get matric number.
214        self.student.matric_number = None
215        self.student['studycourse'].certificate.study_mode = 'found'
216        msg, mnumber = utils.setMatricNumber(self.student)
217        self.assertEqual(msg, 'Matriculation number cannot be set.')
218        self.assertEqual(mnumber, None)
219        # Certificate must be set.
220        self.student.matric_number = None
221        self.student['studycourse'].certificate = None
222        msg, mnumber = utils.setMatricNumber(self.student)
223        self.assertEqual(msg, 'No certificate assigned.')
224        return
Note: See TracBrowser for help on using the repository browser.