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

Last change on this file since 17497 was 16728, checked in by Henrik Bettermann, 3 years ago

Add student_id field.

  • Property svn:keywords set to Id
File size: 14.0 KB
Line 
1## $Id: test_browser.py 16728 2021-12-01 13:12:34Z 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.student_id").value = 'X8888'
212        self.browser.getControl(name="form.certificate").value = ['CERT1']
213        #self.browser.getControl(name="form.carryover_courses_1").value = 'Test Course 1 - TCO1'
214        #self.browser.getControl(name="form.carryover_courses_2").value = 'Test Course 2 - TCO2 \nTest Course 3 - TCO3'
215        self.browser.getControl(name="form.grad_year").value = ['2015']
216        self.configuration.carryover4_fee = 5000.0
217        self.browser.getControl("Save").click()
218        self.browser.getControl("Add online payment ticket").click()
219        self.assertMatches('...Payment ticket created...',
220                           self.browser.contents)
221        self.assertTrue(
222            '<span>4 Carry-Over Courses</span>' in self.browser.contents)
223        self.assertTrue(
224            'This is a special app container' in self.browser.contents)
225        self.assertTrue(
226            '<span>5000.0</span>' in self.browser.contents)
227        self.assertEqual(len(self.special_applicant.keys()), 1)
228        payment_id = self.special_applicant.keys()[0]
229        # The applicant's workflow state is paid ...
230        self.special_applicant.payments[0].approveApplicantPayment()
231        self.assertEqual(self.special_applicant.state, 'paid')
232        self.browser.open(applicant_path + '/edit')
233        self.browser.getControl("Finally Submit").click()
234        self.browser.open(applicant_path + '/' + payment_id)
235        self.browser.getLink("Download payment slip").click()
236        self.assertEqual(self.browser.headers['Content-Type'],
237                 'application/pdf')
238        path = os.path.join(samples_dir(), 'special_payment_slip.pdf')
239        open(path, 'wb').write(self.browser.contents)
240        print "Sample PDF clearance_slip.pdf written to %s" % path
241        self.browser.open(applicant_path)
242        self.browser.getLink("Download application slip").click()
243        path = os.path.join(samples_dir(), 'application_slip.pdf')
244        open(path, 'wb').write(self.browser.contents)
245        print "Sample application_slip.pdf written to %s" % path
246
247class ApplicantExporterTest(ApplicantImportExportSetup):
248
249    layer = FunctionalLayer
250
251    def setUp(self):
252        super(ApplicantExporterTest, self).setUp()
253        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
254        self.cat = getUtility(ICatalog, name='applicants_catalog')
255        self.intids = getUtility(IIntIds)
256        return
257
258    def setup_applicant(self, applicant):
259        # set predictable values for `applicant`
260        applicant.reg_number = u'123456'
261        applicant.applicant_id = u'dp2011_654321'
262        applicant.firstname = u'Anna'
263        applicant.lastname = u'Tester'
264        applicant.middlename = u'M.'
265        applicant.nationality = u'NG'
266        applicant.date_of_birth = datetime.date(1981, 2, 4)
267        applicant.sex = 'f'
268        applicant.email = 'anna@sample.com'
269        applicant.phone = u'+234-123-12345'
270        applicant.course1 = self.certificate
271        applicant.course2 = self.certificate
272        applicant.course_admitted = self.certificate
273        applicant.notice = u'Some notice\nin lines.'
274        applicant.screening_score = 98
275        applicant.screening_venue = u'Exam Room'
276        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
277        applicant.password = 'any password'
278        return applicant
279
280class ApplicantsContainerUITests(ApplicantsFullSetup):
281    # Tests for ApplicantsContainer class views and pages
282
283    layer = FunctionalLayer
284
285    def test_application_slip(self):
286        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
287        self.slip_path = self.view_path + '/application_slip.pdf'
288        self.browser.open(self.manage_path)
289        self.assertEqual(self.browser.headers['Status'], '200 Ok')
290        self.fill_correct_values()
291        self.browser.getControl("Save").click()
292        IWorkflowState(self.applicant).setState('submitted')
293        self.browser.open(self.view_path)
294        self.browser.getLink("Download application slip").click()
295        self.assertEqual(self.browser.headers['Status'], '200 Ok')
296        self.assertEqual(self.browser.headers['Content-Type'],
297                         'application/pdf')
298        path = os.path.join(samples_dir(), 'application_slip.pdf')
299        open(path, 'wb').write(self.browser.contents)
300        print "Sample application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.