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

Last change on this file since 10875 was 10875, checked in by Henrik Bettermann, 11 years ago

Make tests turn-of-the-year-resistant.

  • Property svn:keywords set to Id
File size: 7.7 KB
Line 
1## $Id: test_browser.py 10875 2014-01-07 07:41:08Z 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
32session = datetime.now().year - 2
33
34class ApplicantUITest(FunctionalTestCase):
35    """Perform some browser tests.
36    """
37    layer = FunctionalLayer
38
39    def setUp(self):
40        super(ApplicantUITest, self).setUp()
41        # Setup a sample site for each test
42        app = University()
43        self.dc_root = tempfile.mkdtemp()
44        app['datacenter'].setStoragePath(self.dc_root)
45
46        # Prepopulate the ZODB...
47        self.getRootFolder()['app'] = app
48        # we add the site immediately after creation to the
49        # ZODB. Catalogs and other local utilities are not setup
50        # before that step.
51        self.app = self.getRootFolder()['app']
52        # Set site here. Some of the following setup code might need
53        # to access grok.getSite() and should get our new app then
54        setSite(app)
55
56        # Add bec applicants container
57        self.beccontainer = ApplicantsContainer()
58        self.beccontainer.mode = 'create'
59        self.beccontainer.code = u'bec%s' % session
60        self.beccontainer.prefix = u'bec'
61        self.beccontainer.application_category = u'bec'
62        self.beccontainer.year = session
63        self.beccontainer.application_fee = 300.0
64        self.beccontainer.title = u'This is the bec%s container' % session
65        self.app['applicants'][self.beccontainer.code] = self.beccontainer
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        # Add ug applicants container
71        self.putmecontainer = ApplicantsContainer()
72        self.putmecontainer.mode = 'create'
73        self.putmecontainer.code = u'putme%s' % session
74        self.putmecontainer.prefix = u'putme'
75        self.putmecontainer.application_category = u'bec' # doesn't matter
76        self.putmecontainer.year = session
77        self.putmecontainer.application_fee = 300.0
78        self.putmecontainer.title = u'This is the putme%s container' % session
79        self.app['applicants'][self.putmecontainer.code] = self.putmecontainer
80        delta = datetime.timedelta(days=10)
81        self.putmecontainer.startdate = datetime.datetime.now(pytz.utc) - delta
82        self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta
83
84        # Populate university
85        self.certificate = createObject('waeup.Certificate')
86        self.certificate.code = 'CERT1'
87        self.certificate.application_category = 'bec'
88        self.certificate.start_level = 100
89        self.certificate.end_level = 500
90        self.certificate.study_mode = u'nce_ft'
91        self.app['faculties']['fac1'] = Faculty()
92        self.app['faculties']['fac1']['dep1'] = Department()
93        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
94            self.certificate)
95
96        # Add (customized) applicants
97        becapplicant = createObject(u'waeup.Applicant')
98        becapplicant.firstname = u'Anna'
99        becapplicant.lastname = u'Post'
100        self.app['applicants'][self.beccontainer.code].addApplicant(becapplicant)
101        self.becapplication_number = becapplicant.application_number
102        self.becapplicant = self.app['applicants'][self.beccontainer.code][
103            self.becapplication_number]
104        self.becapplicant_path = ('http://localhost/app/applicants/bec%s/%s'
105            % (session, self.becapplication_number))
106
107        putmeapplicant = createObject(u'waeup.Applicant')
108        putmeapplicant.firstname = u'Anna'
109        putmeapplicant.lastname = u'Post'
110        self.app['applicants'][self.putmecontainer.code].addApplicant(putmeapplicant)
111        self.putmeapplication_number = putmeapplicant.application_number
112        self.putmeapplicant = self.app['applicants'][self.putmecontainer.code][
113            self.putmeapplication_number]
114        self.putmeapplicant_path = ('http://localhost/app/applicants/putme%s/%s'
115            % (session, self.putmeapplication_number))
116
117        self.browser = Browser()
118        self.browser.handleErrors = False
119
120    def tearDown(self):
121        super(ApplicantUITest, self).tearDown()
122        shutil.rmtree(self.dc_root)
123        clearSite()
124        return
125
126    def fill_correct_values(self):
127        self.browser.getControl(name="form.reg_number").value = '1234'
128        self.browser.getControl(name="form.firstname").value = 'John'
129        self.browser.getControl(name="form.lastname").value = 'Tester'
130        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
131        self.browser.getControl(name="form.lga").value = ['foreigner']
132        self.browser.getControl(name="form.nationality").value = ['NG']
133        self.browser.getControl(name="form.sex").value = ['m']
134        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
135
136    def test_manage_and_view_bec_applicant(self):
137        # Managers can manage bec applicants.
138        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
139        self.browser.open(self.becapplicant_path)
140        self.assertEqual(self.browser.headers['Status'], '200 Ok')
141        self.assertTrue("'O' Level" in self.browser.contents)
142        self.browser.open(self.becapplicant_path + '/manage')
143        self.assertEqual(self.browser.headers['Status'], '200 Ok')
144        self.assertTrue("'O' Level" in self.browser.contents)
145        self.browser.open(self.becapplicant_path + '/edit')
146        self.assertEqual(self.browser.headers['Status'], '200 Ok')
147        self.assertTrue("'O' Level" in self.browser.contents)
148        self.browser.open(self.becapplicant_path + '/application_slip.pdf')
149        self.assertEqual(self.browser.headers['Status'], '200 Ok')
150        return
151
152    def test_manage_and_view_putme_applicant(self):
153        # Managers can manage bec applicants.
154        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
155        self.browser.open(self.putmeapplicant_path)
156        self.assertEqual(self.browser.headers['Status'], '200 Ok')
157        self.assertTrue("'O' Level" in self.browser.contents)
158        self.browser.open(self.putmeapplicant_path + '/manage')
159        self.assertEqual(self.browser.headers['Status'], '200 Ok')
160        self.assertTrue("'O' Level" in self.browser.contents)
161        self.browser.open(self.putmeapplicant_path + '/edit')
162        self.assertEqual(self.browser.headers['Status'], '200 Ok')
163        self.assertTrue("'O' Level" in self.browser.contents)
164        self.browser.open(self.putmeapplicant_path + '/application_slip.pdf')
165        self.assertEqual(self.browser.headers['Status'], '200 Ok')
166        return
Note: See TracBrowser for help on using the repository browser.