1 | ## $Id: test_browser.py 17652 2023-12-03 11:29:17Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2013 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 | """ |
---|
19 | Test the applicant-related UI components. |
---|
20 | """ |
---|
21 | import os |
---|
22 | import datetime |
---|
23 | from zope.component import createObject, getUtility |
---|
24 | from zope.catalog.interfaces import ICatalog |
---|
25 | from zope.intid.interfaces import IIntIds |
---|
26 | from hurry.workflow.interfaces import IWorkflowState |
---|
27 | from kofacustom.unidel.testing import FunctionalLayer |
---|
28 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
29 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
30 | from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup |
---|
31 | from kofacustom.unidel.applicants.export import CustomApplicantExporter |
---|
32 | from kofacustom.unidel.applicants.batching import CustomApplicantProcessor |
---|
33 | |
---|
34 | class CustomApplicantUITests(ApplicantsFullSetup): |
---|
35 | # Tests for uploading/browsing the passport image of appplicants |
---|
36 | |
---|
37 | layer = FunctionalLayer |
---|
38 | |
---|
39 | def test_applicant_access(self): |
---|
40 | # Applicants can edit their record |
---|
41 | self.browser.open(self.login_path) |
---|
42 | self.login() |
---|
43 | self.assertTrue( |
---|
44 | 'You logged in as an applicant.' in self.browser.contents) |
---|
45 | self.browser.open(self.edit_path) |
---|
46 | return |
---|
47 | |
---|
48 | class ApplicantExporterTest(ApplicantImportExportSetup): |
---|
49 | |
---|
50 | layer = FunctionalLayer |
---|
51 | |
---|
52 | def setUp(self): |
---|
53 | super(ApplicantExporterTest, self).setUp() |
---|
54 | self.outfile = os.path.join(self.workdir, 'myoutput.csv') |
---|
55 | self.cat = getUtility(ICatalog, name='applicants_catalog') |
---|
56 | self.intids = getUtility(IIntIds) |
---|
57 | return |
---|
58 | |
---|
59 | def setup_applicant(self, applicant): |
---|
60 | # set predictable values for `applicant` |
---|
61 | applicant.reg_number = u'123456' |
---|
62 | applicant.applicant_id = u'dp2011_654321' |
---|
63 | applicant.firstname = u'Anna' |
---|
64 | applicant.lastname = u'Tester' |
---|
65 | applicant.middlename = u'M.' |
---|
66 | applicant.nationality = u'NG' |
---|
67 | applicant.date_of_birth = datetime.date(1981, 2, 4) |
---|
68 | applicant.sex = 'f' |
---|
69 | applicant.email = 'anna@sample.com' |
---|
70 | applicant.phone = u'+234-123-12345' |
---|
71 | applicant.course1 = self.certificate |
---|
72 | applicant.course2 = self.certificate |
---|
73 | applicant.course_admitted = self.certificate |
---|
74 | applicant.notice = u'Some notice\nin lines.' |
---|
75 | applicant.screening_score = 98 |
---|
76 | applicant.screening_venue = u'Exam Room' |
---|
77 | applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM' |
---|
78 | applicant.password = 'any password' |
---|
79 | return applicant |
---|
80 | |
---|
81 | class ApplicantsContainerUITests(ApplicantsFullSetup): |
---|
82 | # Tests for ApplicantsContainer class views and pages |
---|
83 | |
---|
84 | layer = FunctionalLayer |
---|
85 | |
---|
86 | def test_application_slip(self): |
---|
87 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
88 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
89 | self.browser.open(self.manage_path) |
---|
90 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
91 | self.fill_correct_values() |
---|
92 | self.browser.getControl("Save").click() |
---|
93 | IWorkflowState(self.applicant).setState('submitted') |
---|
94 | self.browser.open(self.view_path) |
---|
95 | self.browser.getLink("Download application slip").click() |
---|
96 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
97 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
98 | 'application/pdf') |
---|
99 | path = os.path.join(samples_dir(), 'application_slip.pdf') |
---|
100 | open(path, 'wb').write(self.browser.contents) |
---|
101 | print "Sample application_slip.pdf written to %s" % path |
---|