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

Last change on this file since 11624 was 11624, checked in by Henrik Bettermann, 11 years ago

Configure new and returning school fee in session configuration objects.

  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1## $Id: test_utils.py 11624 2014-05-06 19:00:28Z 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_set_payment_details(self):
40        self.app['configuration']['2004'].gown_fee = 150.0
41        self.app['configuration']['2004'].transfer_fee = 90.0
42        self.app['configuration']['2004'].booking_fee = 150.0
43        self.app['configuration']['2004'].maint_fee = 180.0
44        self.app['configuration']['2004'].clearance_fee = 1234.0
45        self.app['configuration']['2004'].school_fee_1 = 6666.0
46        utils = getUtility(IStudentsUtils)
47
48        configuration = createObject('waeup.SessionConfiguration')
49        configuration.academic_session = 2005
50        self.app['configuration'].addSessionConfiguration(configuration)
51        self.app['configuration']['2005'].school_fee_2 = 7777.0
52
53        error, payment = utils.setPaymentDetails('schoolfee',self.student)
54        self.assertEqual(payment, None)
55        self.assertEqual(error, u'Wrong state.')
56
57        IWorkflowState(self.student).setState('cleared')
58        error, payment = utils.setPaymentDetails('schoolfee',self.student)
59        # Acceptance fee must be paid first.
60        self.assertEqual(error, 'Please pay acceptance fee first.')
61        payment = createObject('waeup.StudentOnlinePayment')
62        payment.p_category = 'clearance'
63        self.student['payments']['any_id'] = payment
64        payment.approveStudentPayment()
65        # No activation code created.
66        self.assertEqual(payment.ac, None)
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
75        # Add penalty fee ...
76        # ... for cleared
77        self.app['configuration']['2004'].penalty_ug = 99.0
78        # ... for returning
79        self.app['configuration']['2005'].penalty_ug = 88.0
80        error, payment = utils.setPaymentDetails('schoolfee',self.student)
81        self.assertEqual(payment.amount_auth, 6765.0)
82        IWorkflowState(self.student).setState('returning')
83        error, payment = utils.setPaymentDetails('schoolfee',self.student)
84        self.assertEqual(payment.p_level, 200)
85        self.assertEqual(payment.p_session, 2005)
86        self.assertEqual(payment.amount_auth, 7865.0)
87        self.assertEqual(payment.p_item, u'CERT1')
88        self.assertEqual(error, None)
89
90        error, payment = utils.setPaymentDetails('clearance',self.student)
91        self.assertEqual(payment.p_level, 100)
92        self.assertEqual(payment.p_session, 2004)
93        self.assertEqual(payment.amount_auth, 1234.0)
94        self.assertEqual(payment.p_item, u'CERT1')
95        self.assertEqual(error, None)
96
97        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
98        self.assertEqual(error, u'Previous session payment not yet implemented.')
99        return
100
101    def test_maxCredits(self):
102        dummy = object()
103        utils = getUtility(IStudentsUtils)
104        self.assertEqual(utils.maxCredits(dummy), 48)
105        return
106
107    def test_setMatricNumber(self):
108        IWorkflowState(self.student).setState('school fee paid')
109        site = grok.getSite()
110        utils = getUtility(IStudentsUtils)
111        site['configuration'].next_matric_integer = 1
112        self.student.matric_number = None
113        # So far we don't set matric numbers of ft students.
114        msg, mnumber = utils.setMatricNumber(self.student)
115        self.assertEqual(msg, 'Matriculation number cannot be set.')
116        self.assertEqual(mnumber, None)
117        #self.assertEqual(msg, None)
118        #self.assertEqual(mnumber, 1)
119        #self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
120        #self.assertEqual(site['configuration'].next_matric_integer, 2)
121        # Part time have an extended matric number
122        self.student.matric_number = None
123        self.student['studycourse'].certificate.study_mode = 'ug_pt'
124        msg, mnumber = utils.setMatricNumber(self.student)
125        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
126        # Foundation programme students don't get matric number.
127        self.student.matric_number = None
128        self.student['studycourse'].certificate.study_mode = 'found'
129        msg, mnumber = utils.setMatricNumber(self.student)
130        self.assertEqual(msg, 'Matriculation number cannot be set.')
131        self.assertEqual(mnumber, None)
132        # Certificate must be set.
133        self.student.matric_number = None
134        self.student['studycourse'].certificate = None
135        msg, mnumber = utils.setMatricNumber(self.student)
136        self.assertEqual(msg, 'No certificate assigned.')
137        return
Note: See TracBrowser for help on using the repository browser.