source: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/applicants/tests/test_browser.py @ 10847

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

Enable import of empty sex and course1 cells.

  • Property svn:keywords set to Id
File size: 6.3 KB
Line 
1## $Id: test_browser.py 10594 2013-09-06 06:07:02Z 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.kwarapoly.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 ndft applicants container
56        self.ndftcontainer = ApplicantsContainer()
57        self.ndftcontainer.mode = 'create'
58        self.ndftcontainer.code = u'ndft2011'
59        self.ndftcontainer.prefix = u'ndft'
60        self.ndftcontainer.application_category = u'ndft'
61        self.ndftcontainer.year = 2011
62        self.ndftcontainer.application_fee = 300.0
63        self.ndftcontainer.title = u'This is the ndft2011 container'
64        self.app['applicants']['ndft2011'] = self.ndftcontainer
65
66        delta = datetime.timedelta(days=10)
67        self.ndftcontainer.startdate = datetime.datetime.now(pytz.utc) - delta
68        self.ndftcontainer.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 = 'ndft'
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        ndftapplicant = createObject(u'waeup.Applicant')
84        ndftapplicant.firstname = u'Anna'
85        ndftapplicant.lastname = u'Post'
86        self.app['applicants']['ndft2011'].addApplicant(ndftapplicant)
87        self.ndftapplication_number = ndftapplicant.application_number
88        self.ndftapplicant = self.app['applicants']['ndft2011'][
89            self.ndftapplication_number]
90        self.ndftapplicant_path = ('http://localhost/app/applicants/ndft2011/%s'
91            % self.ndftapplication_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 ndft applicants.
114        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
115        self.browser.open(self.ndftapplicant_path)
116        self.assertEqual(self.browser.headers['Status'], '200 Ok')
117        self.assertTrue("'O' Level" in self.browser.contents)
118        self.assertFalse("Higher" in self.browser.contents)
119        self.browser.open(self.ndftapplicant_path + '/manage')
120        self.assertEqual(self.browser.headers['Status'], '200 Ok')
121        self.assertTrue("'O' Level" in self.browser.contents)
122        self.assertTrue("Higher" in self.browser.contents)
123        self.browser.open(self.ndftapplicant_path + '/edit')
124        self.assertEqual(self.browser.headers['Status'], '200 Ok')
125        self.assertTrue("'O' Level" in self.browser.contents)
126        self.assertFalse("Higher" in self.browser.contents)
127        self.browser.open(self.ndftapplicant_path + '/application_slip.pdf')
128        self.assertEqual(self.browser.headers['Status'], '200 Ok')
129        # Now we turn the ndft applicant into an hndft applicant.
130        self.ndftapplicant.applicant_id = u'hndft_anything'
131        self.browser.open(self.ndftapplicant_path)
132        self.assertTrue("Higher" in self.browser.contents)
133        self.assertTrue("'O' Level" in self.browser.contents)
134        self.browser.open(self.ndftapplicant_path + '/edit')
135        self.assertTrue("Higher" in self.browser.contents)
136        self.assertTrue("'O' Level" in self.browser.contents)
137
138        self.browser.open(self.ndftapplicant_path + '/manage')
139        # Manager can fill and save the form
140        self.fill_correct_values()
141        self.browser.getControl("Save").click()
142        self.assertMatches('...Form has been saved...', self.browser.contents)
143        return
Note: See TracBrowser for help on using the repository browser.