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

Last change on this file since 13448 was 13374, checked in by Henrik Bettermann, 9 years ago

Configure new payment categories. School fee amounts are now set via certificates not session configuration objects.

  • Property svn:keywords set to Id
File size: 7.1 KB
Line 
1## $Id: test_utils.py 13374 2015-11-01 14:11:52Z 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, 110))
35        self.student['studycourse'].current_verdict = 'NEOR'
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 = 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.nationality = u'NG'
57        utils = getUtility(IStudentsUtils)
58
59        configuration = createObject('waeup.SessionConfiguration')
60        configuration.academic_session = 2005
61        self.app['configuration'].addSessionConfiguration(configuration)
62
63        error, payment = utils.setPaymentDetails('schoolfee',self.student)
64        self.assertEqual(payment, None)
65        self.assertEqual(error, u'Wrong state.')
66        IWorkflowState(self.student).setState('cleared')
67        # School fee can be set.
68        error, payment = utils.setPaymentDetails('schoolfee',self.student)
69        self.assertEqual(payment.p_level, 100)
70        self.assertEqual(payment.p_session, 2004)
71        self.assertEqual(payment.amount_auth, 6666.0)
72        self.assertEqual(payment.p_item, u'CERT1')
73        self.assertEqual(error, None)
74        # Add penalty fee ...
75        # ... for cleared
76        self.app['configuration']['2004'].penalty_ug = 99.0
77        # ... for returning
78        self.app['configuration']['2005'].penalty_ug = 88.0
79        error, payment = utils.setPaymentDetails('schoolfee',self.student)
80        self.assertEqual(payment.amount_auth, 6765.0)
81        IWorkflowState(self.student).setState('returning')
82        error, payment = utils.setPaymentDetails('schoolfee',self.student)
83        self.assertEqual(payment.p_level, 200)
84        self.assertEqual(payment.p_session, 2005)
85        self.assertEqual(payment.amount_auth, 7865.0)
86        self.assertEqual(payment.p_item, u'CERT1')
87        self.assertEqual(error, None)
88
89        error, payment = utils.setPaymentDetails('clearance',self.student)
90        self.assertEqual(payment.p_level, 100)
91        self.assertEqual(payment.p_session, 2004)
92        self.assertEqual(payment.amount_auth, 1234.0)
93        self.assertEqual(payment.p_item, u'CERT1')
94        self.assertEqual(error, None)
95
96        self.app['faculties']['fac1'].code = u'FP'
97        error, payment = utils.setPaymentDetails('clearance',self.student)
98        self.assertEqual(payment.p_level, 100)
99        self.assertEqual(payment.p_session, 2004)
100        self.assertEqual(payment.amount_auth, 3456.0)
101        self.assertEqual(payment.p_item, u'CERT1')
102        self.assertEqual(error, None)
103
104        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
105        self.assertEqual(error, u'Previous session payment not yet implemented.')
106        return
107
108    def test_maxCredits(self):
109        dummy = object()
110        utils = getUtility(IStudentsUtils)
111        self.assertEqual(utils.maxCredits(dummy), 48)
112        return
113
114    def test_setMatricNumber(self):
115        IWorkflowState(self.student).setState('school fee paid')
116        site = grok.getSite()
117        utils = getUtility(IStudentsUtils)
118        site['configuration'].next_matric_integer = 1
119        site['configuration'].next_matric_integer_2 = 1
120        self.student.matric_number = None
121        # Regular ft students have a matric number without leading constant.
122        msg, mnumber = utils.setMatricNumber(self.student)
123        self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
124        self.assertEqual(msg, None)
125        # Part time have an extended matric number with leading 'PTP'
126        # and a different counter which is next_matric_integer.
127        self.student.matric_number = None
128        self.student['studycourse'].certificate.study_mode = 'ug_pt'
129        msg, mnumber = utils.setMatricNumber(self.student)
130        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
131        self.assertEqual(site['configuration'].next_matric_integer, 2)
132        # Students in faculty FBM an extended matric number with leading 'CMS'
133        # and the regular counter which is next_matric_integer_2.
134        self.app['faculties']['fac1'].code = 'FBM'
135        self.student['studycourse'].certificate.study_mode = 'ug_ft'
136        self.student.matric_number = None
137        msg, mnumber = utils.setMatricNumber(self.student)
138        self.assertEqual(self.student.matric_number, 'CMS/FBM/dep1/04/00002')
139        self.assertEqual(site['configuration'].next_matric_integer_2, 3)
140        # Foundation programme students don't get matric number.
141        self.student.matric_number = None
142        self.student['studycourse'].certificate.study_mode = 'found'
143        msg, mnumber = utils.setMatricNumber(self.student)
144        self.assertEqual(msg, 'Matriculation number cannot be set.')
145        self.assertEqual(mnumber, None)
146        # Certificate must be set.
147        self.student.matric_number = None
148        self.student['studycourse'].certificate = None
149        msg, mnumber = utils.setMatricNumber(self.student)
150        self.assertEqual(msg, 'No certificate assigned.')
151        return
Note: See TracBrowser for help on using the repository browser.