source: main/kofacustom.skeleton/trunk/src/kofacustom/skeleton/applicants/tests/test_browser.py @ 13587

Last change on this file since 13587 was 13587, checked in by Henrik Bettermann, 9 years ago

Adjust to changes in base packages.

  • Property svn:keywords set to Id
File size: 9.2 KB
Line 
1## $Id: test_browser.py 13587 2016-01-11 09:14:27Z henrik $
2##
3## Copyright (C) 2013 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##
18"""
19Test the applicant-related UI components.
20"""
21import os
22import datetime
23from zope.component import createObject, getUtility
24from zope.catalog.interfaces import ICatalog
25from zope.intid.interfaces import IIntIds
26from hurry.workflow.interfaces import IWorkflowState
27from kofacustom.skeleton.testing import FunctionalLayer
28from waeup.kofa.browser.tests.test_pdf import samples_dir
29from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
30from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup
31from kofacustom.skeleton.applicants.export import CustomApplicantExporter
32from kofacustom.skeleton.applicants.batching import CustomApplicantProcessor
33
34class CustomApplicantUITests(ApplicantsFullSetup):
35    # Tests for uploading/browsing the passport image of appplicants
36
37    layer = FunctionalLayer
38
39class ApplicantExporterTest(ApplicantImportExportSetup):
40
41    layer = FunctionalLayer
42
43    def setUp(self):
44        super(ApplicantExporterTest, self).setUp()
45        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
46        self.cat = getUtility(ICatalog, name='applicants_catalog')
47        self.intids = getUtility(IIntIds)
48        return
49
50    def setup_applicant(self, applicant):
51        # set predictable values for `applicant`
52        applicant.reg_number = u'123456'
53        applicant.applicant_id = u'dp2011_654321'
54        applicant.firstname = u'Anna'
55        applicant.lastname = u'Tester'
56        applicant.middlename = u'M.'
57        applicant.nationality = u'NG'
58        applicant.date_of_birth = datetime.date(1981, 2, 4)
59        applicant.sex = 'f'
60        applicant.email = 'anna@sample.com'
61        applicant.phone = u'+234-123-12345'
62        applicant.course1 = self.certificate
63        applicant.course2 = self.certificate
64        applicant.course_admitted = self.certificate
65        applicant.notice = u'Some notice\nin lines.'
66        applicant.screening_score = 98
67        applicant.screening_venue = u'Exam Room'
68        applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM'
69        applicant.password = 'any password'
70        return applicant
71
72    def test_export_reimport_all(self):
73        # we can export all applicants in a portal
74        # set values we can expect in export file
75        self.applicant = self.setup_applicant(self.applicant)
76        exporter = CustomApplicantExporter()
77        exporter.export_all(self.app, self.outfile)
78        result = open(self.outfile, 'rb').read()
79        self.assertMatches(result,
80            'aggregate,applicant_id,application_date,application_number,'
81            'container_code,course1,course2,course_admitted,date_of_birth,'
82            'display_fullname,email,emp2_end,emp2_position,emp2_reason,'
83            'emp2_start,emp_end,emp_position,emp_reason,emp_start,employer,'
84            'employer2,firstname,fst_sit_date,fst_sit_fname,fst_sit_no,'
85            'fst_sit_results,fst_sit_type,history,hq_degree,hq_disc,'
86            'hq_fname,hq_matric_no,hq_school,hq_session,hq_type,'
87            'jamb_reg_number,jamb_score,jamb_subjects,jamb_subjects_list,'
88            'lastname,lga,locked,middlename,nationality,notice,nysc_lga,'
89            'nysc_year,password,phone,presently_inst,programme_type,'
90            'reg_number,result_uploaded,scd_sit_date,scd_sit_fname,'
91            'scd_sit_no,scd_sit_results,scd_sit_type,screening_date,'
92            'screening_score,screening_venue,sex,special,special_application,'
93            'state,student_id,suspended,translated_state\r\n,'
94            'dp2011_654321,,654321,dp2011,CERT1,CERT1,CERT1,1981-02-04#,'
95            'Anna M. Tester,anna@sample.com,,,,,,,,,,,Anna,,,,,,'
96            '[u\'2016-01-11 10:05:17 WAT - Application initialized by system\']'
97            ',,,,,,,,,,,,Tester,,0,M.,NG,"Some notice\nin lines.",,,'
98            'any password,+234-123-12345#,,,123456,,,,,,,'
99            '"Saturday, 16th June 2012 2:00:00 PM",98,Exam Room,f,,,'
100            'initialized,,0,initialized\r\n')
101        # We can import the same file if we ignore some columns.
102        # Since the applicants_catalog hasn't been notified, the same
103        # record with same reg_number can be imported twice.
104        processor = CustomApplicantProcessor()
105        result = processor.doImport(
106            self.outfile,
107            ['aggregate','ignore_applicant_id','application_date','ignore_application_number',
108             'container_code','course1','course2','course_admitted',
109             'date_of_birth','ignore_display_fullname','email','emp2_end',
110             'emp2_position','emp2_reason','emp2_start','emp_end',
111             'emp_position','emp_reason','emp_start','employer',
112             'employer2','firstname','fst_sit_date','fst_sit_fname',
113             'fst_sit_no','fst_sit_results','fst_sit_type','ignore_history',
114             'hq_degree','hq_disc','hq_fname','hq_matric_no','hq_school',
115             'hq_session','hq_type','jamb_reg_number','jamb_score',
116             'jamb_subjects','jamb_subjects_list','lastname','lga',
117             'locked','middlename','nationality','notice','nysc_lga',
118             'nysc_year','password','phone','presently_inst','programme_type',
119             'reg_number','result_uploaded','scd_sit_date','scd_sit_fname',
120             'scd_sit_no','scd_sit_results','scd_sit_type','screening_date',
121             'screening_score','screening_venue','sex','ignore_special',
122             'special_application','state','student_id','suspended',
123             'translated_state'],
124            mode='create')
125        num_succ, num_fail, finished_path, failed_path = result
126        #content = open(failed_path).read()
127        self.assertEqual(num_succ,1)
128        self.assertEqual(num_fail,0)
129        # Now we ignore also the container_code and import the same file
130        # in update mode which means that INigeriaApplicantUpdateByRegNo
131        # is used for field conversion. applicant_id must be ignored
132        # too since the previous import has notified the applicants_catalog
133        # so that the portal 'knows' that reg_number is in use.
134        processor = CustomApplicantProcessor()
135        result = processor.doImport(
136            self.outfile,
137           ['aggregate','ignore_applicant_id','application_date','ignore_application_number',
138             'ignore_container_code','course1','course2','course_admitted',
139             'date_of_birth','ignore_display_fullname','email','emp2_end',
140             'emp2_position','emp2_reason','emp2_start','emp_end',
141             'emp_position','emp_reason','emp_start','employer',
142             'employer2','firstname','fst_sit_date','fst_sit_fname',
143             'fst_sit_no','fst_sit_results','fst_sit_type','ignore_history',
144             'hq_degree','hq_disc','hq_fname','hq_matric_no','hq_school',
145             'hq_session','hq_type','jamb_reg_number','jamb_score',
146             'jamb_subjects','jamb_subjects_list','lastname','lga',
147             'locked','middlename','nationality','notice','nysc_lga',
148             'nysc_year','password','phone','presently_inst','programme_type',
149             'reg_number','result_uploaded','scd_sit_date','scd_sit_fname',
150             'scd_sit_no','scd_sit_results','scd_sit_type','screening_date',
151             'screening_score','screening_venue','sex','ignore_special',
152             'special_application','state','student_id','suspended',
153             'translated_state'],
154            mode='update')
155        num_succ, num_fail, finished_path, failed_path = result
156        self.assertEqual(num_succ,1)
157        self.assertEqual(num_fail,0)
158        return
159
160class ApplicantsContainerUITests(ApplicantsFullSetup):
161    # Tests for ApplicantsContainer class views and pages
162
163    layer = FunctionalLayer
164
165    def test_applicatio_slip(self):
166        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
167        self.slip_path = self.view_path + '/application_slip.pdf'
168        self.browser.open(self.manage_path)
169        self.assertEqual(self.browser.headers['Status'], '200 Ok')
170        self.fill_correct_values()
171        self.browser.getControl("Save").click()
172        IWorkflowState(self.applicant).setState('submitted')
173        self.browser.open(self.manage_path)
174        self.browser.getLink("Download application slip").click()
175        self.assertEqual(self.browser.headers['Status'], '200 Ok')
176        self.assertEqual(self.browser.headers['Content-Type'],
177                         'application/pdf')
178        path = os.path.join(samples_dir(), 'application_slip.pdf')
179        open(path, 'wb').write(self.browser.contents)
180        print "Sample application_slip.pdf written to %s" % path
Note: See TracBrowser for help on using the repository browser.