source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/applicants/tests/test_browser.py @ 16281

Last change on this file since 16281 was 15592, checked in by Henrik Bettermann, 5 years ago

Change remedial payment form.

  • Property svn:keywords set to Id
File size: 13.9 KB
Line 
1## $Id: test_browser.py 15592 2019-09-18 16:51:44Z henrik $
2##
3## Copyright (C) 2013 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"""
19Test the applicant-related UI components.
20"""
21import shutil
22import tempfile
23import datetime
24import pytz
25import os
26from zope.component.hooks import setSite, clearSite
27from zope.component import createObject, getUtility
28from zope.catalog.interfaces import ICatalog
29from zope.intid.interfaces import IIntIds
30from zope.testbrowser.testing import Browser
31from kofacustom.dspg.testing import FunctionalLayer
32from hurry.workflow.interfaces import IWorkflowState
33from waeup.kofa.app import University
34from waeup.kofa.browser.tests.test_pdf import samples_dir
35from waeup.kofa.university.faculty import Faculty
36from waeup.kofa.university.department import Department
37from waeup.kofa.interfaces import IUserAccount
38from waeup.kofa.configuration import SessionConfiguration
39from waeup.kofa.testing import FunctionalTestCase
40from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
41from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
42from waeup.kofa.applicants.container import ApplicantsContainer
43
44session = datetime.datetime.now().year - 2
45ndftcontainer_name = u'ndft%s' % session
46
47class ApplicantUITest(FunctionalTestCase):
48    """Perform some browser tests.
49    """
50    layer = FunctionalLayer
51
52    def setUp(self):
53        super(ApplicantUITest, self).setUp()
54        # Setup a sample site for each test
55        app = University()
56        self.dc_root = tempfile.mkdtemp()
57        app['datacenter'].setStoragePath(self.dc_root)
58
59        # Prepopulate the ZODB...
60        self.getRootFolder()['app'] = app
61        # we add the site immediately after creation to the
62        # ZODB. Catalogs and other local utilities are not setup
63        # before that step.
64        self.app = self.getRootFolder()['app']
65        # Set site here. Some of the following setup code might need
66        # to access grok.getSite() and should get our new app then
67        setSite(app)
68
69        # Add ndft applicants container
70        self.ndftcontainer = ApplicantsContainer()
71        self.ndftcontainer.mode = 'create'
72        self.ndftcontainer.code = ndftcontainer_name
73        self.ndftcontainer.prefix = u'ndft'
74        self.ndftcontainer.application_category = u'ndft'
75        self.ndftcontainer.year = session
76        self.ndftcontainer.application_fee = 300.0
77        #self.ndftcontainer.title = u'This is the %s container' % ndftcontainer_name
78        self.app['applicants'][ndftcontainer_name] = self.ndftcontainer
79
80        self.login_path = 'http://localhost/app/login'
81
82        delta = datetime.timedelta(days=10)
83        self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
84        self.ndftcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
85
86        # Populate university
87        self.certificate = createObject('waeup.Certificate')
88        self.certificate.code = 'CERT1'
89        self.certificate.application_category = 'ndft'
90        self.certificate.start_level = 100
91        self.certificate.end_level = 500
92        self.certificate.study_mode = u'nce_ft'
93        self.app['faculties']['fac1'] = Faculty()
94        self.app['faculties']['fac1']['dep1'] = Department()
95        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
96            self.certificate)
97
98        # Add (customized) applicants
99        ndftapplicant = createObject(u'waeup.Applicant')
100        ndftapplicant.firstname = u'Anna'
101        ndftapplicant.lastname = u'Post'
102        self.app['applicants'][ndftcontainer_name].addApplicant(ndftapplicant)
103        self.ndftapplication_number = ndftapplicant.application_number
104        self.ndftapplicant = self.app['applicants'][ndftcontainer_name][
105            self.ndftapplication_number]
106        self.ndftapplicant_path = ('http://localhost/app/applicants/%s/%s'
107            % (ndftcontainer_name, self.ndftapplication_number))
108
109        self.browser = Browser()
110        self.browser.handleErrors = False
111
112    def tearDown(self):
113        super(ApplicantUITest, self).tearDown()
114        shutil.rmtree(self.dc_root)
115        clearSite()
116        return
117
118    def fill_correct_values(self):
119        self.browser.getControl(name="form.reg_number").value = '1234'
120        self.browser.getControl(name="form.firstname").value = 'John'
121        self.browser.getControl(name="form.lastname").value = 'Tester'
122        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
123        self.browser.getControl(name="form.lga").value = ['foreigner']
124        #self.browser.getControl(name="form.nationality").value = ['NG']
125        #self.browser.getControl(name="form.sex").value = ['m']
126        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
127
128    def prepare_special_container(self):
129        # Add special application container
130        container_name = u'special%s' % session
131        applicantscontainer = ApplicantsContainer()
132        applicantscontainer.code = container_name
133        applicantscontainer.prefix = 'special'
134        applicantscontainer.year = session
135        applicantscontainer.with_picture = False
136        applicantscontainer.title = u'This is a special app container'
137        applicantscontainer.application_category = 'no'
138        applicantscontainer.mode = 'create'
139        applicantscontainer.strict_deadline = True
140        delta = datetime.timedelta(days=10)
141        applicantscontainer.startdate = datetime.datetime.now(pytz.utc) - delta
142        applicantscontainer.enddate = datetime.datetime.now(pytz.utc) + delta
143        self.app['applicants'][container_name] = applicantscontainer
144        # Add an applicant
145        applicant = createObject('waeup.Applicant')
146        # reg_number is the only field which has to be preset here
147        # because managers are allowed to edit this required field
148        applicant.reg_number = u'12345'
149        self.special_applicant = applicant
150        self.app['applicants'][container_name].addApplicant(applicant)
151        IUserAccount(
152            self.app['applicants'][container_name][
153            applicant.application_number]).setPassword('apwd')
154        # Add session configuration object
155        self.configuration = SessionConfiguration()
156        self.configuration.academic_session = session
157        #self.configuration.transcript_fee = 200.0
158        self.configuration.clearance_fee = 300.0
159        self.app['configuration'].addSessionConfiguration(self.configuration)
160
161    def test_manage_and_view_applicant(self):
162        # Managers can manage ndft applicants.
163        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
164        self.browser.open(self.ndftapplicant_path)
165        self.assertEqual(self.browser.headers['Status'], '200 Ok')
166        self.assertTrue("'O' Level" in self.browser.contents)
167        self.assertFalse("Higher" in self.browser.contents)
168        self.browser.open(self.ndftapplicant_path + '/manage')
169        self.assertEqual(self.browser.headers['Status'], '200 Ok')
170        self.assertTrue("'O' Level" in self.browser.contents)
171        self.assertTrue("Higher" in self.browser.contents)
172        self.browser.open(self.ndftapplicant_path + '/edit')
173        self.assertEqual(self.browser.headers['Status'], '200 Ok')
174        self.assertTrue("'O' Level" in self.browser.contents)
175        self.assertFalse("Higher" in self.browser.contents)
176        self.browser.open(self.ndftapplicant_path + '/application_slip.pdf')
177        self.assertEqual(self.browser.headers['Status'], '200 Ok')
178        # Now we turn the ndft applicant into an hndft applicant.
179        self.ndftapplicant.applicant_id = u'hndft_anything'
180        self.browser.open(self.ndftapplicant_path)
181        self.assertTrue("Higher" in self.browser.contents)
182        self.assertTrue("'O' Level" in self.browser.contents)
183        self.browser.open(self.ndftapplicant_path + '/edit')
184        self.assertTrue("Higher" in self.browser.contents)
185        self.assertTrue("'O' Level" in self.browser.contents)
186
187        self.browser.open(self.ndftapplicant_path + '/manage')
188        # Manager can fill and save the form
189        self.fill_correct_values()
190        self.browser.getControl("Save").click()
191        self.assertMatches('...Form has been saved...', self.browser.contents)
192        return
193
194    def test_special_application(self):
195        self.prepare_special_container()
196        # Login
197        self.browser.open(self.login_path)
198        self.browser.getControl(
199            name="form.login").value = self.special_applicant.applicant_id
200        self.browser.getControl(name="form.password").value = 'apwd'
201        self.browser.getControl("Login").click()
202        applicant_path = self.browser.url
203        self.browser.getLink("Edit application record").click()
204        self.browser.getControl(name="form.firstname").value = 'John'
205        self.browser.getControl(name="form.middlename").value = 'Anthony'
206        self.browser.getControl(name="form.lastname").value = 'Tester'
207        self.browser.getControl(name="form.special_application").value = [
208            'carryover4']
209        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
210        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
211        self.browser.getControl(name="form.certificate").value = ['CERT1']
212        self.browser.getControl(name="form.carryover_courses_1").value = 'Test Course 1 - TCO1'
213        self.browser.getControl(name="form.carryover_courses_2").value = 'Test Course 2 - TCO2 \nTest Course 3 - TCO3'
214        self.browser.getControl(name="form.grad_year").value = ['2015']
215        self.configuration.carryover4_fee = 5000.0
216        self.browser.getControl("Save").click()
217        self.browser.getControl("Add online payment ticket").click()
218        self.assertMatches('...Payment ticket created...',
219                           self.browser.contents)
220        self.assertTrue(
221            '<span>4 Carry-Over Courses</span>' in self.browser.contents)
222        self.assertTrue(
223            'This is a special app container' in self.browser.contents)
224        self.assertTrue(
225            '<span>5000.0</span>' in self.browser.contents)
226        self.assertEqual(len(self.special_applicant.keys()), 1)
227        payment_id = self.special_applicant.keys()[0]
228        # The applicant's workflow state is paid ...
229        self.special_applicant.payments[0].approveApplicantPayment()
230        self.assertEqual(self.special_applicant.state, 'paid')
231        self.browser.open(applicant_path + '/edit')
232        self.browser.getControl("Finally Submit").click()
233        self.browser.open(applicant_path + '/' + payment_id)
234        self.browser.getLink("Download payment slip").click()
235        self.assertEqual(self.browser.headers['Content-Type'],
236                 'application/pdf')
237        path = os.path.join(samples_dir(), 'special_payment_slip.pdf')
238        open(path, 'wb').write(self.browser.contents)
239        print "Sample PDF clearance_slip.pdf written to %s" % path
240        self.browser.open(applicant_path)
241        self.browser.getLink("Download application slip").click()
242        path = os.path.join(samples_dir(), 'application_slip.pdf')
243        open(path, 'wb').write(self.browser.contents)
244        print "Sample application_slip.pdf written to %s" % path
245
246class ApplicantExporterTest(ApplicantImportExportSetup):
247
248    layer = FunctionalLayer
249
250    def setUp(self):
251        super(ApplicantExporterTest, self).setUp()
252        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
253        self.cat = getUtility(ICatalog, name='applicants_catalog')
254        self.intids = getUtility(IIntIds)
255        return
256
257    def setup_applicant(self, applicant):
258        # set predictable values for `applicant`
259        applicant.reg_number = u'123456'
260        applicant.applicant_id = u'dp2011_654321'
261        applicant.firstname = u'Anna'
262        applicant.lastname = u'Tester'
263        applicant.middlename = u'M.'
264        applicant.nationality = u'NG'
265        applicant.date_of_birth = datetime.date(1981, 2, 4)
266        applicant.sex = 'f'
267        applicant.email = 'anna@sample.com'
268        applicant.phone = u'+234-123-12345'
269        applicant.course1 = self.certificate
270        applicant.course2 = self.certificate
271        applicant.course_admitted = self.certificate
272        applicant.notice = u'Some notice\nin lines.'
273        applicant.screening_score = 98
274        applicant.screening_venue = u'Exam Room'
275        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
276        applicant.password = 'any password'
277        return applicant
278
279class ApplicantsContainerUITests(ApplicantsFullSetup):
280    # Tests for ApplicantsContainer class views and pages
281
282    layer = FunctionalLayer
283
284    def test_application_slip(self):
285        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
286        self.slip_path = self.view_path + '/application_slip.pdf'
287        self.browser.open(self.manage_path)
288        self.assertEqual(self.browser.headers['Status'], '200 Ok')
289        self.fill_correct_values()
290        self.browser.getControl("Save").click()
291        IWorkflowState(self.applicant).setState('submitted')
292        self.browser.open(self.manage_path)
293        self.browser.getLink("Download application slip").click()
294        self.assertEqual(self.browser.headers['Status'], '200 Ok')
295        self.assertEqual(self.browser.headers['Content-Type'],
296                         'application/pdf')
297        path = os.path.join(samples_dir(), 'application_slip.pdf')
298        open(path, 'wb').write(self.browser.contents)
299        print "Sample application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.