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

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

Use same application module setup as for kwarapoly.

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