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

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

Add more fields to ICustomUGApplicant.

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