source: main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/applicants/tests/test_browser.py @ 16276

Last change on this file since 16276 was 16233, checked in by Henrik Bettermann, 4 years ago

Implement PG schoolfee payments.

Show provider_amt in payment ticket pages.

  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1## $Id: test_browser.py 16233 2020-09-10 09:33:13Z 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 grok
22import datetime
23import pytz
24import os
25from StringIO import StringIO
26from zope.event import notify
27from zope.component import createObject, getUtility
28from zope.catalog.interfaces import ICatalog
29from zope.intid.interfaces import IIntIds
30from hurry.workflow.interfaces import IWorkflowState
31from zope.component import createObject, getUtility
32from waeup.kofa.configuration import SessionConfiguration
33from waeup.kofa.interfaces import (
34    IUserAccount, IExtFileStore, IFileStoreNameChooser)
35from kofacustom.iuokada.testing import FunctionalLayer
36from waeup.kofa.applicants.container import ApplicantsContainer
37from waeup.kofa.browser.tests.test_pdf import samples_dir
38from waeup.kofa.applicants.tests.test_browser import (ApplicantsFullSetup,
39    ApplicantsFullSetup, container_name_1, session_1)
40from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
41from kofacustom.iuokada.applicants.export import CustomApplicantExporter
42from kofacustom.iuokada.applicants.batching import CustomApplicantProcessor
43
44class CustomApplicantUITests(ApplicantsFullSetup):
45    # Tests for uploading/browsing the passport image of appplicants
46
47    layer = FunctionalLayer
48
49class ApplicantExporterTest(ApplicantImportExportSetup):
50
51    layer = FunctionalLayer
52
53    def setUp(self):
54        super(ApplicantExporterTest, self).setUp()
55        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
56        self.cat = getUtility(ICatalog, name='applicants_catalog')
57        self.intids = getUtility(IIntIds)
58        return
59
60    def setup_applicant(self, applicant):
61        # set predictable values for `applicant`
62        applicant.reg_number = u'123456'
63        applicant.applicant_id = u'dp2011_654321'
64        applicant.firstname = u'Anna'
65        applicant.lastname = u'Tester'
66        applicant.middlename = u'M.'
67        applicant.nationality = u'NG'
68        applicant.date_of_birth = datetime.date(1981, 2, 4)
69        applicant.sex = 'f'
70        applicant.email = 'anna@sample.com'
71        applicant.phone = u'+234-123-12345'
72        applicant.course1 = self.certificate
73        applicant.course2 = self.certificate
74        applicant.course_admitted = self.certificate
75        applicant.notice = u'Some notice\nin lines.'
76        applicant.screening_score = 98
77        applicant.screening_venue = u'Exam Room'
78        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
79        applicant.password = 'any password'
80        return applicant
81
82class ApplicantsContainerUITests(ApplicantsFullSetup):
83    # Tests for ApplicantsContainer class views and pages
84
85    layer = FunctionalLayer
86
87    def fill_correct_values(self):
88        # Fill the edit form with suitable values
89        self.browser.getControl(name="form.firstname").value = 'John'
90        self.browser.getControl(name="form.middlename").value = 'Anthony'
91        self.browser.getControl(name="form.lastname").value = 'Tester'
92        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
93        self.browser.getControl(name="form.sex").value = ['m']
94        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
95
96    def test_manage_application(self):
97        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
98        self.slip_path = self.view_path + '/application_slip.pdf'
99        self.browser.open(self.manage_path)
100        self.assertEqual(self.browser.headers['Status'], '200 Ok')
101        self.fill_correct_values()
102        self.browser.getControl(name="custom.course1").value = ['']
103        self.browser.getControl("Save").click()
104        self.assertTrue('Please select your 1st Choice Course of Study.'
105            in self.browser.contents)
106        self.browser.getControl(name="custom.course1").value = ['CERT1']
107        self.browser.getControl("Save").click()
108        self.assertEqual(self.applicant.course1, self.certificate)
109        self.assertEqual(self.applicant.course2, None)
110        IWorkflowState(self.applicant).setState('submitted')
111        self.browser.open(self.view_path)
112        self.browser.getLink("Download application slip").click()
113        self.assertEqual(self.browser.headers['Status'], '200 Ok')
114        self.assertEqual(self.browser.headers['Content-Type'],
115                         'application/pdf')
116        path = os.path.join(samples_dir(), 'application_slip.pdf')
117        open(path, 'wb').write(self.browser.contents)
118        print "Sample application_slip.pdf written to %s" % path
119        # Log entries have been added (course1 is missing because it was already stored)
120        logfile = os.path.join(
121            self.app['datacenter'].storage, 'logs', 'applicants.log')
122        logcontent = open(logfile).read()
123        self.assertTrue(
124            'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage - '
125            '%s - saved: firstname + middlename + lastname + date_of_birth '
126            '+ sex + email'
127            % (self.applicant.applicant_id)
128            in logcontent)
129
130    def test_upload_res_stat_by_manager(self):
131        # Add trans applicants container
132        self.transcontainer = ApplicantsContainer()
133        self.transcontainer.mode = 'create'
134        self.transcontainer.code = u'ug%s' % session_1
135        self.transcontainer.prefix = u'ug'
136        self.transcontainer.application_category = u'no'
137        self.transcontainer.year = session_1
138        self.transcontainer.application_fee = 300.0
139        self.transcontainer.title = u'This is the ug%s container' % session_1
140        self.app['applicants'][self.transcontainer.code] = self.transcontainer
141        delta = datetime.timedelta(days=10)
142        self.transcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
143        self.transcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
144        # Add applicant
145        transapplicant = createObject(u'waeup.Applicant')
146        transapplicant.firstname = u'Anna'
147        transapplicant.lastname = u'Post'
148        transapplicant.subtype = 'transfer'
149        self.app['applicants'][self.transcontainer.code].addApplicant(transapplicant)
150        self.transapplicant = self.app['applicants'][self.transcontainer.code][
151            transapplicant.application_number]
152        self.transapplicant_view_path = ('http://localhost/app/applicants/ug%s/%s'
153            % (session_1, transapplicant.application_number))
154        self.transapplicant_manage_path = ('http://localhost/app/applicants/ug%s/%s/manage'
155            % (session_1, transapplicant.application_number))
156        # Login
157        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
158        self.browser.open(self.transapplicant_manage_path)
159        # Create a pseudo file with acceptable size
160        pdf_content = 'A' * 1024 * 300  # A string of 300 KB size
161        pseudo_pdf = StringIO(pdf_content)
162        ctrl = self.browser.getControl(name='res_stat.pdf')
163        file_ctrl = ctrl.mech_control
164        file_ctrl.add_file(pseudo_pdf, filename='myform.pdf')
165        self.browser.getControl("Save").click() # submit form
166        # Even though the form could not be saved ...
167        self.assertTrue('Required input is missing' in self.browser.contents)
168        # ... the file has been successfully uploaded
169        pdf_url = self.transapplicant_manage_path.replace('manage', 'res_stat.pdf')
170        self.browser.open(pdf_url)
171        self.assertEqual(
172            self.browser.headers['content-type'], 'application/pdf')
173        self.assertEqual(len(self.browser.contents), 307200)
174        # There is really a file stored for the applicant
175        storage = getUtility(IExtFileStore)
176        file_id = IFileStoreNameChooser(self.transapplicant).chooseName(
177            attr='res_stat.pdf')
178        # The stored file can be fetched
179        fd = storage.getFile(file_id)
180        file_len = len(fd.read())
181        self.assertEqual(file_len, 307200)
182        # A file link is displayed on the edit view ...
183        self.browser.open(self.transapplicant_manage_path)
184        self.assertTrue('<a href="res_stat.pdf">' in self.browser.contents)
185        # ... and on the dislay view
186        self.browser.open(self.transapplicant_view_path)
187        self.assertTrue('res_stat.pdf">Statement of Result</a>'
188            in self.browser.contents)
189        # Adding file is properly logged
190        logfile = os.path.join(
191            self.app['datacenter'].storage, 'logs', 'applicants.log')
192        logcontent = open(logfile).read()
193        self.assertTrue(
194            'zope.mgr - kofacustom.iuokada.applicants.browser.CustomApplicantManageFormPage'
195            ' - %s - saved: res_stat.pdf'
196            % (self.transapplicant.applicant_id)
197            in logcontent)
198        # When an applicant is removed, also the pdf files are gone.
199        del self.app['applicants'][self.transcontainer.code][self.transapplicant.application_number]
200        fd = storage.getFile(file_id)
201        self.assertTrue(fd is None)
Note: See TracBrowser for help on using the repository browser.