source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/tests.py @ 8055

Last change on this file since 8055 was 8053, checked in by Henrik Bettermann, 13 years ago

Derive IPGApplicant and IUGApplicant from IApplicantBaseData and not from IApplicant. We'll need this for the customized exporter.

  • Property svn:keywords set to Id
File size: 6.6 KB
RevLine 
[7866]1## $Id: tests.py 8053 2012-04-06 16:01:57Z 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 os
19import shutil
20import tempfile
21from zope.interface.verify import verifyClass, verifyObject
22from zope.component.hooks import setSite, clearSite
23from zope.component import createObject
[8012]24from zope.testbrowser.testing import Browser
[7866]25from waeup.kofa.app import University
26from waeup.kofa.university.faculty import Faculty
27from waeup.kofa.university.department import Department
28from waeup.kofa.testing import FunctionalTestCase
[8012]29from waeup.kofa.applicants.container import ApplicantsContainer
[8020]30from waeup.uniben.testing import FunctionalLayer
[7866]31from waeup.kofa.interfaces import IBatchProcessor
32
[8012]33class ApplicantUITest(FunctionalTestCase):
34    """Perform some browser tests.
[7866]35    """
36    layer = FunctionalLayer
37
38    def setUp(self):
[8012]39        super(ApplicantUITest, self).setUp()
[7866]40        # Setup a sample site for each test
41        app = University()
42        self.dc_root = tempfile.mkdtemp()
43        app['datacenter'].setStoragePath(self.dc_root)
44
45        # Prepopulate the ZODB...
46        self.getRootFolder()['app'] = app
47        # we add the site immediately after creation to the
48        # ZODB. Catalogs and other local utilities are not setup
49        # before that step.
50        self.app = self.getRootFolder()['app']
51        # Set site here. Some of the following setup code might need
52        # to access grok.getSite() and should get our new app then
53        setSite(app)
54
[8012]55        # Add an two different applicants containers
56        self.pgcontainer = ApplicantsContainer()
57        self.pgcontainer.code = u'pg2011'
58        self.pgcontainer.prefix = u'pg'
59        self.app['applicants']['pg2011'] = self.pgcontainer
60        self.ugcontainer = ApplicantsContainer()
61        self.ugcontainer.code = u'app2011'
62        self.ugcontainer.prefix = u'app'
63        self.app['applicants']['app2011'] = self.ugcontainer
[7866]64
65        # Populate university
66        self.certificate = createObject('waeup.Certificate')
67        self.certificate.code = 'CERT1'
68        self.certificate.application_category = 'basic'
69        self.certificate.start_level = 100
70        self.certificate.end_level = 500
71        self.app['faculties']['fac1'] = Faculty()
72        self.app['faculties']['fac1']['dep1'] = Department()
73        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
74            self.certificate)
75
[8012]76        # Add (customized) applicants
77        pgapplicant = createObject(u'waeup.Applicant')
78        pgapplicant.firstname = u'Anna'
79        pgapplicant.lastname = u'Post'
80        self.app['applicants']['pg2011'].addApplicant(pgapplicant)
81        self.pgapplication_number = pgapplicant.application_number
82        self.pgapplicant = self.app['applicants']['pg2011'][
83            self.pgapplication_number]
[7866]84
[8012]85        ugapplicant = createObject(u'waeup.Applicant')
86        ugapplicant.firstname = u'Klaus'
87        ugapplicant.lastname = u'Under'
88        self.app['applicants']['app2011'].addApplicant(ugapplicant)
89        self.ugapplication_number = ugapplicant.application_number
90        self.ugapplicant = self.app['applicants']['app2011'][
91            self.ugapplication_number]
92
93        self.browser = Browser()
94        self.browser.handleErrors = False
95
[7866]96    def tearDown(self):
[8012]97        super(ApplicantUITest, self).tearDown()
[7866]98        shutil.rmtree(self.dc_root)
99        clearSite()
100        return
101
[8012]102    def test_manage_and_view_applicant(self):
103        # Managers can manage pg applicants
104        pgapplicant_path = ('http://localhost/app/applicants/pg2011/%s'
105            % self.pgapplication_number)
106        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[8017]107        # The IPGApplicant interface is really used in all pages
[8012]108        self.browser.open(pgapplicant_path)
109        self.assertEqual(self.browser.headers['Status'], '200 Ok')
110        self.assertTrue('Employer' in self.browser.contents)
[8017]111        self.browser.open(pgapplicant_path + '/manage')
112        self.assertEqual(self.browser.headers['Status'], '200 Ok')
113        self.assertTrue('Employer' in self.browser.contents)
114        self.browser.open(pgapplicant_path + '/edit')
115        self.assertEqual(self.browser.headers['Status'], '200 Ok')
116        self.assertTrue('Employer' in self.browser.contents)
117        self.browser.open(pgapplicant_path + '/application_slip.pdf')
118        self.assertEqual(self.browser.headers['Status'], '200 Ok')
119        # If we lool at the applicant in the ug container,
120        # the employer field doesn't appear
[8012]121        ugapplicant_path = ('http://localhost/app/applicants/app2011/%s'
122            % self.ugapplication_number)
123        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
124        self.browser.open(ugapplicant_path)
125        self.assertEqual(self.browser.headers['Status'], '200 Ok')
126        self.assertFalse('Employer' in self.browser.contents)
[8017]127        self.browser.open(ugapplicant_path + '/manage')
128        self.assertEqual(self.browser.headers['Status'], '200 Ok')
[8053]129        # We can save the applicant
130        self.browser.getControl(name="form.reg_number").value = '1234'
131        self.browser.getControl(name="form.firstname").value = 'John'
132        self.browser.getControl(name="form.lastname").value = 'Tester'
133        self.browser.getControl(name="form.course1").value = ['CERT1']
134        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
135        self.browser.getControl(name="form.lga").value = ['foreigner']
136        self.browser.getControl(name="form.sex").value = ['m']
137        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
138        self.browser.getControl("Save").click()
139        self.assertMatches('...Form has been saved...', self.browser.contents)
[8017]140        self.assertFalse('Employer' in self.browser.contents)
141        self.browser.open(ugapplicant_path + '/edit')
142        self.assertEqual(self.browser.headers['Status'], '200 Ok')
143        self.assertFalse('Employer' in self.browser.contents)
144        self.browser.open(ugapplicant_path + '/application_slip.pdf')
145        self.assertEqual(self.browser.headers['Status'], '200 Ok')
[8012]146        return
Note: See TracBrowser for help on using the repository browser.