1 | ## $Id: test_browser.py 12086 2014-11-28 09:55:52Z 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 | """ |
---|
19 | Test the applicant-related UI components. |
---|
20 | """ |
---|
21 | import os |
---|
22 | import datetime |
---|
23 | from zope.component import createObject, getUtility |
---|
24 | from zope.catalog.interfaces import ICatalog |
---|
25 | from zope.intid.interfaces import IIntIds |
---|
26 | from hurry.workflow.interfaces import IWorkflowState |
---|
27 | from kofacustom.wdu.testing import FunctionalLayer |
---|
28 | from waeup.kofa.browser.tests.test_pdf import samples_dir |
---|
29 | from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup |
---|
30 | from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup |
---|
31 | from kofacustom.wdu.applicants.export import CustomApplicantExporter |
---|
32 | from kofacustom.wdu.applicants.batching import CustomApplicantProcessor |
---|
33 | |
---|
34 | class CustomApplicantUITests(ApplicantsFullSetup): |
---|
35 | # Tests for uploading/browsing the passport image of appplicants |
---|
36 | |
---|
37 | layer = FunctionalLayer |
---|
38 | |
---|
39 | class 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 | 'course1,course2,course_admitted,date_of_birth,display_fullname,' |
---|
82 | 'email,emp2_end,emp2_position,emp2_reason,emp2_start,emp_end,' |
---|
83 | 'emp_position,emp_reason,emp_start,employer,employer2,' |
---|
84 | 'firstname,history,hq_degree,hq_disc,hq_matric_no,hq_school,' |
---|
85 | 'hq_session,hq_type,jamb_age,jamb_score,jamb_subjects,lastname,lga,' |
---|
86 | 'locked,middlename,nationality,notice,nysc_lga,nysc_year,' |
---|
87 | 'password,phone,pp_school,presently_inst,reg_number,' |
---|
88 | 'result_uploaded,screening_date,screening_score,' |
---|
89 | 'screening_venue,sex,special_application,' |
---|
90 | 'state,student_id,suspended,container_code\r\n' |
---|
91 | ',dp2011_654321,,654321,CERT1,CERT1,CERT1,1981-02-04#,' |
---|
92 | 'Anna M. Tester,anna@sample.com,,,,,,,,,,,Anna,' |
---|
93 | '[u\'2012-10-28 21:27:52 WAT - Application initialized by system\']' |
---|
94 | ',,,,,,,,,,Tester,,0,M.,NG,"Some notice\nin lines.",,,' |
---|
95 | 'any password,+234-123-12345#,,,123456,,' |
---|
96 | '"Saturday, 16th June 2012 2:00:00 PM",98,Exam Room,f,,initialized,,' |
---|
97 | '0,dp2011\r\n') |
---|
98 | # We can import the same file if we ignore some columns. |
---|
99 | # Since the applicants_catalog hasn't been notified, the same |
---|
100 | # record with same reg_number can be imported twice. |
---|
101 | processor = CustomApplicantProcessor() |
---|
102 | result = processor.doImport( |
---|
103 | self.outfile, |
---|
104 | ['aggreagate','ignore_applicant_id','application_date', |
---|
105 | 'ignore_application_number','course1','course2', |
---|
106 | 'course_admitted','date_of_birth','ignore3','email','emp2_end', |
---|
107 | 'emp2_position','emp2_reason','emp2_start','emp_end','emp_position', |
---|
108 | 'emp_reason','emp_start','employer','employer2','firstname','ignore4', |
---|
109 | 'hq_degree','hq_disc','hq_matric_no','hq_school','hq_session','hq_type', |
---|
110 | 'jamb_age','jamb_score','jamb_subjects','lastname','lga','locked','middlename', |
---|
111 | 'nationality','notice','nysc_lga', |
---|
112 | 'nysc_year','password','phone','pp_school','presently_inst', |
---|
113 | 'reg_number','result_uploaded', |
---|
114 | 'screening_date','screening_score','screening_venue','sex', |
---|
115 | 'special_application', |
---|
116 | 'state','student_id','suspended','container_code'], |
---|
117 | mode='create') |
---|
118 | num_succ, num_fail, finished_path, failed_path = result |
---|
119 | #content = open(failed_path).read() |
---|
120 | self.assertEqual(num_succ,1) |
---|
121 | self.assertEqual(num_fail,0) |
---|
122 | # Now we ignore also the container_code and import the same file |
---|
123 | # in update mode which means that INigeriaApplicantUpdateByRegNo |
---|
124 | # is used for field conversion. applicant_id must be ignored |
---|
125 | # too since the previous import has notified the applicants_catalog |
---|
126 | # so that the portal 'knows' that reg_number is in use. |
---|
127 | processor = CustomApplicantProcessor() |
---|
128 | result = processor.doImport( |
---|
129 | self.outfile, |
---|
130 | ['aggregate','ignore_applicant_id','application_date', |
---|
131 | 'ignore_application_number','course1','course2', |
---|
132 | 'course_admitted','date_of_birth','ignore3','email','emp2_end', |
---|
133 | 'emp2_position','emp2_reason','emp2_start','emp_end','emp_position', |
---|
134 | 'emp_reason','emp_start','employer','employer2','firstname','ignore4', |
---|
135 | 'hq_degree','hq_disc','hq_matric_no','hq_school','hq_session','hq_type', |
---|
136 | 'jamb_age','jamb_score','jamb_subjects','lastname','lga','locked','middlename', |
---|
137 | 'nationality','notice','nysc_lga', |
---|
138 | 'nysc_year','password','phone','pp_school','presently_inst', |
---|
139 | 'reg_number','result_uploaded','screening_date','screening_score', |
---|
140 | 'screening_venue','sex','special_application', |
---|
141 | 'state','student_id','suspended','ignore_container_code'], |
---|
142 | mode='update') |
---|
143 | num_succ, num_fail, finished_path, failed_path = result |
---|
144 | self.assertEqual(num_succ,1) |
---|
145 | self.assertEqual(num_fail,0) |
---|
146 | return |
---|
147 | |
---|
148 | |
---|
149 | class ApplicantsContainerUITests(ApplicantsFullSetup): |
---|
150 | # Tests for ApplicantsContainer class views and pages |
---|
151 | |
---|
152 | layer = FunctionalLayer |
---|
153 | |
---|
154 | def test_application_slip(self): |
---|
155 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
156 | self.slip_path = self.view_path + '/application_slip.pdf' |
---|
157 | self.browser.open(self.manage_path) |
---|
158 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
159 | self.fill_correct_values() |
---|
160 | self.browser.getControl("Save").click() |
---|
161 | IWorkflowState(self.applicant).setState('submitted') |
---|
162 | self.browser.open(self.manage_path) |
---|
163 | self.browser.getLink("Download application slip").click() |
---|
164 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
165 | self.assertEqual(self.browser.headers['Content-Type'], |
---|
166 | 'application/pdf') |
---|
167 | path = os.path.join(samples_dir(), 'application_slip.pdf') |
---|
168 | open(path, 'wb').write(self.browser.contents) |
---|
169 | print "Sample application_slip.pdf written to %s" % path |
---|