source: main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests/test_browser.py @ 14822

Last change on this file since 14822 was 14822, checked in by Henrik Bettermann, 7 years ago

Show screening invitation link only after applicants have paid.

  • Property svn:keywords set to Id
File size: 14.0 KB
Line 
1## $Id: test_browser.py 14822 2017-08-30 10:33:33Z 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##
18import grok
19import datetime
20import pytz
21import os
22from zope.event import notify
23from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
24from zope.component import createObject, getUtility
25from waeup.kofa.configuration import SessionConfiguration
26from waeup.kofa.interfaces import IUserAccount
27from waeup.kofa.applicants.container import ApplicantsContainer
28from waeup.kofa.browser.tests.test_pdf import samples_dir
29from waeup.aaue.testing import FunctionalLayer
30from waeup.kofa.applicants.tests.test_browser import (
31    ApplicantsFullSetup, container_name_1, session_1)
32
33class CustomApplicantUITest(ApplicantsFullSetup):
34    """Perform some browser tests.
35    """
36
37    layer = FunctionalLayer
38
39    def test_show_credentials_on_landing_page(self):
40        # An applicant can register himself.
41        self.applicant.reg_number = u'1234'
42        notify(grok.ObjectModifiedEvent(self.applicant))
43        self.browser.open('http://localhost/app/applicants/%s/' % container_name_1)
44        self.browser.getLink("Register for application").click()
45        # Fill the edit form with suitable values
46        self.browser.getControl(name="form.firstname").value = 'Klaus'
47        self.browser.getControl(name="form.lastname").value = 'Lutz'
48        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
49        self.browser.getControl("Send login credentials").click()
50        self.assertMatches('...Your registration was successful...',
51            self.browser.contents)
52        self.assertTrue('<td>Password:</td>' in self.browser.contents)
53        return
54
55    def test_payment(self):
56        configuration = SessionConfiguration()
57        configuration.academic_session = session_1
58        self.app['configuration'].addSessionConfiguration(configuration)
59        self.applicantscontainer.application_fee = 200.0
60        self.login()
61        self.browser.open(self.edit_path)
62        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
63        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
64        #self.browser.getControl(name="form.programme_type").value = ['regular']
65        self.browser.getControl(name="form.nationality").value = ['NG']
66        self.browser.getControl(name="form.sex").value = ['m']
67        self.browser.getControl(name="form.lastname").value = 'Merkel'
68        self.browser.getControl("Save").click()
69        self.browser.getControl("Add online payment ticket").click()
70        self.assertMatches('...Payment ticket created...',
71                           self.browser.contents)
72        # Payment tickets can be downloaded without submitting the form.
73        self.browser.getLink("Download payment slip").click()
74        self.assertEqual(self.browser.headers['Content-Type'],
75                 'application/pdf')
76        # AAUE applicants never see the 'Remove Selected Tickets' button.
77        self.browser.open(self.edit_path)
78        self.assertFalse('Remove' in self.browser.contents)
79        return
80
81    def test_screening_invitation_download(self):
82        self.login()
83        self.applicant.screening_date = u'29th August 2016 @ 8:30 am'
84        self.applicant.screening_venue = u'Main Auditorium'
85        self.applicant.lastname = u'Cox'
86        self.applicant.firstname = u'Jo'
87        self.applicant.email = 'xx@yy.zz'
88        self.browser.open(self.view_path)
89        self.assertFalse("Download application slip" in self.browser.contents)
90        IWorkflowState(self.applicant).setState('paid')
91        self.browser.open(self.view_path)
92        self.browser.getLink("screening invitation").click()
93        self.assertEqual(self.browser.headers['Status'], '200 Ok')
94        self.assertEqual(
95            self.browser.headers['Content-Type'], 'application/pdf')
96        path = os.path.join(samples_dir(), 'screening_invitation.pdf')
97        open(path, 'wb').write(self.browser.contents)
98        print "Sample PDF screening_invitation.pdf written to %s" % path
99        return
100
101    def test_application_slips(self):
102        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
103        self.slip_path = self.view_path + '/application_slip.pdf'
104        self.browser.open(self.manage_path)
105        self.assertEqual(self.browser.headers['Status'], '200 Ok')
106        self.fill_correct_values()
107        self.browser.getControl("Save").click()
108        IWorkflowState(self.applicant).setState('admitted')
109        self.applicant.course_admitted = self.certificate
110        self.browser.open(self.manage_path)
111        self.browser.getLink("Download application slip").click()
112        self.assertEqual(self.browser.headers['Status'], '200 Ok')
113        self.assertEqual(self.browser.headers['Content-Type'],
114                         'application/pdf')
115        path = os.path.join(samples_dir(), 'application_slip.pdf')
116        open(path, 'wb').write(self.browser.contents)
117        print "Sample application_slip.pdf written to %s" % path
118
119    def test_transcript_application_manage(self):
120        # Add trans applicants container
121        self.transcontainer = ApplicantsContainer()
122        self.transcontainer.mode = 'create'
123        self.transcontainer.code = u'trans%s' % session_1
124        self.transcontainer.prefix = u'trans'
125        self.transcontainer.application_category = u'no'
126        self.transcontainer.year = session_1
127        self.transcontainer.application_fee = 300.0
128        self.transcontainer.title = u'This is the trans%s container' % session_1
129        self.app['applicants'][self.transcontainer.code] = self.transcontainer
130        delta = datetime.timedelta(days=10)
131        self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
132        self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
133        # Add applicant
134        transapplicant = createObject(u'waeup.Applicant')
135        transapplicant.firstname = u'Anna'
136        transapplicant.lastname = u'Post'
137        self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant)
138        self.transapplication_number = transapplicant.application_number
139        self.transapplicant = self.app['applicants'][self.transcontainer.code][
140            self.transapplication_number]
141        self.transapplicant_path = ('http://localhost/app/applicants/trans%s/%s'
142            % (session_1, self.transapplication_number))
143        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
144        self.browser.open(self.transapplicant_path)
145        self.assertEqual(self.browser.headers['Status'], '200 Ok')
146        self.assertTrue("Dispatch Address" in self.browser.contents)
147
148    def _prepare_cert_container(self):
149        # Add cert applicants container
150        self.certcontainer = ApplicantsContainer()
151        self.certcontainer.mode = 'update'
152        self.certcontainer.code = u'cert%s' % session_1
153        self.certcontainer.prefix = u'cert'
154        self.certcontainer.application_category = u'no'
155        self.certcontainer.year = session_1
156        self.certcontainer.application_fee = 300.0
157        self.certcontainer.title = u'This is the cert%s container' % session_1
158        self.app['applicants'][self.certcontainer.code] = self.certcontainer
159        delta = datetime.timedelta(days=10)
160        self.certcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
161        self.certcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
162        # Add applicant
163        certapplicant = createObject(u'waeup.Applicant')
164        certapplicant.firstname = u'Anna'
165        certapplicant.lastname = u'Post'
166        certapplicant.reg_number = u'1234%s' % self.certcontainer.code
167        self.app['applicants'][self.certcontainer.code].addApplicant(certapplicant)
168        self.certapplication_number = certapplicant.application_number
169        self.certapplicant = self.app['applicants'][self.certcontainer.code][
170            self.certapplication_number]
171        self.certcontainer_path = ('http://localhost/app/applicants/cert%s'
172            % session_1)
173        self.certapplicant_path = ('http://localhost/app/applicants/cert%s/%s'
174            % (session_1, self.certapplication_number))
175
176    def test_certificate_request_manage(self):
177        self._prepare_cert_container()
178        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
179        self.browser.open(self.certapplicant_path)
180        self.assertEqual(self.browser.headers['Status'], '200 Ok')
181        self.assertTrue("Dispatch Address" in self.browser.contents)
182
183    def test_certificate_request_update(self):
184        self._prepare_cert_container()
185        #IWorkflowState(self.applicant).setState('initialized')
186        self.browser.open(self.certcontainer_path + '/register')
187        self.browser.getControl(name="form.lastname").value = 'post'
188        self.browser.getControl(name="form.reg_number").value = '1234'
189        self.browser.getControl(name="form.email").value = 'new@yy.zz'
190        self.browser.getControl("Send login credentials").click()
191        # Yeah, we succeded ...
192        self.assertTrue('Your registration was successful.'
193            in self.browser.contents)
194
195    def test_pg_application_manage(self):
196        # Add pg applicants container
197        self.pgcontainer = ApplicantsContainer()
198        self.pgcontainer.mode = 'create'
199        self.pgcontainer.code = u'pgft%s' % session_1
200        self.pgcontainer.prefix = u'pgft'
201        self.pgcontainer.application_category = u'no'
202        self.pgcontainer.year = session_1
203        self.pgcontainer.application_fee = 300.0
204        self.pgcontainer.title = u'This is the pgft%s container' % session_1
205        self.app['applicants'][self.pgcontainer.code] = self.pgcontainer
206        delta = datetime.timedelta(days=10)
207        self.pgcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
208        self.pgcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
209        # Add applicant
210        pgapplicant = createObject(u'waeup.Applicant')
211        pgapplicant.firstname = u'Anna'
212        pgapplicant.lastname = u'Post'
213        self.app['applicants'][self.pgcontainer.code].addApplicant(pgapplicant)
214        self.pgapplication_number = pgapplicant.application_number
215        self.pgapplicant = self.app['applicants'][self.pgcontainer.code][
216            self.pgapplication_number]
217        self.pgapplicant_path = ('http://localhost/app/applicants/pgft%s/%s'
218            % (session_1, self.pgapplication_number))
219        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
220        self.browser.open(self.pgapplicant_path)
221        self.assertEqual(self.browser.headers['Status'], '200 Ok')
222        self.assertTrue("3rd Higher Education Record" in self.browser.contents)
223
224    def test_transcript_payment(self):
225        configuration = SessionConfiguration()
226        configuration.academic_session = session_1
227        self.app['configuration'].addSessionConfiguration(configuration)
228        # Add special application container
229        applicantscontainer = ApplicantsContainer()
230        applicantscontainer.year = session_1
231        applicantscontainer.application_fee = 200.0
232        applicantscontainer.code = u'trans1234'
233        applicantscontainer.prefix = 'trans'
234        applicantscontainer.title = u'This is a trans container'
235        applicantscontainer.application_category = 'no'
236        applicantscontainer.mode = 'create'
237        applicantscontainer.strict_deadline = True
238        delta = datetime.timedelta(days=10)
239        applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
240        applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
241        self.app['applicants']['trans1234'] = applicantscontainer
242        # Add an applicant
243        applicant = createObject('waeup.Applicant')
244        # reg_number is the only field which has to be preset here
245        # because managers are allowed to edit this required field
246        applicant.reg_number = u'12345'
247        self.app['applicants']['trans1234'].addApplicant(applicant)
248        IUserAccount(
249            self.app['applicants']['trans1234'][
250            applicant.application_number]).setPassword('apwd')
251        # Login
252        self.browser.open(self.login_path)
253        self.browser.getControl(
254            name="form.login").value = applicant.applicant_id
255        self.browser.getControl(name="form.password").value = 'apwd'
256        self.browser.getControl("Login").click()
257        self.browser.getLink("Edit").click()
258        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
259        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
260        self.browser.getControl(name="form.nationality").value = ['NG']
261        #self.browser.getControl(name="form.sex").value = ['f']
262        self.browser.getControl(name="form.firstname").value = 'Angela'
263        self.browser.getControl(name="form.lastname").value = 'Merkel'
264        self.browser.getControl(name="form.no_copies").value = ['3']
265        self.browser.getControl(name="form.course_studied").value = ['CERT1']
266        self.browser.getControl(name="form.matric_number").value = '234'
267        self.browser.getControl("Save").click()
268        self.browser.getControl("Add online payment ticket").click()
269        self.assertTrue('Payment ticket created' in self.browser.contents)
270        self.assertTrue('<span>100.0</span>' in self.browser.contents)
271        self.assertEqual(applicant.values()[0].amount_auth, 100.0)
272        return
273
274    def test_view_course_admitted(self):
275        self.applicant.course_admitted = self.certificate
276        self.login()
277        self.assertFalse('Admitted Course of Study' in self.browser.contents)
278        return
Note: See TracBrowser for help on using the repository browser.