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

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

Change logo.

  • Property svn:keywords set to Id
File size: 9.2 KB
Line 
1## $Id: test_browser.py 14887 2017-11-01 13:31:54Z 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.testing import FunctionalTestCase
38from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
39from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
40from waeup.kofa.applicants.container import ApplicantsContainer
41
42session = datetime.datetime.now().year - 2
43ndftcontainer_name = u'ndft%s' % session
44
45class ApplicantUITest(FunctionalTestCase):
46    """Perform some browser tests.
47    """
48    layer = FunctionalLayer
49
50    def setUp(self):
51        super(ApplicantUITest, self).setUp()
52        # Setup a sample site for each test
53        app = University()
54        self.dc_root = tempfile.mkdtemp()
55        app['datacenter'].setStoragePath(self.dc_root)
56
57        # Prepopulate the ZODB...
58        self.getRootFolder()['app'] = app
59        # we add the site immediately after creation to the
60        # ZODB. Catalogs and other local utilities are not setup
61        # before that step.
62        self.app = self.getRootFolder()['app']
63        # Set site here. Some of the following setup code might need
64        # to access grok.getSite() and should get our new app then
65        setSite(app)
66
67        # Add ndft applicants container
68        self.ndftcontainer = ApplicantsContainer()
69        self.ndftcontainer.mode = 'create'
70        self.ndftcontainer.code = ndftcontainer_name
71        self.ndftcontainer.prefix = u'ndft'
72        self.ndftcontainer.application_category = u'ndft'
73        self.ndftcontainer.year = session
74        self.ndftcontainer.application_fee = 300.0
75        #self.ndftcontainer.title = u'This is the %s container' % ndftcontainer_name
76        self.app['applicants'][ndftcontainer_name] = self.ndftcontainer
77
78        delta = datetime.timedelta(days=10)
79        self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
80        self.ndftcontainer.enddate = datetime.datetime.now(pytz.utc) + delta
81
82        # Populate university
83        self.certificate = createObject('waeup.Certificate')
84        self.certificate.code = 'CERT1'
85        self.certificate.application_category = 'ndft'
86        self.certificate.start_level = 100
87        self.certificate.end_level = 500
88        self.certificate.study_mode = u'nce_ft'
89        self.app['faculties']['fac1'] = Faculty()
90        self.app['faculties']['fac1']['dep1'] = Department()
91        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
92            self.certificate)
93
94        # Add (customized) applicants
95        ndftapplicant = createObject(u'waeup.Applicant')
96        ndftapplicant.firstname = u'Anna'
97        ndftapplicant.lastname = u'Post'
98        self.app['applicants'][ndftcontainer_name].addApplicant(ndftapplicant)
99        self.ndftapplication_number = ndftapplicant.application_number
100        self.ndftapplicant = self.app['applicants'][ndftcontainer_name][
101            self.ndftapplication_number]
102        self.ndftapplicant_path = ('http://localhost/app/applicants/%s/%s'
103            % (ndftcontainer_name, self.ndftapplication_number))
104
105        self.browser = Browser()
106        self.browser.handleErrors = False
107
108    def tearDown(self):
109        super(ApplicantUITest, self).tearDown()
110        shutil.rmtree(self.dc_root)
111        clearSite()
112        return
113
114    def fill_correct_values(self):
115        self.browser.getControl(name="form.reg_number").value = '1234'
116        self.browser.getControl(name="form.firstname").value = 'John'
117        self.browser.getControl(name="form.lastname").value = 'Tester'
118        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
119        self.browser.getControl(name="form.lga").value = ['foreigner']
120        #self.browser.getControl(name="form.nationality").value = ['NG']
121        #self.browser.getControl(name="form.sex").value = ['m']
122        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
123
124    def test_manage_and_view_applicant(self):
125        # Managers can manage ndft applicants.
126        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
127        self.browser.open(self.ndftapplicant_path)
128        self.assertEqual(self.browser.headers['Status'], '200 Ok')
129        self.assertTrue("'O' Level" in self.browser.contents)
130        self.assertFalse("Higher" in self.browser.contents)
131        self.browser.open(self.ndftapplicant_path + '/manage')
132        self.assertEqual(self.browser.headers['Status'], '200 Ok')
133        self.assertTrue("'O' Level" in self.browser.contents)
134        self.assertTrue("Higher" in self.browser.contents)
135        self.browser.open(self.ndftapplicant_path + '/edit')
136        self.assertEqual(self.browser.headers['Status'], '200 Ok')
137        self.assertTrue("'O' Level" in self.browser.contents)
138        self.assertFalse("Higher" in self.browser.contents)
139        self.browser.open(self.ndftapplicant_path + '/application_slip.pdf')
140        self.assertEqual(self.browser.headers['Status'], '200 Ok')
141        # Now we turn the ndft applicant into an hndft applicant.
142        self.ndftapplicant.applicant_id = u'hndft_anything'
143        self.browser.open(self.ndftapplicant_path)
144        self.assertTrue("Higher" in self.browser.contents)
145        self.assertTrue("'O' Level" in self.browser.contents)
146        self.browser.open(self.ndftapplicant_path + '/edit')
147        self.assertTrue("Higher" in self.browser.contents)
148        self.assertTrue("'O' Level" in self.browser.contents)
149
150        self.browser.open(self.ndftapplicant_path + '/manage')
151        # Manager can fill and save the form
152        self.fill_correct_values()
153        self.browser.getControl("Save").click()
154        self.assertMatches('...Form has been saved...', self.browser.contents)
155        return
156
157class ApplicantExporterTest(ApplicantImportExportSetup):
158
159    layer = FunctionalLayer
160
161    def setUp(self):
162        super(ApplicantExporterTest, self).setUp()
163        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
164        self.cat = getUtility(ICatalog, name='applicants_catalog')
165        self.intids = getUtility(IIntIds)
166        return
167
168    def setup_applicant(self, applicant):
169        # set predictable values for `applicant`
170        applicant.reg_number = u'123456'
171        applicant.applicant_id = u'dp2011_654321'
172        applicant.firstname = u'Anna'
173        applicant.lastname = u'Tester'
174        applicant.middlename = u'M.'
175        applicant.nationality = u'NG'
176        applicant.date_of_birth = datetime.date(1981, 2, 4)
177        applicant.sex = 'f'
178        applicant.email = 'anna@sample.com'
179        applicant.phone = u'+234-123-12345'
180        applicant.course1 = self.certificate
181        applicant.course2 = self.certificate
182        applicant.course_admitted = self.certificate
183        applicant.notice = u'Some notice\nin lines.'
184        applicant.screening_score = 98
185        applicant.screening_venue = u'Exam Room'
186        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
187        applicant.password = 'any password'
188        return applicant
189
190class ApplicantsContainerUITests(ApplicantsFullSetup):
191    # Tests for ApplicantsContainer class views and pages
192
193    layer = FunctionalLayer
194
195    def test_application_slip(self):
196        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
197        self.slip_path = self.view_path + '/application_slip.pdf'
198        self.browser.open(self.manage_path)
199        self.assertEqual(self.browser.headers['Status'], '200 Ok')
200        self.fill_correct_values()
201        self.browser.getControl("Save").click()
202        IWorkflowState(self.applicant).setState('submitted')
203        self.browser.open(self.manage_path)
204        self.browser.getLink("Download application slip").click()
205        self.assertEqual(self.browser.headers['Status'], '200 Ok')
206        self.assertEqual(self.browser.headers['Content-Type'],
207                         'application/pdf')
208        path = os.path.join(samples_dir(), 'application_slip.pdf')
209        open(path, 'wb').write(self.browser.contents)
210        print "Sample application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.