1 | ## $Id: test_browser.py 15027 2018-05-28 07:16:26Z 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 | from zope.component.hooks import setSite, clearSite |
---|
24 | from zope.component import createObject |
---|
25 | from zope.testbrowser.testing import Browser |
---|
26 | from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState |
---|
27 | from waeup.kofa.app import University |
---|
28 | from waeup.kofa.university.faculty import Faculty |
---|
29 | from waeup.kofa.university.department import Department |
---|
30 | from waeup.kofa.testing import FunctionalTestCase |
---|
31 | from waeup.kofa.interfaces import ( |
---|
32 | IExtFileStore, IFileStoreNameChooser, IUserAccount, IJobManager) |
---|
33 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
34 | from waeup.fceokene.testing import FunctionalLayer |
---|
35 | |
---|
36 | session = datetime.datetime.now().year - 2 |
---|
37 | SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg') |
---|
38 | |
---|
39 | class ApplicantUITest(FunctionalTestCase): |
---|
40 | """Perform some browser tests. |
---|
41 | """ |
---|
42 | layer = FunctionalLayer |
---|
43 | |
---|
44 | def setUp(self): |
---|
45 | super(ApplicantUITest, 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 | self.login_path = 'http://localhost/app/login' |
---|
62 | |
---|
63 | # Add bec applicants container |
---|
64 | self.beccontainer = ApplicantsContainer() |
---|
65 | self.beccontainer.mode = 'create' |
---|
66 | self.beccontainer.code = u'bec%s' % session |
---|
67 | self.beccontainer.prefix = u'bec' |
---|
68 | self.beccontainer.application_category = u'bec' |
---|
69 | self.beccontainer.year = session |
---|
70 | self.beccontainer.application_fee = 300.0 |
---|
71 | self.beccontainer.title = u'This is the bec%s container' % session |
---|
72 | self.app['applicants'][self.beccontainer.code] = self.beccontainer |
---|
73 | delta = datetime.timedelta(days=10) |
---|
74 | self.beccontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
75 | self.beccontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
76 | |
---|
77 | # Add ug applicants container |
---|
78 | self.putmecontainer = ApplicantsContainer() |
---|
79 | self.putmecontainer.mode = 'create' |
---|
80 | self.putmecontainer.code = u'putme%s' % session |
---|
81 | self.putmecontainer.prefix = u'putme' |
---|
82 | self.putmecontainer.application_category = u'bec' # doesn't matter |
---|
83 | self.putmecontainer.year = session |
---|
84 | self.putmecontainer.application_fee = 300.0 |
---|
85 | self.putmecontainer.title = u'This is the putme%s container' % session |
---|
86 | self.app['applicants'][self.putmecontainer.code] = self.putmecontainer |
---|
87 | delta = datetime.timedelta(days=10) |
---|
88 | self.putmecontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
89 | self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
90 | |
---|
91 | # Add tpu applicants container |
---|
92 | self.tpucontainer = ApplicantsContainer() |
---|
93 | self.tpucontainer.mode = 'create' |
---|
94 | self.tpucontainer.code = u'tpu%s' % session |
---|
95 | self.tpucontainer.prefix = u'tpu' |
---|
96 | self.tpucontainer.application_category = u'no' |
---|
97 | self.tpucontainer.year = session |
---|
98 | self.tpucontainer.application_fee = 300.0 |
---|
99 | self.tpucontainer.title = u'This is the tpu%s container' % session |
---|
100 | self.app['applicants'][self.tpucontainer.code] = self.tpucontainer |
---|
101 | delta = datetime.timedelta(days=10) |
---|
102 | self.tpucontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
103 | self.tpucontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
104 | |
---|
105 | # Populate university |
---|
106 | self.certificate = createObject('waeup.Certificate') |
---|
107 | self.certificate.code = 'CERT1' |
---|
108 | self.certificate.application_category = 'bec' |
---|
109 | self.certificate.start_level = 100 |
---|
110 | self.certificate.end_level = 500 |
---|
111 | self.certificate.study_mode = u'nce_ft' |
---|
112 | self.app['faculties']['fac1'] = Faculty() |
---|
113 | self.app['faculties']['fac1']['dep1'] = Department() |
---|
114 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
115 | self.certificate) |
---|
116 | |
---|
117 | # Add (customized) applicants |
---|
118 | becapplicant = createObject(u'waeup.Applicant') |
---|
119 | becapplicant.firstname = u'Anna' |
---|
120 | becapplicant.lastname = u'Post' |
---|
121 | self.app['applicants'][self.beccontainer.code].addApplicant(becapplicant) |
---|
122 | self.becapplication_number = becapplicant.application_number |
---|
123 | self.becapplicant = self.app['applicants'][self.beccontainer.code][ |
---|
124 | self.becapplication_number] |
---|
125 | self.becapplicant_path = ('http://localhost/app/applicants/bec%s/%s' |
---|
126 | % (session, self.becapplication_number)) |
---|
127 | |
---|
128 | putmeapplicant = createObject(u'waeup.Applicant') |
---|
129 | putmeapplicant.firstname = u'Anna' |
---|
130 | putmeapplicant.lastname = u'Post' |
---|
131 | self.app['applicants'][self.putmecontainer.code].addApplicant(putmeapplicant) |
---|
132 | self.putmeapplication_number = putmeapplicant.application_number |
---|
133 | self.putmeapplicant = self.app['applicants'][self.putmecontainer.code][ |
---|
134 | self.putmeapplication_number] |
---|
135 | self.putmeapplicant_path = ('http://localhost/app/applicants/putme%s/%s' |
---|
136 | % (session, self.putmeapplication_number)) |
---|
137 | |
---|
138 | tpuapplicant = createObject(u'waeup.Applicant') |
---|
139 | tpuapplicant.firstname = u'Michelle' |
---|
140 | tpuapplicant.lastname = u'Obama' |
---|
141 | self.app['applicants'][self.tpucontainer.code].addApplicant(tpuapplicant) |
---|
142 | self.tpuapplication_number = tpuapplicant.application_number |
---|
143 | self.tpuapplicant = self.app['applicants'][self.tpucontainer.code][ |
---|
144 | self.tpuapplication_number] |
---|
145 | self.tpuapplicant_path = ('http://localhost/app/applicants/tpu%s/%s' |
---|
146 | % (session, self.tpuapplication_number)) |
---|
147 | IUserAccount( |
---|
148 | self.app['applicants'][self.tpucontainer.code][ |
---|
149 | self.tpuapplicant.application_number]).setPassword('apwd') |
---|
150 | |
---|
151 | self.browser = Browser() |
---|
152 | self.browser.handleErrors = False |
---|
153 | |
---|
154 | def tearDown(self): |
---|
155 | super(ApplicantUITest, self).tearDown() |
---|
156 | shutil.rmtree(self.dc_root) |
---|
157 | clearSite() |
---|
158 | return |
---|
159 | |
---|
160 | def test_manage_and_view_bec_applicant(self): |
---|
161 | # Managers can manage bec applicants. |
---|
162 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
163 | self.browser.open(self.becapplicant_path) |
---|
164 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
165 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
166 | self.browser.open(self.becapplicant_path + '/manage') |
---|
167 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
168 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
169 | self.browser.open(self.becapplicant_path + '/edit') |
---|
170 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
171 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
172 | self.browser.open(self.becapplicant_path + '/application_slip.pdf') |
---|
173 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
174 | return |
---|
175 | |
---|
176 | def test_manage_and_view_putme_applicant(self): |
---|
177 | # Managers can manage bec applicants. |
---|
178 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
179 | self.browser.open(self.putmeapplicant_path) |
---|
180 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
181 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
182 | self.browser.open(self.putmeapplicant_path + '/manage') |
---|
183 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
184 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
185 | self.browser.open(self.putmeapplicant_path + '/edit') |
---|
186 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
187 | self.assertTrue("'O' Level" in self.browser.contents) |
---|
188 | self.browser.open(self.putmeapplicant_path + '/application_slip.pdf') |
---|
189 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
190 | |
---|
191 | |
---|
192 | def test_final_submit_tpu(self): |
---|
193 | IWorkflowState(self.tpuapplicant).setState('paid') |
---|
194 | self.browser.open(self.login_path) |
---|
195 | self.browser.getControl( |
---|
196 | name="form.login").value = self.tpuapplicant.applicant_id |
---|
197 | self.browser.getControl(name="form.password").value = 'apwd' |
---|
198 | self.browser.getControl("Login").click() |
---|
199 | self.browser.open(self.tpuapplicant_path + '/edit') |
---|
200 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
201 | self.browser.getControl(name="form.school1").value = ['s0010'] |
---|
202 | image = open(SAMPLE_IMAGE, 'rb') |
---|
203 | ctrl = self.browser.getControl(name='form.passport') |
---|
204 | file_ctrl = ctrl.mech_control |
---|
205 | file_ctrl.add_file(image, filename='myphoto.jpg') |
---|
206 | self.browser.getControl(name="confirm_passport").value = True |
---|
207 | self.browser.getControl("Save").click() |
---|
208 | self.browser.getControl("Finally Submit").click() |
---|
209 | self.assertTrue( |
---|
210 | 'Application submitted' in self.browser.contents) |
---|
211 | # Create 20 applicants who already selected s0010 |
---|
212 | for i in range(1,11): |
---|
213 | tpuapplicant = createObject(u'waeup.Applicant') |
---|
214 | tpuapplicant.firstname = u'John' |
---|
215 | tpuapplicant.lastname = u'Doe %s' %i |
---|
216 | tpuapplicant.school1 = 's0010' |
---|
217 | self.app['applicants'][ |
---|
218 | self.tpucontainer.code].addApplicant(tpuapplicant) |
---|
219 | IWorkflowState(tpuapplicant).setState('submitted') |
---|
220 | IWorkflowState(self.tpuapplicant).setState('paid') |
---|
221 | self.tpuapplicant.locked = False |
---|
222 | self.browser.open(self.tpuapplicant_path + '/edit') |
---|
223 | self.browser.getControl("Finally Submit").click() |
---|
224 | self.assertTrue("Maximum number of applications per school exceeded." |
---|
225 | in self.browser.contents) |
---|
226 | self.assertEqual(self.tpuapplicant.state, 'paid') |
---|
227 | return |
---|
228 | |
---|