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

Last change on this file since 14697 was 14579, checked in by Henrik Bettermann, 8 years ago

Alumni records have to be imported into several containers.
Therefore a string must be added to their registration number
to make it unique.

  • Property svn:keywords set to Id
File size: 13.9 KB
Line 
1## $Id: test_browser.py 14579 2017-02-23 17:57:10Z 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.browser.getLink("screening invitation").click()
90        self.assertEqual(self.browser.headers['Status'], '200 Ok')
91        self.assertEqual(
92            self.browser.headers['Content-Type'], 'application/pdf')
93        path = os.path.join(samples_dir(), 'screening_invitation.pdf')
94        open(path, 'wb').write(self.browser.contents)
95        print "Sample PDF screening_invitation.pdf written to %s" % path
96        return
97
98    def test_application_slips(self):
99        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
100        self.slip_path = self.view_path + '/application_slip.pdf'
101        self.browser.open(self.manage_path)
102        self.assertEqual(self.browser.headers['Status'], '200 Ok')
103        self.fill_correct_values()
104        self.browser.getControl("Save").click()
105        IWorkflowState(self.applicant).setState('admitted')
106        self.applicant.course_admitted = self.certificate
107        self.browser.open(self.manage_path)
108        self.browser.getLink("Download application slip").click()
109        self.assertEqual(self.browser.headers['Status'], '200 Ok')
110        self.assertEqual(self.browser.headers['Content-Type'],
111                         'application/pdf')
112        path = os.path.join(samples_dir(), 'application_slip.pdf')
113        open(path, 'wb').write(self.browser.contents)
114        print "Sample application_slip.pdf written to %s" % path
115
116    def test_transcript_application_manage(self):
117        # Add trans applicants container
118        self.transcontainer = ApplicantsContainer()
119        self.transcontainer.mode = 'create'
120        self.transcontainer.code = u'trans%s' % session_1
121        self.transcontainer.prefix = u'trans'
122        self.transcontainer.application_category = u'no'
123        self.transcontainer.year = session_1
124        self.transcontainer.application_fee = 300.0
125        self.transcontainer.title = u'This is the trans%s container' % session_1
126        self.app['applicants'][self.transcontainer.code] = self.transcontainer
127        delta = datetime.timedelta(days=10)
128        self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
129        self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
130        # Add applicant
131        transapplicant = createObject(u'waeup.Applicant')
132        transapplicant.firstname = u'Anna'
133        transapplicant.lastname = u'Post'
134        self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant)
135        self.transapplication_number = transapplicant.application_number
136        self.transapplicant = self.app['applicants'][self.transcontainer.code][
137            self.transapplication_number]
138        self.transapplicant_path = ('http://localhost/app/applicants/trans%s/%s'
139            % (session_1, self.transapplication_number))
140        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
141        self.browser.open(self.transapplicant_path)
142        self.assertEqual(self.browser.headers['Status'], '200 Ok')
143        self.assertTrue("Dispatch Address" in self.browser.contents)
144
145    def _prepare_cert_container(self):
146        # Add cert applicants container
147        self.certcontainer = ApplicantsContainer()
148        self.certcontainer.mode = 'update'
149        self.certcontainer.code = u'cert%s' % session_1
150        self.certcontainer.prefix = u'cert'
151        self.certcontainer.application_category = u'no'
152        self.certcontainer.year = session_1
153        self.certcontainer.application_fee = 300.0
154        self.certcontainer.title = u'This is the cert%s container' % session_1
155        self.app['applicants'][self.certcontainer.code] = self.certcontainer
156        delta = datetime.timedelta(days=10)
157        self.certcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
158        self.certcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
159        # Add applicant
160        certapplicant = createObject(u'waeup.Applicant')
161        certapplicant.firstname = u'Anna'
162        certapplicant.lastname = u'Post'
163        certapplicant.reg_number = u'1234%s' % self.certcontainer.code
164        self.app['applicants'][self.certcontainer.code].addApplicant(certapplicant)
165        self.certapplication_number = certapplicant.application_number
166        self.certapplicant = self.app['applicants'][self.certcontainer.code][
167            self.certapplication_number]
168        self.certcontainer_path = ('http://localhost/app/applicants/cert%s'
169            % session_1)
170        self.certapplicant_path = ('http://localhost/app/applicants/cert%s/%s'
171            % (session_1, self.certapplication_number))
172
173    def test_certificate_request_manage(self):
174        self._prepare_cert_container()
175        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
176        self.browser.open(self.certapplicant_path)
177        self.assertEqual(self.browser.headers['Status'], '200 Ok')
178        self.assertTrue("Dispatch Address" in self.browser.contents)
179
180    def test_certificate_request_update(self):
181        self._prepare_cert_container()
182        #IWorkflowState(self.applicant).setState('initialized')
183        self.browser.open(self.certcontainer_path + '/register')
184        self.browser.getControl(name="form.lastname").value = 'post'
185        self.browser.getControl(name="form.reg_number").value = '1234'
186        self.browser.getControl(name="form.email").value = 'new@yy.zz'
187        self.browser.getControl("Send login credentials").click()
188        # Yeah, we succeded ...
189        self.assertTrue('Your registration was successful.'
190            in self.browser.contents)
191
192    def test_pg_application_manage(self):
193        # Add pg applicants container
194        self.pgcontainer = ApplicantsContainer()
195        self.pgcontainer.mode = 'create'
196        self.pgcontainer.code = u'pgft%s' % session_1
197        self.pgcontainer.prefix = u'pgft'
198        self.pgcontainer.application_category = u'no'
199        self.pgcontainer.year = session_1
200        self.pgcontainer.application_fee = 300.0
201        self.pgcontainer.title = u'This is the pgft%s container' % session_1
202        self.app['applicants'][self.pgcontainer.code] = self.pgcontainer
203        delta = datetime.timedelta(days=10)
204        self.pgcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
205        self.pgcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
206        # Add applicant
207        pgapplicant = createObject(u'waeup.Applicant')
208        pgapplicant.firstname = u'Anna'
209        pgapplicant.lastname = u'Post'
210        self.app['applicants'][self.pgcontainer.code].addApplicant(pgapplicant)
211        self.pgapplication_number = pgapplicant.application_number
212        self.pgapplicant = self.app['applicants'][self.pgcontainer.code][
213            self.pgapplication_number]
214        self.pgapplicant_path = ('http://localhost/app/applicants/pgft%s/%s'
215            % (session_1, self.pgapplication_number))
216        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
217        self.browser.open(self.pgapplicant_path)
218        self.assertEqual(self.browser.headers['Status'], '200 Ok')
219        self.assertTrue("3rd Higher Education Record" in self.browser.contents)
220
221    def test_transcript_payment(self):
222        configuration = SessionConfiguration()
223        configuration.academic_session = session_1
224        self.app['configuration'].addSessionConfiguration(configuration)
225        # Add special application container
226        applicantscontainer = ApplicantsContainer()
227        applicantscontainer.year = session_1
228        applicantscontainer.application_fee = 200.0
229        applicantscontainer.code = u'trans1234'
230        applicantscontainer.prefix = 'trans'
231        applicantscontainer.title = u'This is a trans container'
232        applicantscontainer.application_category = 'no'
233        applicantscontainer.mode = 'create'
234        applicantscontainer.strict_deadline = True
235        delta = datetime.timedelta(days=10)
236        applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
237        applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
238        self.app['applicants']['trans1234'] = applicantscontainer
239        # Add an applicant
240        applicant = createObject('waeup.Applicant')
241        # reg_number is the only field which has to be preset here
242        # because managers are allowed to edit this required field
243        applicant.reg_number = u'12345'
244        self.app['applicants']['trans1234'].addApplicant(applicant)
245        IUserAccount(
246            self.app['applicants']['trans1234'][
247            applicant.application_number]).setPassword('apwd')
248        # Login
249        self.browser.open(self.login_path)
250        self.browser.getControl(
251            name="form.login").value = applicant.applicant_id
252        self.browser.getControl(name="form.password").value = 'apwd'
253        self.browser.getControl("Login").click()
254        self.browser.getLink("Edit").click()
255        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
256        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
257        self.browser.getControl(name="form.nationality").value = ['NG']
258        #self.browser.getControl(name="form.sex").value = ['f']
259        self.browser.getControl(name="form.firstname").value = 'Angela'
260        self.browser.getControl(name="form.lastname").value = 'Merkel'
261        self.browser.getControl(name="form.no_copies").value = ['3']
262        self.browser.getControl(name="form.course_studied").value = ['CERT1']
263        self.browser.getControl(name="form.matric_number").value = '234'
264        self.browser.getControl("Save").click()
265        self.browser.getControl("Add online payment ticket").click()
266        self.assertTrue('Payment ticket created' in self.browser.contents)
267        self.assertTrue('<span>100.0</span>' in self.browser.contents)
268        self.assertEqual(applicant.values()[0].amount_auth, 100.0)
269        return
270
271    def test_view_course_admitted(self):
272        self.applicant.course_admitted = self.certificate
273        self.login()
274        self.assertFalse('Admitted Course of Study' in self.browser.contents)
275        return
Note: See TracBrowser for help on using the repository browser.