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