1 | ## $Id: test_browser.py 16931 2022-04-21 08:07:31Z 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 shutil |
---|
19 | import tempfile |
---|
20 | import datetime |
---|
21 | import pytz |
---|
22 | import os |
---|
23 | import grok |
---|
24 | from zope.event import notify |
---|
25 | from zope.component.hooks import setSite, clearSite |
---|
26 | from zope.component import createObject |
---|
27 | from zope.testbrowser.testing import Browser |
---|
28 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
29 | from waeup.kofa.app import University |
---|
30 | from waeup.kofa.university.faculty import Faculty |
---|
31 | from waeup.kofa.university.department import Department |
---|
32 | from waeup.kofa.testing import FunctionalTestCase |
---|
33 | from waeup.kofa.interfaces import ( |
---|
34 | IExtFileStore, IFileStoreNameChooser, IUserAccount, IJobManager) |
---|
35 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
36 | from waeup.fceokene.testing import FunctionalLayer |
---|
37 | |
---|
38 | session = datetime.datetime.now().year - 2 |
---|
39 | SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
40 | |
---|
41 | class ApplicantUITest(FunctionalTestCase): |
---|
42 | """Perform some browser tests. |
---|
43 | """ |
---|
44 | layer = FunctionalLayer |
---|
45 | |
---|
46 | def setUp(self): |
---|
47 | super(ApplicantUITest, self).setUp() |
---|
48 | # Setup a sample site for each test |
---|
49 | app = University() |
---|
50 | self.dc_root = tempfile.mkdtemp() |
---|
51 | app['datacenter'].setStoragePath(self.dc_root) |
---|
52 | |
---|
53 | # Prepopulate the ZODB... |
---|
54 | self.getRootFolder()['app'] = app |
---|
55 | # we add the site immediately after creation to the |
---|
56 | # ZODB. Catalogs and other local utilities are not setup |
---|
57 | # before that step. |
---|
58 | self.app = self.getRootFolder()['app'] |
---|
59 | # Set site here. Some of the following setup code might need |
---|
60 | # to access grok.getSite() and should get our new app then |
---|
61 | setSite(app) |
---|
62 | |
---|
63 | self.login_path = 'http://localhost/app/login' |
---|
64 | |
---|
65 | # Add bec applicants container |
---|
66 | self.beccontainer = ApplicantsContainer() |
---|
67 | self.beccontainer.mode = 'create' |
---|
68 | self.beccontainer.code = u'bec%s' % session |
---|
69 | self.beccontainer.prefix = u'bec' |
---|
70 | self.beccontainer.application_category = u'bec' |
---|
71 | self.beccontainer.year = session |
---|
72 | self.beccontainer.application_fee = 300.0 |
---|
73 | self.beccontainer.title = u'This is the bec%s container' % session |
---|
74 | self.app['applicants'][self.beccontainer.code] = self.beccontainer |
---|
75 | delta = datetime.timedelta(days=10) |
---|
76 | self.beccontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
77 | self.beccontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
78 | |
---|
79 | # Add ug applicants container |
---|
80 | self.putmecontainer = ApplicantsContainer() |
---|
81 | self.putmecontainer.mode = 'create' |
---|
82 | self.putmecontainer.code = u'putme%s' % session |
---|
83 | self.putmecontainer.prefix = u'putme' |
---|
84 | self.putmecontainer.application_category = u'bec' # doesn't matter |
---|
85 | self.putmecontainer.year = session |
---|
86 | self.putmecontainer.application_fee = 300.0 |
---|
87 | self.putmecontainer.title = u'This is the putme%s container' % session |
---|
88 | self.app['applicants'][self.putmecontainer.code] = self.putmecontainer |
---|
89 | delta = datetime.timedelta(days=10) |
---|
90 | self.putmecontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
91 | self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
92 | |
---|
93 | # Add tpu applicants container |
---|
94 | self.tpucontainer = ApplicantsContainer() |
---|
95 | self.tpucontainer.mode = 'create' |
---|
96 | self.tpucontainer.code = u'tpu%s' % session |
---|
97 | self.tpucontainer.prefix = u'tpu' |
---|
98 | self.tpucontainer.application_category = u'basic' |
---|
99 | self.tpucontainer.year = session |
---|
100 | self.tpucontainer.application_fee = 300.0 |
---|
101 | self.tpucontainer.title = u'This is the tpu%s container' % session |
---|
102 | self.app['applicants'][self.tpucontainer.code] = self.tpucontainer |
---|
103 | delta = datetime.timedelta(days=10) |
---|
104 | self.tpucontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
105 | self.tpucontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
106 | |
---|
107 | # Add utp applicants container |
---|
108 | self.utpcontainer = ApplicantsContainer() |
---|
109 | self.utpcontainer.mode = 'create' |
---|
110 | self.utpcontainer.code = u'utp%s' % session |
---|
111 | self.utpcontainer.prefix = u'utp' |
---|
112 | self.utpcontainer.application_category = u'basic' |
---|
113 | self.utpcontainer.year = session |
---|
114 | self.utpcontainer.application_fee = 300.0 |
---|
115 | self.utpcontainer.title = u'This is the utp%s container' % session |
---|
116 | self.app['applicants'][self.utpcontainer.code] = self.utpcontainer |
---|
117 | delta = datetime.timedelta(days=10) |
---|
118 | self.utpcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
119 | self.utpcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
120 | |
---|
121 | # Populate university |
---|
122 | self.certificate = createObject('waeup.Certificate') |
---|
123 | self.certificate.code = 'CERT1' |
---|
124 | self.certificate.application_category = 'bec' |
---|
125 | self.certificate.start_level = 100 |
---|
126 | self.certificate.end_level = 500 |
---|
127 | self.certificate.study_mode = u'nce_ft' |
---|
128 | self.app['faculties']['fac1'] = Faculty() |
---|
129 | self.app['faculties']['fac1']['dep1'] = Department() |
---|
130 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
131 | self.certificate) |
---|
132 | |
---|
133 | # Add (customized) applicants |
---|
134 | becapplicant = createObject(u'waeup.Applicant') |
---|
135 | becapplicant.firstname = u'Anna' |
---|
136 | becapplicant.lastname = u'Post' |
---|
137 | self.app['applicants'][self.beccontainer.code].addApplicant(becapplicant) |
---|
138 | self.becapplication_number = becapplicant.application_number |
---|
139 | self.becapplicant = self.app['applicants'][self.beccontainer.code][ |
---|
140 | self.becapplication_number] |
---|
141 | self.becapplicant_path = ('http://localhost/app/applicants/bec%s/%s' |
---|
142 | % (session, self.becapplication_number)) |
---|
143 | |
---|
144 | putmeapplicant = createObject(u'waeup.Applicant') |
---|
145 | putmeapplicant.firstname = u'Anna' |
---|
146 | putmeapplicant.lastname = u'Post' |
---|
147 | self.app['applicants'][self.putmecontainer.code].addApplicant(putmeapplicant) |
---|
148 | self.putmeapplication_number = putmeapplicant.application_number |
---|
149 | self.putmeapplicant = self.app['applicants'][self.putmecontainer.code][ |
---|
150 | self.putmeapplication_number] |
---|
151 | self.putmeapplicant_path = ('http://localhost/app/applicants/putme%s/%s' |
---|
152 | % (session, self.putmeapplication_number)) |
---|
153 | |
---|
154 | tpuapplicant = createObject(u'waeup.Applicant') |
---|
155 | tpuapplicant.firstname = u'Michelle' |
---|
156 | tpuapplicant.lastname = u'Obama' |
---|
157 | self.app['applicants'][self.tpucontainer.code].addApplicant(tpuapplicant) |
---|
158 | self.tpuapplication_number = tpuapplicant.application_number |
---|
159 | self.tpuapplicant = self.app['applicants'][self.tpucontainer.code][ |
---|
160 | self.tpuapplication_number] |
---|
161 | self.tpuapplicant_path = ('http://localhost/app/applicants/tpu%s/%s' |
---|
162 | % (session, self.tpuapplication_number)) |
---|
163 | IUserAccount( |
---|
164 | self.app['applicants'][self.tpucontainer.code][ |
---|
165 | self.tpuapplicant.application_number]).setPassword('apwd') |
---|
166 | |
---|
167 | utpapplicant = createObject(u'waeup.Applicant') |
---|
168 | utpapplicant.firstname = u'Michelle' |
---|
169 | utpapplicant.lastname = u'Obama' |
---|
170 | self.app['applicants'][self.utpcontainer.code].addApplicant(utpapplicant) |
---|
171 | self.utpapplication_number = utpapplicant.application_number |
---|
172 | self.utpapplicant = self.app['applicants'][self.utpcontainer.code][ |
---|
173 | self.utpapplication_number] |
---|
174 | self.utpapplicant_path = ('http://localhost/app/applicants/utp%s/%s' |
---|
175 | % (session, self.utpapplication_number)) |
---|
176 | IUserAccount( |
---|
177 | self.app['applicants'][self.utpcontainer.code][ |
---|
178 | self.utpapplicant.application_number]).setPassword('apwd') |
---|
179 | |
---|
180 | self.browser = Browser() |
---|
181 | self.browser.handleErrors = False |
---|
182 | |
---|
183 | def tearDown(self): |
---|
184 | super(ApplicantUITest, self).tearDown() |
---|
185 | shutil.rmtree(self.dc_root) |
---|
186 | clearSite() |
---|
187 | return |
---|
188 | |
---|
189 | def test_manage_and_view_bec_applicant(self): |
---|
190 | # Managers can manage bec applicants. |
---|
191 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
192 | self.browser.open(self.becapplicant_path) |
---|
193 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
194 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
195 | self.browser.open(self.becapplicant_path + '/manage') |
---|
196 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
197 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
198 | self.browser.open(self.becapplicant_path + '/edit') |
---|
199 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
200 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
201 | self.browser.open(self.becapplicant_path + '/application_slip.pdf') |
---|
202 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
203 | return |
---|
204 | |
---|
205 | def test_manage_and_view_putme_applicant(self): |
---|
206 | # Managers can manage bec applicants. |
---|
207 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
208 | self.browser.open(self.putmeapplicant_path) |
---|
209 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
210 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
211 | self.browser.open(self.putmeapplicant_path + '/manage') |
---|
212 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
213 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
214 | self.browser.open(self.putmeapplicant_path + '/edit') |
---|
215 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
216 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
217 | self.browser.open(self.putmeapplicant_path + '/application_slip.pdf') |
---|
218 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
219 | |
---|
220 | def test_final_submit_tpu(self): |
---|
221 | # Create NCE certificate |
---|
222 | certificate1 = createObject('waeup.Certificate') |
---|
223 | certificate1.application_category = 'basic' |
---|
224 | certificate1.code = 'NCECERT1' |
---|
225 | certificate1.title = 'NCECert1' |
---|
226 | certificate1.start_level = 100 |
---|
227 | certificate1.end_level = 500 |
---|
228 | certificate1.study_mode = u'nce_ft' |
---|
229 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
230 | certificate1) |
---|
231 | IWorkflowState(self.tpuapplicant).setState('paid') |
---|
232 | self.browser.open(self.login_path) |
---|
233 | self.browser.getControl( |
---|
234 | name="form.login").value = self.tpuapplicant.applicant_id |
---|
235 | self.browser.getControl(name="form.password").value = 'apwd' |
---|
236 | self.browser.getControl("Login").click() |
---|
237 | self.browser.open(self.tpuapplicant_path + '/edit') |
---|
238 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
239 | self.browser.getControl(name="form.school_tpu").value = ['tpu0010'] |
---|
240 | self.browser.getControl(name="form.subj_comb").value = ['NCECERT1'] |
---|
241 | image = open(SAMPLE_IMAGE, 'rb') |
---|
242 | ctrl = self.browser.getControl(name='form.passport') |
---|
243 | file_ctrl = ctrl.mech_control |
---|
244 | file_ctrl.add_file(image, filename='myphoto.jpg') |
---|
245 | self.browser.getControl(name="confirm_passport").value = True |
---|
246 | self.browser.getControl("Save").click() |
---|
247 | self.browser.getControl("Finally Submit").click() |
---|
248 | self.assertTrue( |
---|
249 | 'Application submitted' in self.browser.contents) |
---|
250 | # Create 10 applicants who already selected tpu0010 |
---|
251 | for i in range(1,11): |
---|
252 | dummy = createObject(u'waeup.Applicant') |
---|
253 | dummy.firstname = u'John' |
---|
254 | dummy.lastname = u'Doe %s' %i |
---|
255 | dummy.school_tpu = 'tpu0010' |
---|
256 | self.app['applicants'][ |
---|
257 | self.tpucontainer.code].addApplicant(dummy) |
---|
258 | IWorkflowState(dummy).setState('submitted') |
---|
259 | IWorkflowState(self.tpuapplicant).setState('paid') |
---|
260 | self.tpuapplicant.locked = False |
---|
261 | self.browser.open(self.tpuapplicant_path + '/edit') |
---|
262 | self.browser.getControl(name="form.school_tpu").value = ['tpu0010'] |
---|
263 | self.browser.getControl("Finally Submit").click() |
---|
264 | self.assertTrue("Maximum number of applications per school exceeded." |
---|
265 | in self.browser.contents) |
---|
266 | self.assertEqual(self.tpuapplicant.state, 'paid') |
---|
267 | # Create second certificate |
---|
268 | certificate2 = createObject('waeup.Certificate') |
---|
269 | certificate2.code = 'NCECERT2' |
---|
270 | certificate2.title = 'NCECert2' |
---|
271 | certificate2.application_category = 'basic' |
---|
272 | certificate2.start_level = 100 |
---|
273 | certificate2.end_level = 500 |
---|
274 | certificate2.study_mode = u'nce_ft' |
---|
275 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
276 | certificate2) |
---|
277 | # Create one applicant with same subject and same school |
---|
278 | dummy = createObject(u'waeup.Applicant') |
---|
279 | dummy.firstname = u'John' |
---|
280 | dummy.lastname = u'Doe %s' %i |
---|
281 | dummy.school_tpu = 'tpu0012' |
---|
282 | dummy.subj_comb = certificate1 |
---|
283 | self.app['applicants'][ |
---|
284 | self.tpucontainer.code].addApplicant(dummy) |
---|
285 | IWorkflowState(dummy).setState('submitted') |
---|
286 | self.browser.open(self.tpuapplicant_path + '/edit') |
---|
287 | self.browser.getControl(name="form.school_tpu").value = ['tpu0012'] |
---|
288 | self.browser.getControl(name="form.subj_comb").value = ['NCECERT1'] |
---|
289 | self.browser.getControl("Finally Submit").click() |
---|
290 | self.assertTrue("Maximum number of applications per school exceeded." |
---|
291 | in self.browser.contents) |
---|
292 | # Same school with another subj_comb can be submitted |
---|
293 | self.assertEqual(self.tpuapplicant.state, 'paid') |
---|
294 | self.browser.open(self.tpuapplicant_path + '/edit') |
---|
295 | self.browser.getControl(name="form.school_tpu").value = ['tpu0012'] |
---|
296 | self.browser.getControl(name="form.subj_comb").value = ['NCECERT2'] |
---|
297 | self.browser.getControl("Finally Submit").click() |
---|
298 | self.assertEqual(self.tpuapplicant.state, 'submitted') |
---|
299 | return |
---|
300 | |
---|
301 | def test_final_submit_utp(self): |
---|
302 | # Create BED certificate |
---|
303 | certificate1 = createObject('waeup.Certificate') |
---|
304 | certificate1.application_category = 'basic' |
---|
305 | certificate1.code = 'BEDCERT1' |
---|
306 | certificate1.title = 'BEDCert1' |
---|
307 | certificate1.start_level = 100 |
---|
308 | certificate1.end_level = 500 |
---|
309 | certificate1.study_mode = u'nce_ft' |
---|
310 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
311 | certificate1) |
---|
312 | IWorkflowState(self.utpapplicant).setState('paid') |
---|
313 | self.browser.open(self.login_path) |
---|
314 | self.browser.getControl( |
---|
315 | name="form.login").value = self.utpapplicant.applicant_id |
---|
316 | self.browser.getControl(name="form.password").value = 'apwd' |
---|
317 | self.browser.getControl("Login").click() |
---|
318 | self.browser.open(self.utpapplicant_path + '/edit') |
---|
319 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
320 | self.browser.getControl(name="form.school_utp").value = ['utp0010'] |
---|
321 | self.browser.getControl(name="form.subj_comb").value = ['BEDCERT1'] |
---|
322 | image = open(SAMPLE_IMAGE, 'rb') |
---|
323 | ctrl = self.browser.getControl(name='form.passport') |
---|
324 | file_ctrl = ctrl.mech_control |
---|
325 | file_ctrl.add_file(image, filename='myphoto.jpg') |
---|
326 | self.browser.getControl(name="confirm_passport").value = True |
---|
327 | self.browser.getControl("Save").click() |
---|
328 | self.browser.getControl("Finally Submit").click() |
---|
329 | self.assertTrue( |
---|
330 | 'Application submitted' in self.browser.contents) |
---|
331 | # Create 10 applicants who already selected utp0010 |
---|
332 | for i in range(1,11): |
---|
333 | dummy = createObject(u'waeup.Applicant') |
---|
334 | dummy.firstname = u'John' |
---|
335 | dummy.lastname = u'Doe %s' %i |
---|
336 | dummy.school_utp = 'utp0010' |
---|
337 | self.app['applicants'][ |
---|
338 | self.utpcontainer.code].addApplicant(dummy) |
---|
339 | IWorkflowState(dummy).setState('submitted') |
---|
340 | IWorkflowState(self.utpapplicant).setState('paid') |
---|
341 | self.utpapplicant.locked = False |
---|
342 | self.browser.open(self.utpapplicant_path + '/edit') |
---|
343 | self.browser.getControl(name="form.school_utp").value = ['utp0010'] |
---|
344 | self.browser.getControl("Finally Submit").click() |
---|
345 | self.assertTrue("Maximum number of applications per school exceeded." |
---|
346 | in self.browser.contents) |
---|
347 | self.assertEqual(self.utpapplicant.state, 'paid') |
---|
348 | # Create second certificate |
---|
349 | certificate2 = createObject('waeup.Certificate') |
---|
350 | certificate2.code = 'BEDCERT2' |
---|
351 | certificate2.title = 'BEDCert2' |
---|
352 | certificate2.application_category = 'basic' |
---|
353 | certificate2.start_level = 100 |
---|
354 | certificate2.end_level = 500 |
---|
355 | certificate2.study_mode = u'nce_ft' |
---|
356 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
357 | certificate2) |
---|
358 | # Create one applicant with same subject and same school |
---|
359 | dummy = createObject(u'waeup.Applicant') |
---|
360 | dummy.firstname = u'John' |
---|
361 | dummy.lastname = u'Doe %s' %i |
---|
362 | dummy.school_utp = 'utp0012' |
---|
363 | dummy.subj_comb = certificate1 |
---|
364 | self.app['applicants'][ |
---|
365 | self.utpcontainer.code].addApplicant(dummy) |
---|
366 | IWorkflowState(dummy).setState('submitted') |
---|
367 | self.browser.open(self.utpapplicant_path + '/edit') |
---|
368 | self.browser.getControl(name="form.school_utp").value = ['utp0012'] |
---|
369 | self.browser.getControl(name="form.subj_comb").value = ['BEDCERT1'] |
---|
370 | self.browser.getControl("Finally Submit").click() |
---|
371 | # UTP applications allow two, one is not enough |
---|
372 | self.assertEqual(self.utpapplicant.state, 'submitted') |
---|
373 | return |
---|