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

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

Deduct Interswitch surcharge.

  • Property svn:keywords set to Id
File size: 12.6 KB
Line 
1## $Id: test_browser.py 14308 2016-12-04 16:58:28Z 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 test_certificate_request_manage(self):
146        # Add cert applicants container
147        self.certcontainer = ApplicantsContainer()
148        self.certcontainer.mode = 'create'
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        self.app['applicants'][self.certcontainer.code].addApplicant(certapplicant)
164        self.certapplication_number = certapplicant.application_number
165        self.certapplicant = self.app['applicants'][self.certcontainer.code][
166            self.certapplication_number]
167        self.certapplicant_path = ('http://localhost/app/applicants/cert%s/%s'
168            % (session_1, self.certapplication_number))
169        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
170        self.browser.open(self.certapplicant_path)
171        self.assertEqual(self.browser.headers['Status'], '200 Ok')
172        self.assertTrue("Dispatch Address" in self.browser.contents)
173
174    def test_pg_application_manage(self):
175        # Add pg applicants container
176        self.pgcontainer = ApplicantsContainer()
177        self.pgcontainer.mode = 'create'
178        self.pgcontainer.code = u'pgft%s' % session_1
179        self.pgcontainer.prefix = u'pgft'
180        self.pgcontainer.application_category = u'no'
181        self.pgcontainer.year = session_1
182        self.pgcontainer.application_fee = 300.0
183        self.pgcontainer.title = u'This is the pgft%s container' % session_1
184        self.app['applicants'][self.pgcontainer.code] = self.pgcontainer
185        delta = datetime.timedelta(days=10)
186        self.pgcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
187        self.pgcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
188        # Add applicant
189        pgapplicant = createObject(u'waeup.Applicant')
190        pgapplicant.firstname = u'Anna'
191        pgapplicant.lastname = u'Post'
192        self.app['applicants'][self.pgcontainer.code].addApplicant(pgapplicant)
193        self.pgapplication_number = pgapplicant.application_number
194        self.pgapplicant = self.app['applicants'][self.pgcontainer.code][
195            self.pgapplication_number]
196        self.pgapplicant_path = ('http://localhost/app/applicants/pgft%s/%s'
197            % (session_1, self.pgapplication_number))
198        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
199        self.browser.open(self.pgapplicant_path)
200        self.assertEqual(self.browser.headers['Status'], '200 Ok')
201        self.assertTrue("3rd Higher Education Record" in self.browser.contents)
202
203    def test_transcript_payment(self):
204        configuration = SessionConfiguration()
205        configuration.academic_session = session_1
206        self.app['configuration'].addSessionConfiguration(configuration)
207        # Add special application container
208        applicantscontainer = ApplicantsContainer()
209        applicantscontainer.year = session_1
210        applicantscontainer.application_fee = 200.0
211        applicantscontainer.code = u'trans1234'
212        applicantscontainer.prefix = 'trans'
213        applicantscontainer.title = u'This is a trans container'
214        applicantscontainer.application_category = 'no'
215        applicantscontainer.mode = 'create'
216        applicantscontainer.strict_deadline = True
217        delta = datetime.timedelta(days=10)
218        applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
219        applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
220        self.app['applicants']['trans1234'] = applicantscontainer
221        # Add an applicant
222        applicant = createObject('waeup.Applicant')
223        # reg_number is the only field which has to be preset here
224        # because managers are allowed to edit this required field
225        applicant.reg_number = u'12345'
226        self.app['applicants']['trans1234'].addApplicant(applicant)
227        IUserAccount(
228            self.app['applicants']['trans1234'][
229            applicant.application_number]).setPassword('apwd')
230        # Login
231        self.browser.open(self.login_path)
232        self.browser.getControl(
233            name="form.login").value = applicant.applicant_id
234        self.browser.getControl(name="form.password").value = 'apwd'
235        self.browser.getControl("Login").click()
236        self.browser.getLink("Edit").click()
237        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
238        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
239        self.browser.getControl(name="form.nationality").value = ['NG']
240        #self.browser.getControl(name="form.sex").value = ['f']
241        self.browser.getControl(name="form.firstname").value = 'Angela'
242        self.browser.getControl(name="form.lastname").value = 'Merkel'
243        self.browser.getControl(name="form.no_copies").value = ['3']
244        self.browser.getControl("Save").click()
245        self.browser.getControl("Add online payment ticket").click()
246        self.assertTrue('Payment ticket created' in self.browser.contents)
247        self.assertTrue('<span>100.0</span>' in self.browser.contents)
248        self.assertEqual(applicant.values()[0].amount_auth, 100.0)
249        return
Note: See TracBrowser for help on using the repository browser.