1 | ## $Id: test_browser.py 9409 2012-10-24 22:01:59Z 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.university.faculty import Faculty |
---|
28 | from waeup.kofa.university.department import Department |
---|
29 | from waeup.kofa.students.tests.test_browser import StudentsFullSetup |
---|
30 | from waeup.kofa.testing import FunctionalTestCase |
---|
31 | from waeup.kofa.interfaces import ( |
---|
32 | IExtFileStore, IFileStoreNameChooser) |
---|
33 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
34 | from waeup.kofa.hostels.hostel import Bed, NOT_OCCUPIED |
---|
35 | from waeup.futminna.testing import FunctionalLayer |
---|
36 | |
---|
37 | |
---|
38 | class StudentProcessorTest(FunctionalTestCase): |
---|
39 | """Perform some batching tests. |
---|
40 | """ |
---|
41 | |
---|
42 | layer = FunctionalLayer |
---|
43 | |
---|
44 | def setUp(self): |
---|
45 | super(StudentProcessorTest, self).setUp() |
---|
46 | # Setup a sample site for each test |
---|
47 | app = University() |
---|
48 | self.dc_root = tempfile.mkdtemp() |
---|
49 | app['datacenter'].setStoragePath(self.dc_root) |
---|
50 | |
---|
51 | # Prepopulate the ZODB... |
---|
52 | self.getRootFolder()['app'] = app |
---|
53 | # we add the site immediately after creation to the |
---|
54 | # ZODB. Catalogs and other local utilities are not setup |
---|
55 | # before that step. |
---|
56 | self.app = self.getRootFolder()['app'] |
---|
57 | # Set site here. Some of the following setup code might need |
---|
58 | # to access grok.getSite() and should get our new app then |
---|
59 | setSite(app) |
---|
60 | |
---|
61 | |
---|
62 | def tearDown(self): |
---|
63 | super(StudentProcessorTest, self).tearDown() |
---|
64 | shutil.rmtree(self.workdir) |
---|
65 | shutil.rmtree(self.dc_root) |
---|
66 | clearSite() |
---|
67 | return |
---|
68 | |
---|
69 | class StudentUITests(StudentsFullSetup): |
---|
70 | """Tests for customized student class views and pages |
---|
71 | """ |
---|
72 | |
---|
73 | layer = FunctionalLayer |
---|
74 | |
---|
75 | def setUp(self): |
---|
76 | super(StudentUITests, self).setUp() |
---|
77 | |
---|
78 | # Create SSE faculty with certificate |
---|
79 | self.app['faculties']['SSE'] = Faculty(code='SSE') |
---|
80 | self.app['faculties']['SSE']['dep1'] = Department(code='dep1') |
---|
81 | self.certificate2 = createObject('waeup.Certificate') |
---|
82 | self.certificate2.code = u'CERT2' |
---|
83 | self.certificate2.application_category = 'basic' |
---|
84 | self.certificate2.study_mode = 'ug_ft' |
---|
85 | self.certificate2.start_level = 100 |
---|
86 | self.certificate2.end_level = 300 |
---|
87 | self.app['faculties']['SSE']['dep1'].certificates.addCertificate( |
---|
88 | self.certificate2) |
---|
89 | # Set study course attributes of test student |
---|
90 | self.student['studycourse'].certificate = self.certificate2 |
---|
91 | self.student['studycourse'].current_session = 2004 |
---|
92 | self.student['studycourse'].entry_session = 2004 |
---|
93 | self.student['studycourse'].current_verdict = 'A' |
---|
94 | self.student['studycourse'].current_level = 100 |
---|
95 | # Add sse bed |
---|
96 | bed = Bed() |
---|
97 | bed.bed_id = u'hall-1_A_101_C' |
---|
98 | bed.bed_number = 2 |
---|
99 | bed.owner = NOT_OCCUPIED |
---|
100 | bed.bed_type = u'sse_male_fr' |
---|
101 | self.app['hostels']['hall-1'].addBed(bed) |
---|
102 | |
---|
103 | def test_get_returning_data(self): |
---|
104 | # Student is in level 100, session 2004 with verdict A |
---|
105 | utils = getUtility(IStudentsUtils) |
---|
106 | self.assertEqual(utils.getReturningData(self.student),(2005, 200)) |
---|
107 | self.student['studycourse'].current_verdict = 'C' |
---|
108 | self.assertEqual(utils.getReturningData(self.student),(2005, 110)) |
---|
109 | self.student['studycourse'].current_verdict = 'D' |
---|
110 | self.assertEqual(utils.getReturningData(self.student),(2005, 100)) |
---|
111 | return |
---|
112 | |
---|
113 | def test_set_payment_details(self): |
---|
114 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
115 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
116 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
117 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
118 | self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
119 | utils = getUtility(IStudentsUtils) |
---|
120 | |
---|
121 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
122 | self.assertEqual(payment, None) |
---|
123 | self.assertEqual(error, u'Amount could not be determined.') |
---|
124 | |
---|
125 | self.student.nationality = u'NG' |
---|
126 | |
---|
127 | IWorkflowState(self.student).setState('cleared') |
---|
128 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
129 | self.assertEqual(payment.p_level, 100) |
---|
130 | self.assertEqual(payment.p_session, 2004) |
---|
131 | self.assertEqual(payment.amount_auth, 37000.0) |
---|
132 | self.assertEqual(payment.p_item, u'CERT2') |
---|
133 | self.assertEqual(error, None) |
---|
134 | |
---|
135 | self.certificate2.study_mode = 'jm_ft' |
---|
136 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
137 | self.assertEqual(payment.amount_auth, 72700.0) |
---|
138 | |
---|
139 | IWorkflowState(self.student).setState('returning') |
---|
140 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
141 | self.assertEqual(payment.p_level, 200) |
---|
142 | self.assertEqual(payment.p_session, 2005) |
---|
143 | self.assertEqual(payment.amount_auth, 37000.0) |
---|
144 | self.assertEqual(payment.p_item, u'CERT2') |
---|
145 | self.assertEqual(error, None) |
---|
146 | |
---|
147 | self.certificate2.study_mode = 'ug_ft' |
---|
148 | error, payment = utils.setPaymentDetails('schoolfee',self.student) |
---|
149 | self.assertEqual(payment.amount_auth, 20000.0) |
---|
150 | |
---|
151 | error, payment = utils.setPaymentDetails('schoolfee',self.student, 2004, 100) |
---|
152 | self.assertEqual(error, u'Previous session payment not yet implemented.') |
---|
153 | |
---|
154 | error, payment = utils.setPaymentDetails('clearance',self.student) |
---|
155 | self.assertEqual(payment.p_level, 100) |
---|
156 | self.assertEqual(payment.p_session, 2004) |
---|
157 | self.assertEqual(payment.amount_auth, 20000.0) |
---|
158 | self.assertEqual(payment.p_item, u'CERT2') |
---|
159 | self.assertEqual(error, None) |
---|
160 | |
---|
161 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
162 | self.assertEqual(payment.p_level, 100) |
---|
163 | self.assertEqual(payment.p_session, 2004) |
---|
164 | self.assertEqual(payment.amount_auth, 10000.0) |
---|
165 | self.assertEqual(payment.p_item, u'sse_male_fr') |
---|
166 | self.assertEqual(error, None) |
---|
167 | |
---|
168 | self.student['studycourse'].certificate = self.certificate |
---|
169 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
170 | self.assertEqual(payment.p_level, 100) |
---|
171 | self.assertEqual(payment.p_session, 2004) |
---|
172 | self.assertEqual(payment.amount_auth, 10000.0) |
---|
173 | self.assertEqual(payment.p_item, u'regular_male_fr') |
---|
174 | self.assertEqual(error, None) |
---|
175 | |
---|
176 | error, payment = utils.setPaymentDetails('block_h_maintenance',self.student) |
---|
177 | self.assertEqual(payment.p_level, 100) |
---|
178 | self.assertEqual(payment.p_session, 2004) |
---|
179 | self.assertEqual(payment.amount_auth, 15000.0) |
---|
180 | self.assertEqual(payment.p_item, u'regular_male_fr') |
---|
181 | self.assertEqual(error, None) |
---|
182 | |
---|
183 | self.app['hostels'].accommodation_session = 2009 |
---|
184 | error, payment = utils.setPaymentDetails('hostel_maintenance',self.student) |
---|
185 | self.assertEqual(error, |
---|
186 | 'Current session does not match accommodation session.') |
---|
187 | self.assertEqual(payment, None) |
---|
188 | return |
---|
189 | |
---|
190 | def test_get_accommodation_details(self): |
---|
191 | self.app['configuration']['2004'].gown_fee = 150.0 |
---|
192 | self.app['configuration']['2004'].transfer_fee = 90.0 |
---|
193 | self.app['configuration']['2004'].booking_fee = 150.0 |
---|
194 | self.app['configuration']['2004'].maint_fee = 180.0 |
---|
195 | self.app['configuration']['2004'].clearance_fee = 120.0 |
---|
196 | utils = getUtility(IStudentsUtils) |
---|
197 | |
---|
198 | details = utils.getAccommodationDetails(self.student) |
---|
199 | self.assertEqual(details['bt'], u'sse_male_fr') |
---|
200 | |
---|
201 | def test_student_accommodation(self): |
---|
202 | # Login |
---|
203 | self.browser.open(self.login_path) |
---|
204 | self.browser.getControl(name="form.login").value = self.student_id |
---|
205 | self.browser.getControl(name="form.password").value = 'spwd' |
---|
206 | self.browser.getControl("Login").click() |
---|
207 | |
---|
208 | # Students can book accommodation without AC ... |
---|
209 | self.browser.open(self.acco_path) |
---|
210 | IWorkflowState(self.student).setState('admitted') |
---|
211 | self.browser.getLink("Book accommodation").click() |
---|
212 | self.assertFalse('Activation Code:' in self.browser.contents) |
---|
213 | self.browser.getControl("Create bed ticket").click() |
---|
214 | # Bed is randomly selected but, since there is only |
---|
215 | # one bed for this student, we know that ... |
---|
216 | self.assertMatches('...Hall 1, Block A, Room 101, Bed C...', |
---|
217 | self.browser.contents) |
---|
218 | return |
---|