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

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

Replace 'NEOR' and 'NEOV'.

  • Property svn:keywords set to Id
File size: 10.4 KB
Line 
1## $Id: test_utils.py 14487 2017-02-01 09:17:31Z 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('schoolfee',self.student, 2004, 100)
131        self.assertEqual(error, u'Previous session payment not yet implemented.')
132        return
133
134    def test_maxCredits(self):
135        dummy = object()
136        utils = getUtility(IStudentsUtils)
137        self.assertEqual(utils.maxCredits(dummy), 48)
138        return
139
140    def test_setMatricNumber(self):
141        IWorkflowState(self.student).setState('school fee paid')
142        site = grok.getSite()
143        utils = getUtility(IStudentsUtils)
144        site['configuration'].next_matric_integer = 1
145        site['configuration'].next_matric_integer_2 = 1
146        site['configuration'].next_matric_integer_3 = 1
147        site['configuration'].next_matric_integer_4 = 1
148        self.student.matric_number = None
149        #msg, mnumber = utils.setMatricNumber(self.student)
150        #self.assertEqual(msg, 'Matriculation number cannot be set.')
151        #payment = createObject('waeup.StudentOnlinePayment')
152        #payment.p_category = u'concessional'
153        #payment.p_id = u'anyid'
154        #payment.p_state = u'paid'
155        #self.student['payments']['anykey'] = payment
156        # Regular ft students have a matric number without leading constant.
157        msg, mnumber = utils.setMatricNumber(self.student)
158        self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
159        self.assertEqual(msg, None)
160        # Part time have an extended matric number with leading 'PTP'
161        # and a different counter which is next_matric_integer.
162        self.student.matric_number = None
163        self.student['studycourse'].certificate.study_mode = 'ug_pt'
164        msg, mnumber = utils.setMatricNumber(self.student)
165        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
166        self.assertEqual(site['configuration'].next_matric_integer, 2)
167        # Students in faculty FBM get an extended matric number with leading 'CMS'
168        # and the regular counter which is next_matric_integer_2.
169        self.app['faculties']['fac1'].code = 'FBM'
170        self.student['studycourse'].certificate.study_mode = 'ug_ft'
171        self.student.matric_number = None
172        msg, mnumber = utils.setMatricNumber(self.student)
173        self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002')
174        self.assertEqual(site['configuration'].next_matric_integer_2, 3)
175        # PG Students get an extended matric number with leading 'AAU/SPS'
176        # and the pg  counter which is next_matric_integer_3.
177        self.app['faculties']['fac1'].code = 'ABC'
178        self.student['studycourse'].certificate.study_mode = 'special_pg_ft'
179        self.student.matric_number = None
180        self.certificate.degree = 'AGRB'
181        msg, mnumber = utils.setMatricNumber(self.student)
182        self.assertEqual(self.student.matric_number, 'AAU/SPS/ABC/dep1/04/AGRB/00001')
183        self.assertEqual(site['configuration'].next_matric_integer_3, 2)
184        self.student.matric_number = None
185        # students in IOE don't have a department
186        self.app['faculties']['fac1'].code = 'IOE'
187        msg, mnumber = utils.setMatricNumber(self.student)
188        self.assertEqual(self.student.matric_number, 'AAU/SPS/IOE/04/AGRB/00002')
189        # Diploma Students get a matric number with leading 'IOS'
190        # and the dp counter which is next_matric_integer_3.
191        self.student['studycourse'].certificate.study_mode = 'dp_ft'
192        self.student.matric_number = None
193        msg, mnumber = utils.setMatricNumber(self.student)
194        self.assertEqual(self.student.matric_number, 'IOE/DIP/04/00001')
195        self.assertEqual(site['configuration'].next_matric_integer_4, 2)
196        # Foundation programme students don't get matric number.
197        self.student.matric_number = None
198        self.student['studycourse'].certificate.study_mode = 'found'
199        msg, mnumber = utils.setMatricNumber(self.student)
200        self.assertEqual(msg, 'Matriculation number cannot be set.')
201        self.assertEqual(mnumber, None)
202        # Certificate must be set.
203        self.student.matric_number = None
204        self.student['studycourse'].certificate = None
205        msg, mnumber = utils.setMatricNumber(self.student)
206        self.assertEqual(msg, 'No certificate assigned.')
207        return
Note: See TracBrowser for help on using the repository browser.