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

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

UG programmes (utme and de) are in affiliation with Ibadan. Use appropriate header in slips.

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1## $Id: test_browser.py 10570 2013-08-31 08:19:05Z 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        delta = datetime.timedelta(days=10)
66        self.beccontainer.startdate = datetime.datetime.now(pytz.utc) - delta
67        self.beccontainer.enddate = datetime.datetime.now(pytz.utc) + delta
68
69        # Add ug applicants container
70        self.putmecontainer = ApplicantsContainer()
71        self.putmecontainer.mode = 'create'
72        self.putmecontainer.code = u'putme2011'
73        self.putmecontainer.prefix = u'putme'
74        self.putmecontainer.application_category = u'bec' # doesn't matter
75        self.putmecontainer.year = 2011
76        self.putmecontainer.application_fee = 300.0
77        self.putmecontainer.title = u'This is the putme2011 container'
78        self.app['applicants']['putme2011'] = self.putmecontainer
79        delta = datetime.timedelta(days=10)
80        self.putmecontainer.startdate = datetime.datetime.now(pytz.utc) - delta
81        self.putmecontainer.enddate = datetime.datetime.now(pytz.utc) + delta
82
83        # Populate university
84        self.certificate = createObject('waeup.Certificate')
85        self.certificate.code = 'CERT1'
86        self.certificate.application_category = 'bec'
87        self.certificate.start_level = 100
88        self.certificate.end_level = 500
89        self.certificate.study_mode = u'nce_ft'
90        self.app['faculties']['fac1'] = Faculty()
91        self.app['faculties']['fac1']['dep1'] = Department()
92        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
93            self.certificate)
94
95        # Add (customized) applicants
96        becapplicant = createObject(u'waeup.Applicant')
97        becapplicant.firstname = u'Anna'
98        becapplicant.lastname = u'Post'
99        self.app['applicants']['bec2011'].addApplicant(becapplicant)
100        self.becapplication_number = becapplicant.application_number
101        self.becapplicant = self.app['applicants']['bec2011'][
102            self.becapplication_number]
103        self.becapplicant_path = ('http://localhost/app/applicants/bec2011/%s'
104            % self.becapplication_number)
105
106        putmeapplicant = createObject(u'waeup.Applicant')
107        putmeapplicant.firstname = u'Anna'
108        putmeapplicant.lastname = u'Post'
109        self.app['applicants']['putme2011'].addApplicant(putmeapplicant)
110        self.putmeapplication_number = putmeapplicant.application_number
111        self.putmeapplicant = self.app['applicants']['putme2011'][
112            self.putmeapplication_number]
113        self.putmeapplicant_path = ('http://localhost/app/applicants/putme2011/%s'
114            % self.putmeapplication_number)
115
116        self.browser = Browser()
117        self.browser.handleErrors = False
118
119    def tearDown(self):
120        super(ApplicantUITest, self).tearDown()
121        shutil.rmtree(self.dc_root)
122        clearSite()
123        return
124
125    def fill_correct_values(self):
126        self.browser.getControl(name="form.reg_number").value = '1234'
127        self.browser.getControl(name="form.firstname").value = 'John'
128        self.browser.getControl(name="form.lastname").value = 'Tester'
129        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
130        self.browser.getControl(name="form.lga").value = ['foreigner']
131        self.browser.getControl(name="form.nationality").value = ['NG']
132        self.browser.getControl(name="form.sex").value = ['m']
133        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
134
135    def test_manage_and_view_bec_applicant(self):
136        # Managers can manage bec applicants.
137        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
138        self.browser.open(self.becapplicant_path)
139        self.assertEqual(self.browser.headers['Status'], '200 Ok')
140        self.assertTrue("'O' Level" in self.browser.contents)
141        self.browser.open(self.becapplicant_path + '/manage')
142        self.assertEqual(self.browser.headers['Status'], '200 Ok')
143        self.assertTrue("'O' Level" in self.browser.contents)
144        self.browser.open(self.becapplicant_path + '/edit')
145        self.assertEqual(self.browser.headers['Status'], '200 Ok')
146        self.assertTrue("'O' Level" in self.browser.contents)
147        self.browser.open(self.becapplicant_path + '/application_slip.pdf')
148        self.assertEqual(self.browser.headers['Status'], '200 Ok')
149        return
150
151    def test_manage_and_view_putme_applicant(self):
152        # Managers can manage bec applicants.
153        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
154        self.browser.open(self.putmeapplicant_path)
155        self.assertEqual(self.browser.headers['Status'], '200 Ok')
156        self.assertTrue("'O' Level" in self.browser.contents)
157        self.browser.open(self.putmeapplicant_path + '/manage')
158        self.assertEqual(self.browser.headers['Status'], '200 Ok')
159        self.assertTrue("'O' Level" in self.browser.contents)
160        self.browser.open(self.putmeapplicant_path + '/edit')
161        self.assertEqual(self.browser.headers['Status'], '200 Ok')
162        self.assertTrue("'O' Level" in self.browser.contents)
163        self.browser.open(self.putmeapplicant_path + '/application_slip.pdf')
164        self.assertEqual(self.browser.headers['Status'], '200 Ok')
165        return
Note: See TracBrowser for help on using the repository browser.