1 | ## $Id: test_browser.py 8908 2012-07-04 07:46:38Z 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 os |
---|
19 | import shutil |
---|
20 | import tempfile |
---|
21 | from StringIO import StringIO |
---|
22 | from hurry.workflow.interfaces import IWorkflowState |
---|
23 | from zope.component.hooks import setSite, clearSite |
---|
24 | from zope.component import getUtility, createObject |
---|
25 | from zope.interface import verify |
---|
26 | from waeup.kofa.app import University |
---|
27 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
28 | from waeup.kofa.testing import FunctionalTestCase |
---|
29 | from waeup.kofa.interfaces import ( |
---|
30 | IExtFileStore, IFileStoreNameChooser) |
---|
31 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
32 | from waeup.fceokene.testing import FunctionalLayer |
---|
33 | |
---|
34 | |
---|
35 | class StudentProcessorTest(FunctionalTestCase): |
---|
36 | """Perform some batching tests. |
---|
37 | """ |
---|
38 | |
---|
39 | layer = FunctionalLayer |
---|
40 | |
---|
41 | def setUp(self): |
---|
42 | super(StudentProcessorTest, self).setUp() |
---|
43 | # Setup a sample site for each test |
---|
44 | app = University() |
---|
45 | self.dc_root = tempfile.mkdtemp() |
---|
46 | app['datacenter'].setStoragePath(self.dc_root) |
---|
47 | |
---|
48 | # Prepopulate the ZODB... |
---|
49 | self.getRootFolder()['app'] = app |
---|
50 | # we add the site immediately after creation to the |
---|
51 | # ZODB. Catalogs and other local utilities are not setup |
---|
52 | # before that step. |
---|
53 | self.app = self.getRootFolder()['app'] |
---|
54 | # Set site here. Some of the following setup code might need |
---|
55 | # to access grok.getSite() and should get our new app then |
---|
56 | setSite(app) |
---|
57 | |
---|
58 | |
---|
59 | def tearDown(self): |
---|
60 | super(StudentProcessorTest, self).tearDown() |
---|
61 | shutil.rmtree(self.workdir) |
---|
62 | shutil.rmtree(self.dc_root) |
---|
63 | clearSite() |
---|
64 | return |
---|
65 | |
---|
66 | class StudentUITests(StudentsFullSetup): |
---|
67 | """Tests for customized student class views and pages |
---|
68 | """ |
---|
69 | |
---|
70 | layer = FunctionalLayer |
---|
71 | |
---|
72 | def test_manage_payments(self): |
---|
73 | # Add missing configuration data |
---|
74 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
75 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
76 | #self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
77 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
78 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
79 | |
---|
80 | # Managers can add online payment tickets |
---|
81 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
82 | self.browser.open(self.payments_path) |
---|
83 | self.browser.getControl("Add online payment ticket").click() |
---|
84 | self.browser.getControl("Create ticket").click() |
---|
85 | self.assertMatches('...Amount could not be determined...', |
---|
86 | self.browser.contents) |
---|
87 | IWorkflowState(self.student).setState('cleared') |
---|
88 | self.browser.open(self.payments_path + '/addop') |
---|
89 | self.browser.getControl("Create ticket").click() |
---|
90 | self.assertMatches('...ticket created...', |
---|
91 | self.browser.contents) |
---|
92 | ctrl = self.browser.getControl(name='val_id') |
---|
93 | value = ctrl.options[0] |
---|
94 | self.browser.getLink(value).click() |
---|
95 | self.assertMatches('...Amount Authorized...', |
---|
96 | self.browser.contents) |
---|
97 | # Managers can open payment slip |
---|
98 | self.browser.getLink("Download payment slip").click() |
---|
99 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
100 | self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') |
---|
101 | # Set ticket paid |
---|
102 | ticket = self.student['payments'].items()[0][1] |
---|
103 | ticket.p_state = 'paid' |
---|
104 | self.browser.open(self.payments_path + '/addop') |
---|
105 | self.browser.getControl("Create ticket").click() |
---|
106 | self.assertMatches('...This type of payment has already been made...', |
---|
107 | self.browser.contents) |
---|
108 | # Remove all payments so that we can add a school fee payment again |
---|
109 | keys = [i for i in self.student['payments'].keys()] |
---|
110 | for payment in keys: |
---|
111 | del self.student['payments'][payment] |
---|
112 | self.browser.open(self.payments_path + '/addop') |
---|
113 | self.browser.getControl("Create ticket").click() |
---|
114 | self.assertMatches('...ticket created...', |
---|
115 | self.browser.contents) |
---|
116 | self.browser.open(self.payments_path + '/addop') |
---|
117 | self.browser.getControl(name="form.p_category").value = ['gown'] |
---|
118 | self.browser.getControl("Create ticket").click() |
---|
119 | self.assertMatches('...ticket created...', |
---|
120 | self.browser.contents) |
---|
121 | self.browser.open(self.payments_path + '/addop') |
---|
122 | self.browser.getControl(name="form.p_category").value = ['transfer'] |
---|
123 | self.browser.getControl("Create ticket").click() |
---|
124 | self.assertMatches('...ticket created...', |
---|
125 | self.browser.contents) |
---|
126 | self.browser.open(self.payments_path + '/addop') |
---|
127 | self.browser.getControl( |
---|
128 | name="form.p_category").value = ['bed_allocation'] |
---|
129 | self.browser.getControl("Create ticket").click() |
---|
130 | self.assertMatches('...ticket created...', |
---|
131 | self.browser.contents) |
---|
132 | self.browser.open(self.payments_path + '/addop') |
---|
133 | self.browser.getControl( |
---|
134 | name="form.p_category").value = ['hostel_maintenance'] |
---|
135 | self.browser.getControl("Create ticket").click() |
---|
136 | self.assertMatches('...ticket created...', |
---|
137 | self.browser.contents) |
---|
138 | self.browser.open(self.payments_path + '/addop') |
---|
139 | self.browser.getControl(name="form.p_category").value = ['clearance'] |
---|
140 | self.browser.getControl("Create ticket").click() |
---|
141 | self.assertMatches('...ticket created...', |
---|
142 | self.browser.contents) |
---|
143 | self.browser.open(self.payments_path + '/addop') |
---|
144 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
145 | self.browser.getControl("Create ticket").click() |
---|
146 | self.assertMatches('...ticket created...', |
---|
147 | self.browser.contents) |
---|
148 | # In state returning we can add a new school fee ticket since |
---|
149 | # p_session and p_level is different |
---|
150 | IWorkflowState(self.student).setState('returning') |
---|
151 | self.browser.open(self.payments_path + '/addop') |
---|
152 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
153 | self.browser.getControl("Create ticket").click() |
---|
154 | self.assertMatches('...ticket created...', |
---|
155 | self.browser.contents) |
---|
156 | # In state admitted school fee can't be determined |
---|
157 | IWorkflowState(self.student).setState('admitted') |
---|
158 | self.browser.open(self.payments_path + '/addop') |
---|
159 | self.browser.getControl(name="form.p_category").value = ['schoolfee'] |
---|
160 | self.browser.getControl("Create ticket").click() |
---|
161 | self.assertMatches('...Amount could not be determined...', |
---|
162 | self.browser.contents) |
---|
163 | |
---|
164 | # If the session configuration doesn't exist an error message will |
---|
165 | # be shown. No other requirement is being checked. |
---|
166 | del self.app['configuration']['2004'] |
---|
167 | self.browser.open(self.payments_path) |
---|
168 | self.browser.getControl("Add online payment ticket").click() |
---|
169 | self.browser.getControl("Create ticket").click() |
---|
170 | self.assertMatches('...Session configuration object is not...', |
---|
171 | self.browser.contents) |
---|
172 | |
---|
173 | def test_get_returning_data(self): |
---|
174 | # Student is in level 100, session 2004 with verdict A |
---|
175 | utils = getUtility(IStudentsUtils) |
---|
176 | self.assertEqual(utils.getReturningData(self.student),(2005, 200)) |
---|
177 | self.student['studycourse'].current_verdict = 'C' |
---|
178 | self.assertEqual(utils.getReturningData(self.student),(2005, 110)) |
---|
179 | self.student['studycourse'].current_verdict = 'D' |
---|
180 | self.assertEqual(utils.getReturningData(self.student),(2005, 100)) |
---|
181 | return |
---|
182 | |
---|
183 | def test_set_payment_details(self): |
---|
184 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
185 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
186 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
187 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
188 | utils = getUtility(IStudentsUtils) |
---|
189 | |
---|
190 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
191 | self.assertEqual(payment, None) |
---|
192 | self.assertEqual(error, u'Amount could not be determined.') |
---|
193 | |
---|
194 | IWorkflowState(self.student).setState('cleared') |
---|
195 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
196 | self.assertEqual(payment.p_level, 100) |
---|
197 | self.assertEqual(payment.p_session, 2004) |
---|
198 | self.assertEqual(payment.amount_auth, 40000.0) |
---|
199 | self.assertEqual(payment.p_item, u'CERT1') |
---|
200 | self.assertEqual(error, None) |
---|
201 | |
---|
202 | IWorkflowState(self.student).setState('returning') |
---|
203 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
204 | self.assertEqual(payment.p_level, 200) |
---|
205 | self.assertEqual(payment.p_session, 2005) |
---|
206 | self.assertEqual(payment.amount_auth, 20000.0) |
---|
207 | self.assertEqual(payment.p_item, u'CERT1') |
---|
208 | self.assertEqual(error, None) |
---|
209 | |
---|
210 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
211 | self.assertEqual(payment.p_level, 100) |
---|
212 | self.assertEqual(payment.p_session, 2004) |
---|
213 | self.assertEqual(payment.amount_auth, 34250.0) |
---|
214 | self.assertEqual(payment.p_item, u'CERT1') |
---|
215 | self.assertEqual(error, None) |
---|
216 | |
---|
217 | error, payment = utils.setPaymentDetails('gown',self.student) |
---|
218 | self.assertEqual(payment.p_level, 100) |
---|
219 | self.assertEqual(payment.p_session, 2004) |
---|
220 | self.assertEqual(payment.amount_auth, 150.0) |
---|
221 | self.assertEqual(payment.p_item, u'') |
---|
222 | self.assertEqual(error, None) |
---|
223 | |
---|
224 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
225 | self.assertEqual(payment.p_level, 100) |
---|
226 | self.assertEqual(payment.p_session, 2004) |
---|
227 | self.assertEqual(payment.amount_auth, 180.0) |
---|
228 | self.assertEqual(payment.p_item, u'') |
---|
229 | self.assertEqual(error, None) |
---|
230 | |
---|
231 | error, payment = utils.setPaymentDetails('bed_allocation',self.student) |
---|
232 | self.assertEqual(payment.p_level, 100) |
---|
233 | self.assertEqual(payment.p_session, 2004) |
---|
234 | self.assertEqual(payment.amount_auth, 150.0) |
---|
235 | self.assertEqual(payment.p_item, u'') |
---|
236 | self.assertEqual(error, None) |
---|
237 | |
---|
238 | error, payment = utils.setPaymentDetails('transfer',self.student) |
---|
239 | self.assertEqual(payment.p_level, 100) |
---|
240 | self.assertEqual(payment.p_session, 2004) |
---|
241 | self.assertEqual(payment.amount_auth, 90.0) |
---|
242 | self.assertEqual(payment.p_item, u'') |
---|
243 | self.assertEqual(error, None) |
---|
244 | return |
---|