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

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

See r8535.

  • Property svn:keywords set to Id
File size: 12.2 KB
Line 
1## $Id: tests.py 8537 2012-05-28 05:26:18Z 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.configuration import SessionConfiguration
33from waeup.kofa.applicants.container import ApplicantsContainer
34from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
35from waeup.kofa.interfaces import IBatchProcessor
36from waeup.fceokene.testing import FunctionalLayer
37from waeup.fceokene.applicants.export import CustomApplicantsExporter
38
39
40class ApplicantUITest(FunctionalTestCase):
41    """Perform some browser tests.
42    """
43    layer = FunctionalLayer
44
45    def setUp(self):
46        super(ApplicantUITest, self).setUp()
47        # Setup a sample site for each test
48        app = University()
49        self.dc_root = tempfile.mkdtemp()
50        app['datacenter'].setStoragePath(self.dc_root)
51
52        # Prepopulate the ZODB...
53        self.getRootFolder()['app'] = app
54        # we add the site immediately after creation to the
55        # ZODB. Catalogs and other local utilities are not setup
56        # before that step.
57        self.app = self.getRootFolder()['app']
58        # Set site here. Some of the following setup code might need
59        # to access grok.getSite() and should get our new app then
60        setSite(app)
61
62        # Add an two different applicants containers
63        self.pgcontainer = ApplicantsContainer()
64        self.pgcontainer.code = u'pgft2011'
65        self.pgcontainer.prefix = u'pgft'
66        self.pgcontainer.year = 2011
67        self.pgcontainer.application_fee = 300.0
68        self.pgcontainer.title = u'This is the pgft2011 container'
69        self.app['applicants']['pgft2011'] = self.pgcontainer
70        self.ugcontainer = ApplicantsContainer()
71        self.ugcontainer.code = u'putme2011'
72        self.ugcontainer.prefix = u'putme'
73        self.ugcontainer.year = 2011
74        self.ugcontainer.application_fee = 200.0
75        self.ugcontainer.title = u'This is the app2011 container'
76        self.app['applicants']['app2011'] = self.ugcontainer
77
78        # Populate university
79        self.certificate = createObject('waeup.Certificate')
80        self.certificate.code = 'CERT1'
81        self.certificate.application_category = 'basic'
82        self.certificate.start_level = 100
83        self.certificate.end_level = 500
84        self.app['faculties']['fac1'] = Faculty()
85        self.app['faculties']['fac1']['dep1'] = Department()
86        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
87            self.certificate)
88
89        # Add (customized) applicants
90        pgapplicant = createObject(u'waeup.Applicant')
91        pgapplicant.firstname = u'Anna'
92        pgapplicant.lastname = u'Post'
93        self.app['applicants']['pgft2011'].addApplicant(pgapplicant)
94        self.pgapplication_number = pgapplicant.application_number
95        self.pgapplicant = self.app['applicants']['pgft2011'][
96            self.pgapplication_number]
97
98        ugapplicant = createObject(u'waeup.Applicant')
99        ugapplicant.firstname = u'Klaus'
100        ugapplicant.lastname = u'Under'
101        self.app['applicants']['app2011'].addApplicant(ugapplicant)
102        self.ugapplication_number = ugapplicant.application_number
103        self.ugapplicant = self.app['applicants']['app2011'][
104            self.ugapplication_number]
105        self.pgapplicant_path = ('http://localhost/app/applicants/pgft2011/%s'
106            % self.pgapplication_number)
107        self.ugapplicant_path = ('http://localhost/app/applicants/app2011/%s'
108            % self.ugapplication_number)
109
110        self.browser = Browser()
111        self.browser.handleErrors = False
112
113    def tearDown(self):
114        super(ApplicantUITest, self).tearDown()
115        shutil.rmtree(self.dc_root)
116        clearSite()
117        return
118
119    def fill_correct_values(self):
120        self.browser.getControl(name="form.reg_number").value = '1234'
121        self.browser.getControl(name="form.firstname").value = 'John'
122        self.browser.getControl(name="form.lastname").value = 'Tester'
123        self.browser.getControl(name="form.course1").value = ['CERT1']
124        self.browser.getControl(name="form.date_of_birth").value = '09/09/1988'
125        self.browser.getControl(name="form.lga").value = ['foreigner']
126        self.browser.getControl(name="form.sex").value = ['m']
127        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
128
129    def test_manage_and_view_applicant(self):
130        # Managers can manage pg applicants
131        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
132        # The IPGApplicant interface is really used in all pages
133        self.browser.open(self.pgapplicant_path)
134        self.assertEqual(self.browser.headers['Status'], '200 Ok')
135        self.assertTrue('Employer' in self.browser.contents)
136        self.browser.open(self.pgapplicant_path + '/manage')
137        self.assertEqual(self.browser.headers['Status'], '200 Ok')
138        self.assertTrue('Employer' in self.browser.contents)
139        self.browser.open(self.pgapplicant_path + '/edit')
140        self.assertEqual(self.browser.headers['Status'], '200 Ok')
141        self.assertTrue('Employer' in self.browser.contents)
142        self.browser.open(self.pgapplicant_path + '/application_slip.pdf')
143        self.assertEqual(self.browser.headers['Status'], '200 Ok')
144        # If we view the applicant in the ug container,
145        # the employer field doesn't appear
146        self.browser.open(self.ugapplicant_path)
147        self.assertEqual(self.browser.headers['Status'], '200 Ok')
148        self.assertFalse('Employer' in self.browser.contents)
149        self.browser.open(self.ugapplicant_path + '/manage')
150        self.assertEqual(self.browser.headers['Status'], '200 Ok')
151        # We can save the applicant
152        self.fill_correct_values()
153        self.browser.getControl("Save").click()
154        self.assertMatches('...Form has been saved...', self.browser.contents)
155        self.assertFalse('Employer' in self.browser.contents)
156        self.browser.open(self.ugapplicant_path + '/edit')
157        self.assertEqual(self.browser.headers['Status'], '200 Ok')
158        self.assertFalse('Employer' in self.browser.contents)
159        self.browser.open(self.ugapplicant_path + '/application_slip.pdf')
160        self.assertEqual(self.browser.headers['Status'], '200 Ok')
161        return
162
163    def test_application_payment(self):
164        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
165
166        # UG (UTME) applicant
167        self.browser.open(self.ugapplicant_path)
168        self.browser.open(self.ugapplicant_path + '/manage')
169        self.assertEqual(self.browser.headers['Status'], '200 Ok')
170        self.fill_correct_values()
171        self.browser.getControl("Save").click()
172        self.assertMatches('...Form has been saved...', self.browser.contents)
173        self.fill_correct_values()
174        self.browser.getControl("Save").click()
175        self.browser.getControl("Add online payment ticket").click()
176        self.assertMatches('...Payment ticket created...',
177                           self.browser.contents)
178        self.assertMatches('...Amount Authorized...',
179                           self.browser.contents)
180        payment_id = self.ugapplicant.keys()[0]
181        payment = self.ugapplicant[payment_id]
182        self.assertEqual(payment.p_item,'This is the app2011 container')
183        self.assertEqual(payment.p_session,2011)
184        self.assertEqual(payment.p_category,'application')
185        self.assertEqual(payment.amount_auth, 200.0)
186
187        # PG applicants pay more
188        self.browser.open(self.pgapplicant_path)
189        self.browser.open(self.pgapplicant_path + '/manage')
190        self.assertEqual(self.browser.headers['Status'], '200 Ok')
191        self.fill_correct_values()
192        self.browser.getControl(name="form.reg_number").value = '2345'
193        self.browser.getControl(name="form.firstname").value = 'Anna'
194        self.browser.getControl("Save").click()
195        self.assertMatches('...Form has been saved...', self.browser.contents)
196        self.browser.getControl("Add online payment ticket").click()
197        self.assertMatches('...Payment ticket created...',
198                           self.browser.contents)
199        self.assertMatches('...Amount Authorized...',
200                           self.browser.contents)
201        payment_id = self.pgapplicant.keys()[0]
202        payment = self.pgapplicant[payment_id]
203        self.assertEqual(payment.p_item,'This is the pgft2011 container')
204        self.assertEqual(payment.p_session,2011)
205        self.assertEqual(payment.p_category,'application')
206        self.assertEqual(payment.amount_auth, 300.0)
207        return
208
209class ApplicantsExporterTest(ApplicantImportExportSetup):
210
211    layer = FunctionalLayer
212
213    def setUp(self):
214        super(ApplicantsExporterTest, self).setUp()
215        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
216        self.cat = getUtility(ICatalog, name='applicants_catalog')
217        self.intids = getUtility(IIntIds)
218        return
219
220    def setup_applicant(self, applicant):
221        # set predictable values for `applicant`
222        applicant.reg_number = u'123456'
223        applicant.applicant_id = u'dp2011_654321'
224        applicant.firstname = u'Anna'
225        applicant.lastname = u'Tester'
226        applicant.middlename = u'M.'
227        applicant.date_of_birth = datetime.date(1981, 2, 4)
228        applicant.sex = 'f'
229        applicant.email = 'anna@sample.com'
230        applicant.phone = u'+234-123-12345'
231        applicant.course1 = self.certificate
232        applicant.course2 = self.certificate
233        applicant.course_admitted = self.certificate
234        applicant.notice = u'Some notice\nin lines.'
235        applicant.screening_score = 98
236        applicant.screening_venue = u'Exam Room'
237        applicant.password = 'any password'
238        return applicant
239
240    def test_export_all(self):
241        # we can export all applicants in a portal
242        # set values we can expect in export file
243        self.applicant = self.setup_applicant(self.applicant)
244        exporter = CustomApplicantsExporter()
245        exporter.export_all(self.app, self.outfile)
246        result = open(self.outfile, 'rb').read()
247        # The exported records do contain a real date in their
248        # history dict. We skip the date and split the comparison
249        # into two parts.
250        self.assertTrue(
251            'applicant_id,application_date,application_number,course1,course2,'
252            'course_admitted,date_of_birth,display_fullname,email,emp2_end,'
253            'emp2_position,emp2_reason,emp2_start,emp_end,emp_position,'
254            'emp_reason,emp_start,employer,employer2,firstname,history,'
255            'hq_degree,hq_disc,hq_matric_no,hq_school,hq_session,hq_type,'
256            'jamb_score,jamb_subjects,lastname,lga,locked,middlename,'
257            'nationality,notice,nysc_lga,'
258            'nysc_year,password,perm_address,phone,pp_school,presently_inst,'
259            'reg_number,screening_score,screening_venue,sex,state,student_id,'
260            'container_code'
261            in result)
262        self.assertTrue(
263            'Application initialized by system\'],,,,,,,,,Tester,,0,M.,,'
264            '"Some notice\nin lines.",,,any password,,+234-123-12345,,,'
265            '123456,98,Exam Room,f,initialized,,dp2011' in result)
266        return
Note: See TracBrowser for help on using the repository browser.