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

Last change on this file since 10222 was 9943, checked in by Henrik Bettermann, 12 years ago

Rename study mode.

  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1## $Id: test_browser.py 9943 2013-02-13 10:17:01Z 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
22from zope.component.hooks import setSite, clearSite
23from zope.component import createObject
24from zope.testbrowser.testing import Browser
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
29from waeup.kofa.applicants.container import ApplicantsContainer
30from waeup.fceokene.testing import FunctionalLayer
31
32
33class ApplicantUITest(FunctionalTestCase):
34    """Perform some browser tests.
35    """
36    layer = FunctionalLayer
37
38    def setUp(self):
39        super(ApplicantUITest, self).setUp()
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
55        # Add bec applicants container
56        self.beccontainer = ApplicantsContainer()
57        self.beccontainer.mode = 'create'
58        self.beccontainer.code = u'bec2011'
59        self.beccontainer.prefix = u'bec'
60        self.beccontainer.application_category = u'bec'
61        self.beccontainer.year = 2011
62        self.beccontainer.application_fee = 300.0
63        self.beccontainer.title = u'This is the bec2011 container'
64        self.app['applicants']['bec2011'] = self.beccontainer
65
66        delta = datetime.timedelta(days=10)
67        self.beccontainer.startdate = datetime.datetime.now(pytz.utc) - delta
68        self.beccontainer.enddate = datetime.datetime.now(pytz.utc) + delta
69
70        # Populate university
71        self.certificate = createObject('waeup.Certificate')
72        self.certificate.code = 'CERT1'
73        self.certificate.application_category = 'bec'
74        self.certificate.start_level = 100
75        self.certificate.end_level = 500
76        self.certificate.study_mode = u'nce_ft'
77        self.app['faculties']['fac1'] = Faculty()
78        self.app['faculties']['fac1']['dep1'] = Department()
79        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
80            self.certificate)
81
82        # Add (customized) applicants
83        becapplicant = createObject(u'waeup.Applicant')
84        becapplicant.firstname = u'Anna'
85        becapplicant.lastname = u'Post'
86        self.app['applicants']['bec2011'].addApplicant(becapplicant)
87        self.becapplication_number = becapplicant.application_number
88        self.becapplicant = self.app['applicants']['bec2011'][
89            self.becapplication_number]
90        self.becapplicant_path = ('http://localhost/app/applicants/bec2011/%s'
91            % self.becapplication_number)
92
93        self.browser = Browser()
94        self.browser.handleErrors = False
95
96    def tearDown(self):
97        super(ApplicantUITest, self).tearDown()
98        shutil.rmtree(self.dc_root)
99        clearSite()
100        return
101
102    def fill_correct_values(self):
103        self.browser.getControl(name="form.reg_number").value = '1234'
104        self.browser.getControl(name="form.firstname").value = 'John'
105        self.browser.getControl(name="form.lastname").value = 'Tester'
106        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
107        self.browser.getControl(name="form.lga").value = ['foreigner']
108        self.browser.getControl(name="form.nationality").value = ['NG']
109        self.browser.getControl(name="form.sex").value = ['m']
110        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
111
112    def test_manage_and_view_applicant(self):
113        # Managers can manage bec applicants.
114        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
115        self.browser.open(self.becapplicant_path)
116        self.assertEqual(self.browser.headers['Status'], '200 Ok')
117        self.assertTrue("'O' Level" in self.browser.contents)
118        self.browser.open(self.becapplicant_path + '/manage')
119        self.assertEqual(self.browser.headers['Status'], '200 Ok')
120        self.assertTrue("'O' Level" in self.browser.contents)
121        self.browser.open(self.becapplicant_path + '/edit')
122        self.assertEqual(self.browser.headers['Status'], '200 Ok')
123        self.assertTrue("'O' Level" in self.browser.contents)
124        self.browser.open(self.becapplicant_path + '/application_slip.pdf')
125        self.assertEqual(self.browser.headers['Status'], '200 Ok')
126        return
Note: See TracBrowser for help on using the repository browser.