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

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

See r8535.

  • Property svn:keywords set to Id
File size: 12.2 KB
RevLine 
[7866]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
[8056]21import datetime
22from zope.intid.interfaces import IIntIds
[7866]23from zope.interface.verify import verifyClass, verifyObject
24from zope.component.hooks import setSite, clearSite
[8056]25from zope.component import createObject, getUtility
26from zope.catalog.interfaces import ICatalog
[8012]27from zope.testbrowser.testing import Browser
[7866]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
[8528]32from waeup.kofa.configuration import SessionConfiguration
[8012]33from waeup.kofa.applicants.container import ApplicantsContainer
[8056]34from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
35from waeup.kofa.interfaces import IBatchProcessor
[8460]36from waeup.fceokene.testing import FunctionalLayer
37from waeup.fceokene.applicants.export import CustomApplicantsExporter
[7866]38
[8056]39
[8012]40class ApplicantUITest(FunctionalTestCase):
41    """Perform some browser tests.
[7866]42    """
43    layer = FunctionalLayer
44
45    def setUp(self):
[8012]46        super(ApplicantUITest, self).setUp()
[7866]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
[8012]62        # Add an two different applicants containers
63        self.pgcontainer = ApplicantsContainer()
[8064]64        self.pgcontainer.code = u'pgft2011'
65        self.pgcontainer.prefix = u'pgft'
[8528]66        self.pgcontainer.year = 2011
67        self.pgcontainer.application_fee = 300.0
68        self.pgcontainer.title = u'This is the pgft2011 container'
[8064]69        self.app['applicants']['pgft2011'] = self.pgcontainer
[8012]70        self.ugcontainer = ApplicantsContainer()
[8528]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'
[8012]76        self.app['applicants']['app2011'] = self.ugcontainer
[7866]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
[8012]89        # Add (customized) applicants
90        pgapplicant = createObject(u'waeup.Applicant')
91        pgapplicant.firstname = u'Anna'
92        pgapplicant.lastname = u'Post'
[8064]93        self.app['applicants']['pgft2011'].addApplicant(pgapplicant)
[8012]94        self.pgapplication_number = pgapplicant.application_number
[8064]95        self.pgapplicant = self.app['applicants']['pgft2011'][
[8012]96            self.pgapplication_number]
[7866]97
[8012]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]
[8528]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)
[8012]109
110        self.browser = Browser()
111        self.browser.handleErrors = False
112
[7866]113    def tearDown(self):
[8012]114        super(ApplicantUITest, self).tearDown()
[7866]115        shutil.rmtree(self.dc_root)
116        clearSite()
117        return
118
[8528]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
[8012]129    def test_manage_and_view_applicant(self):
130        # Managers can manage pg applicants
131        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
[8017]132        # The IPGApplicant interface is really used in all pages
[8528]133        self.browser.open(self.pgapplicant_path)
[8012]134        self.assertEqual(self.browser.headers['Status'], '200 Ok')
135        self.assertTrue('Employer' in self.browser.contents)
[8528]136        self.browser.open(self.pgapplicant_path + '/manage')
[8017]137        self.assertEqual(self.browser.headers['Status'], '200 Ok')
138        self.assertTrue('Employer' in self.browser.contents)
[8528]139        self.browser.open(self.pgapplicant_path + '/edit')
[8017]140        self.assertEqual(self.browser.headers['Status'], '200 Ok')
141        self.assertTrue('Employer' in self.browser.contents)
[8528]142        self.browser.open(self.pgapplicant_path + '/application_slip.pdf')
[8017]143        self.assertEqual(self.browser.headers['Status'], '200 Ok')
[8520]144        # If we view the applicant in the ug container,
[8017]145        # the employer field doesn't appear
[8528]146        self.browser.open(self.ugapplicant_path)
[8012]147        self.assertEqual(self.browser.headers['Status'], '200 Ok')
148        self.assertFalse('Employer' in self.browser.contents)
[8528]149        self.browser.open(self.ugapplicant_path + '/manage')
[8017]150        self.assertEqual(self.browser.headers['Status'], '200 Ok')
[8053]151        # We can save the applicant
[8528]152        self.fill_correct_values()
[8053]153        self.browser.getControl("Save").click()
154        self.assertMatches('...Form has been saved...', self.browser.contents)
[8017]155        self.assertFalse('Employer' in self.browser.contents)
[8528]156        self.browser.open(self.ugapplicant_path + '/edit')
[8017]157        self.assertEqual(self.browser.headers['Status'], '200 Ok')
158        self.assertFalse('Employer' in self.browser.contents)
[8528]159        self.browser.open(self.ugapplicant_path + '/application_slip.pdf')
[8017]160        self.assertEqual(self.browser.headers['Status'], '200 Ok')
[8056]161        return
162
[8528]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
[8056]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)
[8196]244        exporter = CustomApplicantsExporter()
[8056]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,'
[8130]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,'
[8537]256            'jamb_score,jamb_subjects,lastname,lga,locked,middlename,'
257            'nationality,notice,nysc_lga,'
[8130]258            'nysc_year,password,perm_address,phone,pp_school,presently_inst,'
[8531]259            'reg_number,screening_score,screening_venue,sex,state,student_id,'
260            'container_code'
[8056]261            in result)
262        self.assertTrue(
[8537]263            'Application initialized by system\'],,,,,,,,,Tester,,0,M.,,'
[8130]264            '"Some notice\nin lines.",,,any password,,+234-123-12345,,,'
[8531]265            '123456,98,Exam Room,f,initialized,,dp2011' in result)
[8012]266        return
Note: See TracBrowser for help on using the repository browser.