source: main/waeup.fceokene/trunk/src/waeup/fceokene/applicants/tests/test_browser.py @ 16541

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

If applicants haven't saved the form before submission (which is allowed), the attribute was not set and wasn't counted. This use case was not covered by the test.

  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1## $Id: test_browser.py 15635 2019-10-03 20:47:58Z henrik $
2##
3## Copyright (C) 2011 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##
18import shutil
19import tempfile
20import datetime
21import pytz
22import os
23from zope.component.hooks import setSite, clearSite
24from zope.component import createObject
25from zope.testbrowser.testing import Browser
26from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
27from waeup.kofa.app import University
28from waeup.kofa.university.faculty import Faculty
29from waeup.kofa.university.department import Department
30from waeup.kofa.testing import FunctionalTestCase
31from waeup.kofa.interfaces import (
32    IExtFileStore, IFileStoreNameChooser, IUserAccount, IJobManager)
33from waeup.kofa.applicants.container import ApplicantsContainer
34from waeup.fceokene.testing import FunctionalLayer
35
36session = datetime.datetime.now().year - 2
37SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
38
39class ApplicantUITest(FunctionalTestCase):
40    """Perform some browser tests.
41    """
42    layer = FunctionalLayer
43
44    def setUp(self):
45        super(ApplicantUITest, self).setUp()
46        # Setup a sample site for each test
47        app = University()
48        self.dc_root = tempfile.mkdtemp()
49        app['datacenter'].setStoragePath(self.dc_root)
50
51        # Prepopulate the ZODB...
52        self.getRootFolder()['app'] = app
53        # we add the site immediately after creation to the
54        # ZODB. Catalogs and other local utilities are not setup
55        # before that step.
56        self.app = self.getRootFolder()['app']
57        # Set site here. Some of the following setup code might need
58        # to access grok.getSite() and should get our new app then
59        setSite(app)
60
61        self.login_path = 'http://localhost/app/login'
62
63        # Add bec applicants container
64        self.beccontainer = ApplicantsContainer()
65        self.beccontainer.mode = 'create'
66        self.beccontainer.code = u'bec%s' % session
67        self.beccontainer.prefix = u'bec'
68        self.beccontainer.application_category = u'bec'
69        self.beccontainer.year = session
70        self.beccontainer.application_fee = 300.0
71        self.beccontainer.title = u'This is the bec%s container' % session
72        self.app['applicants'][self.beccontainer.code] = self.beccontainer
73        delta = datetime.timedelta(days=10)
74        self.beccontainer.startdate = datetime.datetime.now(pytz.utc) - delta
75        self.beccontainer.enddate = datetime.datetime.now(pytz.utc) + delta
76
77        # Add ug applicants container
78        self.putmecontainer = ApplicantsContainer()
79        self.putmecontainer.mode = 'create'
80        self.putmecontainer.code = u'putme%s' % session
81        self.putmecontainer.prefix = u'putme'
82        self.putmecontainer.application_category = u'bec' # doesn't matter
83        self.putmecontainer.year = session
84        self.putmecontainer.application_fee = 300.0
85        self.putmecontainer.title = u'This is the putme%s container' % session
86        self.app['applicants'][self.putmecontainer.code] = self.putmecontainer
87        delta = datetime.timedelta(days=10)
88        self.putmecontainer.startdate = datetime.datetime.now(pytz.utc) - delta
89        self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta
90
91        # Add tpu applicants container
92        self.tpucontainer = ApplicantsContainer()
93        self.tpucontainer.mode = 'create'
94        self.tpucontainer.code = u'tpu%s' % session
95        self.tpucontainer.prefix = u'tpu'
96        self.tpucontainer.application_category = u'no'
97        self.tpucontainer.year = session
98        self.tpucontainer.application_fee = 300.0
99        self.tpucontainer.title = u'This is the tpu%s container' % session
100        self.app['applicants'][self.tpucontainer.code] = self.tpucontainer
101        delta = datetime.timedelta(days=10)
102        self.tpucontainer.startdate = datetime.datetime.now(pytz.utc) - delta
103        self.tpucontainer.enddate = datetime.datetime.now(pytz.utc) + delta
104
105        # Populate university
106        self.certificate = createObject('waeup.Certificate')
107        self.certificate.code = 'CERT1'
108        self.certificate.application_category = 'bec'
109        self.certificate.start_level = 100
110        self.certificate.end_level = 500
111        self.certificate.study_mode = u'nce_ft'
112        self.app['faculties']['fac1'] = Faculty()
113        self.app['faculties']['fac1']['dep1'] = Department()
114        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
115            self.certificate)
116
117        # Add (customized) applicants
118        becapplicant = createObject(u'waeup.Applicant')
119        becapplicant.firstname = u'Anna'
120        becapplicant.lastname = u'Post'
121        self.app['applicants'][self.beccontainer.code].addApplicant(becapplicant)
122        self.becapplication_number = becapplicant.application_number
123        self.becapplicant = self.app['applicants'][self.beccontainer.code][
124            self.becapplication_number]
125        self.becapplicant_path = ('http://localhost/app/applicants/bec%s/%s'
126            % (session, self.becapplication_number))
127
128        putmeapplicant = createObject(u'waeup.Applicant')
129        putmeapplicant.firstname = u'Anna'
130        putmeapplicant.lastname = u'Post'
131        self.app['applicants'][self.putmecontainer.code].addApplicant(putmeapplicant)
132        self.putmeapplication_number = putmeapplicant.application_number
133        self.putmeapplicant = self.app['applicants'][self.putmecontainer.code][
134            self.putmeapplication_number]
135        self.putmeapplicant_path = ('http://localhost/app/applicants/putme%s/%s'
136            % (session, self.putmeapplication_number))
137
138        tpuapplicant = createObject(u'waeup.Applicant')
139        tpuapplicant.firstname = u'Michelle'
140        tpuapplicant.lastname = u'Obama'
141        self.app['applicants'][self.tpucontainer.code].addApplicant(tpuapplicant)
142        self.tpuapplication_number = tpuapplicant.application_number
143        self.tpuapplicant = self.app['applicants'][self.tpucontainer.code][
144            self.tpuapplication_number]
145        self.tpuapplicant_path = ('http://localhost/app/applicants/tpu%s/%s'
146            % (session, self.tpuapplication_number))
147        IUserAccount(
148            self.app['applicants'][self.tpucontainer.code][
149            self.tpuapplicant.application_number]).setPassword('apwd')
150
151        self.browser = Browser()
152        self.browser.handleErrors = False
153
154    def tearDown(self):
155        super(ApplicantUITest, self).tearDown()
156        shutil.rmtree(self.dc_root)
157        clearSite()
158        return
159
160    def test_manage_and_view_bec_applicant(self):
161        # Managers can manage bec applicants.
162        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
163        self.browser.open(self.becapplicant_path)
164        self.assertEqual(self.browser.headers['Status'], '200 Ok')
165        self.assertTrue("'O' Level" in self.browser.contents)
166        self.browser.open(self.becapplicant_path + '/manage')
167        self.assertEqual(self.browser.headers['Status'], '200 Ok')
168        self.assertTrue("'O' Level" in self.browser.contents)
169        self.browser.open(self.becapplicant_path + '/edit')
170        self.assertEqual(self.browser.headers['Status'], '200 Ok')
171        self.assertTrue("'O' Level" in self.browser.contents)
172        self.browser.open(self.becapplicant_path + '/application_slip.pdf')
173        self.assertEqual(self.browser.headers['Status'], '200 Ok')
174        return
175
176    def test_manage_and_view_putme_applicant(self):
177        # Managers can manage bec applicants.
178        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
179        self.browser.open(self.putmeapplicant_path)
180        self.assertEqual(self.browser.headers['Status'], '200 Ok')
181        self.assertTrue("'O' Level" in self.browser.contents)
182        self.browser.open(self.putmeapplicant_path + '/manage')
183        self.assertEqual(self.browser.headers['Status'], '200 Ok')
184        self.assertTrue("'O' Level" in self.browser.contents)
185        self.browser.open(self.putmeapplicant_path + '/edit')
186        self.assertEqual(self.browser.headers['Status'], '200 Ok')
187        self.assertTrue("'O' Level" in self.browser.contents)
188        self.browser.open(self.putmeapplicant_path + '/application_slip.pdf')
189        self.assertEqual(self.browser.headers['Status'], '200 Ok')
190       
191    def test_final_submit_tpu(self):
192        IWorkflowState(self.tpuapplicant).setState('paid')
193        self.browser.open(self.login_path)
194        self.browser.getControl(
195            name="form.login").value = self.tpuapplicant.applicant_id
196        self.browser.getControl(name="form.password").value = 'apwd'
197        self.browser.getControl("Login").click()
198        self.browser.open(self.tpuapplicant_path + '/edit')
199        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
200        self.browser.getControl(name="form.school1").value = ['s0010']
201        image = open(SAMPLE_IMAGE, 'rb')
202        ctrl = self.browser.getControl(name='form.passport')
203        file_ctrl = ctrl.mech_control
204        file_ctrl.add_file(image, filename='myphoto.jpg')
205        self.browser.getControl(name="confirm_passport").value = True
206        self.browser.getControl("Save").click()
207        self.browser.getControl("Finally Submit").click()
208        self.assertTrue(
209            'Application submitted' in self.browser.contents)
210        # Create 10 applicants who already selected s0010
211        for i in range(1,11):
212            dummy = createObject(u'waeup.Applicant')
213            dummy.firstname = u'John'
214            dummy.lastname = u'Doe %s' %i
215            dummy.school1 = 's0010'
216            self.app['applicants'][
217                self.tpucontainer.code].addApplicant(dummy)
218            IWorkflowState(dummy).setState('submitted')
219        IWorkflowState(self.tpuapplicant).setState('paid')
220        self.tpuapplicant.school1 = None
221        self.tpuapplicant.locked = False
222        self.browser.open(self.tpuapplicant_path + '/edit')
223        self.browser.getControl(name="form.school1").value = ['s0010']
224        self.browser.getControl("Finally Submit").click()
225        self.assertTrue("Maximum number of applications per school exceeded."
226            in self.browser.contents)
227        self.assertEqual(self.tpuapplicant.state, 'paid')
228        return
229
Note: See TracBrowser for help on using the repository browser.