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

Last change on this file since 11627 was 11627, checked in by Henrik Bettermann, 10 years ago

To guarantee that cleared students pay both acceptance fee and school fees,
the eTranzact History can only be queried for school fee payments if
acceptance/clearance fee has been successfully queried/paid beforehand.

  • Property svn:keywords set to Id
File size: 6.1 KB
Line 
1## $Id: test_utils.py 11627 2014-05-07 18:21:58Z 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'].school_fee_1 = 6666.0
54        utils = getUtility(IStudentsUtils)
55
56        configuration = createObject('waeup.SessionConfiguration')
57        configuration.academic_session = 2005
58        self.app['configuration'].addSessionConfiguration(configuration)
59        self.app['configuration']['2005'].school_fee_2 = 7777.0
60
61        error, payment = utils.setPaymentDetails('schoolfee',self.student)
62        self.assertEqual(payment, None)
63        self.assertEqual(error, u'Wrong state.')
64        IWorkflowState(self.student).setState('cleared')
65        # School fee can be set.
66        error, payment = utils.setPaymentDetails('schoolfee',self.student)
67        self.assertEqual(payment.p_level, 100)
68        self.assertEqual(payment.p_session, 2004)
69        self.assertEqual(payment.amount_auth, 6666.0)
70        self.assertEqual(payment.p_item, u'CERT1')
71        self.assertEqual(error, None)
72        # Add penalty fee ...
73        # ... for cleared
74        self.app['configuration']['2004'].penalty_ug = 99.0
75        # ... for returning
76        self.app['configuration']['2005'].penalty_ug = 88.0
77        error, payment = utils.setPaymentDetails('schoolfee',self.student)
78        self.assertEqual(payment.amount_auth, 6765.0)
79        IWorkflowState(self.student).setState('returning')
80        error, payment = utils.setPaymentDetails('schoolfee',self.student)
81        self.assertEqual(payment.p_level, 200)
82        self.assertEqual(payment.p_session, 2005)
83        self.assertEqual(payment.amount_auth, 7865.0)
84        self.assertEqual(payment.p_item, u'CERT1')
85        self.assertEqual(error, None)
86
87        error, payment = utils.setPaymentDetails('clearance',self.student)
88        self.assertEqual(payment.p_level, 100)
89        self.assertEqual(payment.p_session, 2004)
90        self.assertEqual(payment.amount_auth, 1234.0)
91        self.assertEqual(payment.p_item, u'CERT1')
92        self.assertEqual(error, None)
93
94        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
95        self.assertEqual(error, u'Previous session payment not yet implemented.')
96        return
97
98    def test_maxCredits(self):
99        dummy = object()
100        utils = getUtility(IStudentsUtils)
101        self.assertEqual(utils.maxCredits(dummy), 48)
102        return
103
104    def test_setMatricNumber(self):
105        IWorkflowState(self.student).setState('school fee paid')
106        site = grok.getSite()
107        utils = getUtility(IStudentsUtils)
108        site['configuration'].next_matric_integer = 1
109        self.student.matric_number = None
110        # So far we don't set matric numbers of ft students.
111        msg, mnumber = utils.setMatricNumber(self.student)
112        self.assertEqual(msg, 'Matriculation number cannot be set.')
113        self.assertEqual(mnumber, None)
114        #self.assertEqual(msg, None)
115        #self.assertEqual(mnumber, 1)
116        #self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
117        #self.assertEqual(site['configuration'].next_matric_integer, 2)
118        # Part time have an extended matric number
119        self.student.matric_number = None
120        self.student['studycourse'].certificate.study_mode = 'ug_pt'
121        msg, mnumber = utils.setMatricNumber(self.student)
122        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
123        # Foundation programme students don't get matric number.
124        self.student.matric_number = None
125        self.student['studycourse'].certificate.study_mode = 'found'
126        msg, mnumber = utils.setMatricNumber(self.student)
127        self.assertEqual(msg, 'Matriculation number cannot be set.')
128        self.assertEqual(mnumber, None)
129        # Certificate must be set.
130        self.student.matric_number = None
131        self.student['studycourse'].certificate = None
132        msg, mnumber = utils.setMatricNumber(self.student)
133        self.assertEqual(msg, 'No certificate assigned.')
134        return
Note: See TracBrowser for help on using the repository browser.