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

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

Adjust exporter and fix tests.

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