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

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

Reorganize tests.

Further adjust constructMatricNumber (see ticket).

  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1## $Id: test_utils.py 11596 2014-04-23 09:46:18Z 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 = 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 = 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        self.assertEqual(payment.p_level, 100)
60        self.assertEqual(payment.p_session, 2004)
61        self.assertEqual(payment.amount_auth, 6666.0)
62        self.assertEqual(payment.p_item, u'CERT1')
63        self.assertEqual(error, None)
64
65        # Add penalty fee ...
66        # ... for cleared
67        self.app['configuration']['2004'].penalty_ug = 99.0
68        # ... for returning
69        self.app['configuration']['2005'].penalty_ug = 88.0
70        error, payment = utils.setPaymentDetails('schoolfee',self.student)
71        self.assertEqual(payment.amount_auth, 6765.0)
72        IWorkflowState(self.student).setState('returning')
73        error, payment = utils.setPaymentDetails('schoolfee',self.student)
74        self.assertEqual(payment.p_level, 200)
75        self.assertEqual(payment.p_session, 2005)
76        self.assertEqual(payment.amount_auth, 7865.0)
77        self.assertEqual(payment.p_item, u'CERT1')
78        self.assertEqual(error, None)
79
80        error, payment = utils.setPaymentDetails('clearance',self.student)
81        self.assertEqual(payment.p_level, 100)
82        self.assertEqual(payment.p_session, 2004)
83        self.assertEqual(payment.amount_auth, 1234.0)
84        self.assertEqual(payment.p_item, u'CERT1')
85        self.assertEqual(error, None)
86
87        error, payment = utils.setPaymentDetails('gown',self.student)
88        self.assertEqual(payment.p_level, 100)
89        self.assertEqual(payment.p_session, 2004)
90        self.assertEqual(payment.amount_auth, 150.0)
91        self.assertEqual(payment.p_item, u'')
92        self.assertEqual(error, None)
93
94        error, payment = utils.setPaymentDetails('hostel_maintenance',self.student)
95        self.assertEqual(payment.p_level, 100)
96        self.assertEqual(payment.p_session, 2004)
97        self.assertEqual(payment.amount_auth, 180.0)
98        self.assertEqual(payment.p_item, u'')
99        self.assertEqual(error, None)
100
101        error, payment = utils.setPaymentDetails('bed_allocation',self.student)
102        self.assertEqual(payment.p_level, 100)
103        self.assertEqual(payment.p_session, 2004)
104        self.assertEqual(payment.amount_auth, 150.0)
105        self.assertEqual(payment.p_item, u'')
106        self.assertEqual(error, None)
107
108        error, payment = utils.setPaymentDetails('transfer',self.student)
109        self.assertEqual(payment.p_level, 100)
110        self.assertEqual(payment.p_session, 2004)
111        self.assertEqual(payment.amount_auth, 90.0)
112        self.assertEqual(payment.p_item, u'')
113        self.assertEqual(error, None)
114
115        error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100)
116        self.assertEqual(error, u'Previous session payment not yet implemented.')
117        return
118
119    def test_maxCredits(self):
120        dummy = object()
121        utils = getUtility(IStudentsUtils)
122        self.assertEqual(utils.maxCredits(dummy), 48)
123        return
124
125    def test_setMatricNumber(self):
126        site = grok.getSite()
127        utils = getUtility(IStudentsUtils)
128        site['configuration'].next_matric_integer = 1
129        self.student.matric_number = None
130        # So far we don't set matric numbers of ft students.
131        msg, mnumber = utils.setMatricNumber(self.student)
132        self.assertEqual(msg, 'Matriculation number cannot be set.')
133        self.assertEqual(mnumber, None)
134        #self.assertEqual(msg, None)
135        #self.assertEqual(mnumber, 1)
136        #self.assertEqual(self.student.matric_number, 'fac1/dep1/04/00001')
137        #self.assertEqual(site['configuration'].next_matric_integer, 2)
138        # Part time have an extended matric number
139        self.student.matric_number = None
140        self.student['studycourse'].certificate.study_mode = 'ug_pt'
141        msg, mnumber = utils.setMatricNumber(self.student)
142        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
143        # Foundation programme students don't get matric number.
144        self.student.matric_number = None
145        self.student['studycourse'].certificate.study_mode = 'found'
146        msg, mnumber = utils.setMatricNumber(self.student)
147        self.assertEqual(msg, 'Matriculation number cannot be set.')
148        self.assertEqual(mnumber, None)
149        # Certificate must be set.
150        self.student.matric_number = None
151        self.student['studycourse'].certificate = None
152        msg, mnumber = utils.setMatricNumber(self.student)
153        self.assertEqual(msg, 'No certificate assigned.')
154        return
Note: See TracBrowser for help on using the repository browser.