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

Last change on this file since 14697 was 14585, checked in by Henrik Bettermann, 8 years ago

Replace maxCreditsExceeded by warnCreditsOOR.

  • Property svn:keywords set to Id
File size: 11.0 KB
Line 
1## $Id: test_utils.py 14585 2017-02-24 09:24:09Z 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.tests.test_browser import StudentsFullSetup
22from waeup.kofa.students.interfaces import IStudentsUtils
23from waeup.aaue.testing import FunctionalLayer
24
25class StudentsUtilsTests(StudentsFullSetup):
26
27    layer = FunctionalLayer
28
29    def test_get_returning_data(self):
30        # Student is in level 100, session 2004 with verdict A
31        utils = getUtility(IStudentsUtils)
32        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
33        self.student['studycourse'].current_verdict = 'C'
34        self.assertEqual(utils.getReturningData(self.student),(2005, 200))
35        self.student['studycourse'].current_verdict = 'NER'
36        self.assertEqual(utils.getReturningData(self.student),(2005, 100))
37        return
38
39    def test_no_clearance_ac_code_created(self):
40        payment = createObject('waeup.StudentOnlinePayment')
41        payment.p_category = 'clearance'
42        self.student['payments']['any_id'] = payment
43        payment.approveStudentPayment()
44        # No activation code created.
45        self.assertEqual(payment.ac, None)
46
47    def test_set_payment_details(self):
48        self.app['configuration']['2004'].gown_fee = 150.0
49        self.app['configuration']['2004'].transfer_fee = 90.0
50        self.app['configuration']['2004'].booking_fee = 150.0
51        self.app['configuration']['2004'].maint_fee = 180.0
52        self.app['configuration']['2004'].clearance_fee_pg = 1234.0
53        self.app['configuration']['2004'].clearance_fee_fp = 3456.0
54        self.student['studycourse'].certificate.school_fee_1 = 6666.0
55        self.student['studycourse'].certificate.school_fee_2 = 7777.0
56        self.student['studycourse'].certificate.school_fee_3 = 8888.0
57        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
58        self.student.nationality = u'NG'
59        self.student.lga = 'ebonyi_ukaba'
60        utils = getUtility(IStudentsUtils)
61
62        configuration = createObject('waeup.SessionConfiguration')
63        configuration.academic_session = 2005
64        self.app['configuration'].addSessionConfiguration(configuration)
65
66        error, payment = utils.setPaymentDetails('schoolfee',self.student)
67        self.assertEqual(payment, None)
68        self.assertEqual(error, u'Wrong state.')
69        IWorkflowState(self.student).setState('cleared')
70        # School fee can be set.
71        error, payment = utils.setPaymentDetails('schoolfee',self.student)
72        self.assertEqual(payment.p_level, 100)
73        self.assertEqual(payment.p_session, 2004)
74        # 20000 Naira non-indigenous fee added
75        self.assertEqual(payment.amount_auth, 26666.0)
76        self.assertEqual(payment.p_item, u'CERT1')
77        self.assertEqual(error, None)
78        # Add penalty fee ...
79        # ... for cleared
80        self.app['configuration']['2004'].penalty_pg = 99.0
81        # ... for returning
82        self.app['configuration']['2005'].penalty_pg = 88.0
83        self.student.lga = 'edo_afuze'
84        error, payment = utils.setPaymentDetails('schoolfee',self.student)
85        self.assertEqual(payment.amount_auth, 6765.0)
86        IWorkflowState(self.student).setState('returning')
87        error, payment = utils.setPaymentDetails('schoolfee',self.student)
88        self.assertEqual(error, u'Personal data form is not properly filled.')
89        self.student.father_name = u'Rudolf'
90        error, payment = utils.setPaymentDetails('schoolfee_incl',self.student)
91        self.assertEqual(error, 'No additional fees required.')
92        error, payment = utils.setPaymentDetails('schoolfee',self.student)
93        self.assertEqual(payment.p_level, 200)
94        self.assertEqual(payment.p_session, 2005)
95        self.assertEqual(payment.amount_auth, 8976.0)
96        self.assertEqual(payment.p_item, u'CERT1')
97        self.assertEqual(error, None)
98
99        error, payment = utils.setPaymentDetails('clearance',self.student)
100        self.assertEqual(error, 'Acceptance Fee payments not allowed.')
101        IWorkflowState(self.student).setState('cleared')
102        error, payment = utils.setPaymentDetails('clearance_incl',self.student)
103        self.assertEqual(error, 'No additional fees required.')
104        error, payment = utils.setPaymentDetails('clearance',self.student)
105        self.assertEqual(payment.p_level, 100)
106        self.assertEqual(payment.p_session, 2004)
107        self.assertEqual(payment.amount_auth, 1234.0)
108        self.assertEqual(payment.p_item, u'CERT1')
109        self.assertEqual(error, None)
110
111        self.app['faculties']['fac1'].code = u'FP'
112        error, payment = utils.setPaymentDetails('clearance',self.student)
113        self.assertEqual(payment.p_level, 100)
114        self.assertEqual(payment.p_session, 2004)
115        self.assertEqual(payment.amount_auth, 3456.0)
116        self.assertEqual(payment.p_item, u'CERT1')
117        self.assertEqual(error, None)
118
119        error, payment = utils.setPaymentDetails('restitution',self.student)
120        self.assertEqual(error, 'Restitution fee payment not required.')
121        self.student['studycourse'].certificate.study_mode = 'ug_ft'
122        self.app['configuration']['2004'].restitution_fee = 1111.0
123        error, payment = utils.setPaymentDetails('restitution',self.student)
124        self.assertEqual(payment.p_level, 100)
125        self.assertEqual(payment.p_session, 2004)
126        self.assertEqual(payment.amount_auth, 1111.0)
127        self.assertEqual(payment.p_item, u'')
128        self.assertEqual(error, None)
129
130        error, payment = utils.setPaymentDetails('clearance',self.student, 2004, 100)
131        self.assertEqual(error, 'This is not a previous session.')
132        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
133        self.assertEqual(payment.p_level, 100)
134        self.assertEqual(payment.p_session, 2004)
135        self.assertEqual(payment.amount_auth, 6666.0)
136        self.assertEqual(payment.p_item, u'CERT1')
137        self.assertEqual(error, None)
138        return
139
140    def test_maxCreditsExceeded(self):
141        students_utils = getUtility(IStudentsUtils)
142        studylevel = grok.Container()
143        studylevel.total_credits = 30
144        course = grok.Model()
145        course.credits = 18
146        warning = students_utils.warnCreditsOOR(studylevel, course)
147        self.assertEqual(warning, None)
148        course.credits = 19
149        warning = students_utils.warnCreditsOOR(studylevel, course)
150        self.assertEqual(warning, 'Maximum credits exceeded.')
151        return
152
153    def test_setMatricNumber(self):
154        IWorkflowState(self.student).setState('school fee paid')
155        site = grok.getSite()
156        utils = getUtility(IStudentsUtils)
157        site['configuration'].next_matric_integer = 1
158        site['configuration'].next_matric_integer_2 = 1
159        site['configuration'].next_matric_integer_3 = 1
160        site['configuration'].next_matric_integer_4 = 1
161        self.student.matric_number = None
162        #msg, mnumber = utils.setMatricNumber(self.student)
163        #self.assertEqual(msg, 'Matriculation number cannot be set.')
164        #payment = createObject('waeup.StudentOnlinePayment')
165        #payment.p_category = u'concessional'
166        #payment.p_id = u'anyid'
167        #payment.p_state = u'paid'
168        #self.student['payments']['anykey'] = payment
169        # Regular ft students have a matric number without leading constant.
170        msg, mnumber = utils.setMatricNumber(self.student)
171        self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
172        self.assertEqual(msg, None)
173        # Part time have an extended matric number with leading 'PTP'
174        # and a different counter which is next_matric_integer.
175        self.student.matric_number = None
176        self.student['studycourse'].certificate.study_mode = 'ug_pt'
177        msg, mnumber = utils.setMatricNumber(self.student)
178        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
179        self.assertEqual(site['configuration'].next_matric_integer, 2)
180        # Students in faculty FBM get an extended matric number with leading 'CMS'
181        # and the regular counter which is next_matric_integer_2.
182        self.app['faculties']['fac1'].code = 'FBM'
183        self.student['studycourse'].certificate.study_mode = 'ug_ft'
184        self.student.matric_number = None
185        msg, mnumber = utils.setMatricNumber(self.student)
186        self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002')
187        self.assertEqual(site['configuration'].next_matric_integer_2, 3)
188        # PG Students get an extended matric number with leading 'AAU/SPS'
189        # and the pg  counter which is next_matric_integer_3.
190        self.app['faculties']['fac1'].code = 'ABC'
191        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
192        self.student.matric_number = None
193        self.certificate.degree = 'AGRB'
194        msg, mnumber = utils.setMatricNumber(self.student)
195        self.assertEqual(self.student.matric_number, 'AAU/SPS/ABC/dep1/04/AGRB/00001')
196        self.assertEqual(site['configuration'].next_matric_integer_3, 2)
197        self.student.matric_number = None
198        # students in IOE don't have a department
199        self.app['faculties']['fac1'].code = 'IOE'
200        msg, mnumber = utils.setMatricNumber(self.student)
201        self.assertEqual(self.student.matric_number, 'AAU/SPS/IOE/04/AGRB/00002')
202        # Diploma Students get a matric number with leading 'IOS'
203        # and the dp counter which is next_matric_integer_3.
204        self.student['studycourse'].certificate.study_mode = 'dp_ft'
205        self.student.matric_number = None
206        msg, mnumber = utils.setMatricNumber(self.student)
207        self.assertEqual(self.student.matric_number, 'IOE/DIP/04/00001')
208        self.assertEqual(site['configuration'].next_matric_integer_4, 2)
209        # Foundation programme students don't get matric number.
210        self.student.matric_number = None
211        self.student['studycourse'].certificate.study_mode = 'found'
212        msg, mnumber = utils.setMatricNumber(self.student)
213        self.assertEqual(msg, 'Matriculation number cannot be set.')
214        self.assertEqual(mnumber, None)
215        # Certificate must be set.
216        self.student.matric_number = None
217        self.student['studycourse'].certificate = None
218        msg, mnumber = utils.setMatricNumber(self.student)
219        self.assertEqual(msg, 'No certificate assigned.')
220        return
Note: See TracBrowser for help on using the repository browser.