source: main/waeup.aaue/trunk/src/waeup/aaue/applicants/tests.py @ 8503

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

Rename uniben to aaue.

  • Property svn:keywords set to Id
File size: 9.4 KB
Line 
1## $Id: tests.py 8444 2012-05-14 10:04:25Z 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
21import datetime
22from zope.intid.interfaces import IIntIds
23from zope.interface.verify import verifyClass, verifyObject
24from zope.component.hooks import setSite, clearSite
25from zope.component import createObject, getUtility
26from zope.catalog.interfaces import ICatalog
27from zope.testbrowser.testing import Browser
28from waeup.kofa.app import University
29from waeup.kofa.university.faculty import Faculty
30from waeup.kofa.university.department import Department
31from waeup.kofa.testing import FunctionalTestCase
32from waeup.kofa.applicants.container import ApplicantsContainer
33from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
34from waeup.kofa.interfaces import IBatchProcessor
35from waeup.aaue.testing import FunctionalLayer
36from waeup.aaue.applicants.export import CustomApplicantsExporter
37
38
39class ApplicantUITest(FunctionalTestCase):
40    """Perform some browser tests.
41    """
42    layer = FunctionalLayer
43
44    def setUp(self):
45        super(ApplicantUITest, self).setUp()
46        # Setup a sample site for each test
47        app = University()
48        self.dc_root = tempfile.mkdtemp()
49        app['datacenter'].setStoragePath(self.dc_root)
50
51        # Prepopulate the ZODB...
52        self.getRootFolder()['app'] = app
53        # we add the site immediately after creation to the
54        # ZODB. Catalogs and other local utilities are not setup
55        # before that step.
56        self.app = self.getRootFolder()['app']
57        # Set site here. Some of the following setup code might need
58        # to access grok.getSite() and should get our new app then
59        setSite(app)
60
61        # Add an two different applicants containers
62        self.pgcontainer = ApplicantsContainer()
63        self.pgcontainer.code = u'pgft2011'
64        self.pgcontainer.prefix = u'pgft'
65        self.app['applicants']['pgft2011'] = self.pgcontainer
66        self.ugcontainer = ApplicantsContainer()
67        self.ugcontainer.code = u'app2011'
68        self.ugcontainer.prefix = u'app'
69        self.app['applicants']['app2011'] = self.ugcontainer
70
71        # Populate university
72        self.certificate = createObject('waeup.Certificate')
73        self.certificate.code = 'CERT1'
74        self.certificate.application_category = 'basic'
75        self.certificate.start_level = 100
76        self.certificate.end_level = 500
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        pgapplicant = createObject(u'waeup.Applicant')
84        pgapplicant.firstname = u'Anna'
85        pgapplicant.lastname = u'Post'
86        self.app['applicants']['pgft2011'].addApplicant(pgapplicant)
87        self.pgapplication_number = pgapplicant.application_number
88        self.pgapplicant = self.app['applicants']['pgft2011'][
89            self.pgapplication_number]
90
91        ugapplicant = createObject(u'waeup.Applicant')
92        ugapplicant.firstname = u'Klaus'
93        ugapplicant.lastname = u'Under'
94        self.app['applicants']['app2011'].addApplicant(ugapplicant)
95        self.ugapplication_number = ugapplicant.application_number
96        self.ugapplicant = self.app['applicants']['app2011'][
97            self.ugapplication_number]
98
99        self.browser = Browser()
100        self.browser.handleErrors = False
101
102    def tearDown(self):
103        super(ApplicantUITest, self).tearDown()
104        shutil.rmtree(self.dc_root)
105        clearSite()
106        return
107
108    def test_manage_and_view_applicant(self):
109        # Managers can manage pg applicants
110        pgapplicant_path = ('http://localhost/app/applicants/pgft2011/%s'
111            % self.pgapplication_number)
112        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
113        # The IPGApplicant interface is really used in all pages
114        self.browser.open(pgapplicant_path)
115        self.assertEqual(self.browser.headers['Status'], '200 Ok')
116        self.assertTrue('Employer' in self.browser.contents)
117        self.browser.open(pgapplicant_path + '/manage')
118        self.assertEqual(self.browser.headers['Status'], '200 Ok')
119        self.assertTrue('Employer' in self.browser.contents)
120        self.browser.open(pgapplicant_path + '/edit')
121        self.assertEqual(self.browser.headers['Status'], '200 Ok')
122        self.assertTrue('Employer' in self.browser.contents)
123        self.browser.open(pgapplicant_path + '/application_slip.pdf')
124        self.assertEqual(self.browser.headers['Status'], '200 Ok')
125        # If we lool at the applicant in the ug container,
126        # the employer field doesn't appear
127        ugapplicant_path = ('http://localhost/app/applicants/app2011/%s'
128            % self.ugapplication_number)
129        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
130        self.browser.open(ugapplicant_path)
131        self.assertEqual(self.browser.headers['Status'], '200 Ok')
132        self.assertFalse('Employer' in self.browser.contents)
133        self.browser.open(ugapplicant_path + '/manage')
134        self.assertEqual(self.browser.headers['Status'], '200 Ok')
135        # We can save the applicant
136        self.browser.getControl(name="form.reg_number").value = '1234'
137        self.browser.getControl(name="form.firstname").value = 'John'
138        self.browser.getControl(name="form.lastname").value = 'Tester'
139        self.browser.getControl(name="form.course1").value = ['CERT1']
140        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
141        self.browser.getControl(name="form.lga").value = ['foreigner']
142        self.browser.getControl(name="form.sex").value = ['m']
143        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
144        self.browser.getControl("Save").click()
145        self.assertMatches('...Form has been saved...', self.browser.contents)
146        self.assertFalse('Employer' in self.browser.contents)
147        self.browser.open(ugapplicant_path + '/edit')
148        self.assertEqual(self.browser.headers['Status'], '200 Ok')
149        self.assertFalse('Employer' in self.browser.contents)
150        self.browser.open(ugapplicant_path + '/application_slip.pdf')
151        self.assertEqual(self.browser.headers['Status'], '200 Ok')
152        return
153
154class ApplicantsExporterTest(ApplicantImportExportSetup):
155
156    layer = FunctionalLayer
157
158    def setUp(self):
159        super(ApplicantsExporterTest, self).setUp()
160        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
161        self.cat = getUtility(ICatalog, name='applicants_catalog')
162        self.intids = getUtility(IIntIds)
163        return
164
165    def setup_applicant(self, applicant):
166        # set predictable values for `applicant`
167        applicant.reg_number = u'123456'
168        applicant.applicant_id = u'dp2011_654321'
169        applicant.firstname = u'Anna'
170        applicant.lastname = u'Tester'
171        applicant.middlename = u'M.'
172        applicant.date_of_birth = datetime.date(1981, 2, 4)
173        applicant.sex = 'f'
174        applicant.email = 'anna@sample.com'
175        applicant.phone = u'+234-123-12345'
176        applicant.course1 = self.certificate
177        applicant.course2 = self.certificate
178        applicant.course_admitted = self.certificate
179        applicant.notice = u'Some notice\nin lines.'
180        applicant.screening_score = 98
181        applicant.screening_venue = u'Exam Room'
182        applicant.password = 'any password'
183        return applicant
184
185    def test_export_all(self):
186        # we can export all applicants in a portal
187        # set values we can expect in export file
188        self.applicant = self.setup_applicant(self.applicant)
189        exporter = CustomApplicantsExporter()
190        exporter.export_all(self.app, self.outfile)
191        result = open(self.outfile, 'rb').read()
192        # The exported records do contain a real date in their
193        # history dict. We skip the date and split the comparison
194        # into two parts.
195        self.assertTrue(
196            'applicant_id,application_date,application_number,course1,course2,'
197            'course_admitted,date_of_birth,display_fullname,email,emp2_end,'
198            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
199            'emp_reason,emp_start,employer,employer2,firstname,history,'
200            'hq_degree,hq_disc,hq_matric_no,hq_school,hq_session,hq_type,'
201            'lastname,lga,locked,middlename,nationality,notice,nysc_lga,'
202            'nysc_year,password,perm_address,phone,pp_school,presently_inst,'
203            'reg_number,screening_score,screening_venue,sex,state,student_id'
204            in result)
205        self.assertTrue(
206            'Application initialized by system\'],,,,,,,Tester,,0,M.,,'
207            '"Some notice\nin lines.",,,any password,,+234-123-12345,,,'
208            '123456,98,Exam Room,f,initialized,' in result)
209        return
Note: See TracBrowser for help on using the repository browser.