1 | ## $Id: test_browser.py 13979 2016-06-23 10:05:58Z 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 | ## |
---|
18 | import os |
---|
19 | import shutil |
---|
20 | import tempfile |
---|
21 | import datetime |
---|
22 | import grok |
---|
23 | import pytz |
---|
24 | from zope.event import notify |
---|
25 | from zope.intid.interfaces import IIntIds |
---|
26 | from zope.interface.verify import verifyClass, verifyObject |
---|
27 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
28 | from zope.component.hooks import setSite, clearSite |
---|
29 | from zope.component import createObject, getUtility |
---|
30 | from zope.catalog.interfaces import ICatalog |
---|
31 | from zope.testbrowser.testing import Browser |
---|
32 | from hurry.workflow.interfaces import IWorkflowState |
---|
33 | from waeup.kofa.app import University |
---|
34 | from waeup.kofa.university.faculty import Faculty |
---|
35 | from waeup.kofa.university.department import Department |
---|
36 | from waeup.kofa.testing import FunctionalTestCase |
---|
37 | from waeup.kofa.configuration import SessionConfiguration |
---|
38 | from waeup.kofa.applicants.container import ApplicantsContainer |
---|
39 | from waeup.kofa.applicants.tests.test_batching import ApplicantImportExportSetup |
---|
40 | from waeup.kofa.interfaces import IBatchProcessor, IUserAccount |
---|
41 | from kofacustom.nigeria.testing import FunctionalLayer |
---|
42 | from kofacustom.nigeria.applicants.export import NigeriaApplicantExporter |
---|
43 | from kofacustom.nigeria.applicants.batching import NigeriaApplicantProcessor |
---|
44 | |
---|
45 | session_1 = datetime.datetime.now().year - 2 |
---|
46 | app_container_name = u'app%s' % session_1 |
---|
47 | pgft_container_name = u'pgft%s' % session_1 |
---|
48 | cbt_container_name = u'cbt%s' % session_1 |
---|
49 | |
---|
50 | class ApplicantUITest(FunctionalTestCase): |
---|
51 | """Perform some browser tests. |
---|
52 | """ |
---|
53 | layer = FunctionalLayer |
---|
54 | |
---|
55 | def setUp(self): |
---|
56 | super(ApplicantUITest, self).setUp() |
---|
57 | # Setup a sample site for each test |
---|
58 | app = University() |
---|
59 | self.dc_root = tempfile.mkdtemp() |
---|
60 | app['datacenter'].setStoragePath(self.dc_root) |
---|
61 | |
---|
62 | # Prepopulate the ZODB... |
---|
63 | self.getRootFolder()['app'] = app |
---|
64 | # we add the site immediately after creation to the |
---|
65 | # ZODB. Catalogs and other local utilities are not setup |
---|
66 | # before that step. |
---|
67 | self.app = self.getRootFolder()['app'] |
---|
68 | # Set site here. Some of the following setup code might need |
---|
69 | # to access grok.getSite() and should get our new app then |
---|
70 | setSite(app) |
---|
71 | |
---|
72 | # Add three different applicants containers |
---|
73 | self.pgcontainer = ApplicantsContainer() |
---|
74 | self.pgcontainer.code = pgft_container_name |
---|
75 | self.pgcontainer.prefix = u'pgft' |
---|
76 | self.pgcontainer.application_category = u'pg_ft' |
---|
77 | self.pgcontainer.year = session_1 |
---|
78 | self.pgcontainer.application_fee = 300.0 |
---|
79 | self.pgcontainer.title = u'This is the %s container' % pgft_container_name |
---|
80 | self.app['applicants'][pgft_container_name] = self.pgcontainer |
---|
81 | |
---|
82 | self.ugcontainer = ApplicantsContainer() |
---|
83 | self.ugcontainer.code = app_container_name |
---|
84 | self.ugcontainer.prefix = u'app' |
---|
85 | self.ugcontainer.application_category = u'basic' |
---|
86 | self.ugcontainer.year = session_1 |
---|
87 | self.ugcontainer.application_fee = 200.0 |
---|
88 | self.ugcontainer.title = u'This is the %s container' % app_container_name |
---|
89 | self.app['applicants'][app_container_name] = self.ugcontainer |
---|
90 | self.ugcontainer.mode = 'update' |
---|
91 | delta = datetime.timedelta(days=10) |
---|
92 | self.ugcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
93 | self.ugcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
94 | |
---|
95 | self.cbtcontainer = ApplicantsContainer() |
---|
96 | self.cbtcontainer.code = cbt_container_name |
---|
97 | self.cbtcontainer.prefix = u'cbt' |
---|
98 | self.cbtcontainer.application_category = u'basic' |
---|
99 | self.cbtcontainer.year = session_1 |
---|
100 | self.cbtcontainer.application_fee = 300.0 |
---|
101 | self.cbtcontainer.title = u'This is the %s container' % cbt_container_name |
---|
102 | self.app['applicants'][cbt_container_name] = self.cbtcontainer |
---|
103 | self.cbtcontainer.mode = 'update' |
---|
104 | delta = datetime.timedelta(days=10) |
---|
105 | self.cbtcontainer.startdate = datetime.datetime.now(pytz.utc) - delta |
---|
106 | self.cbtcontainer.enddate = datetime.datetime.now(pytz.utc) + delta |
---|
107 | |
---|
108 | # Populate university |
---|
109 | self.certificate = createObject('waeup.Certificate') |
---|
110 | self.certificate.code = 'CERT1' |
---|
111 | self.certificate.application_category = 'basic' |
---|
112 | self.certificate.start_level = 100 |
---|
113 | self.certificate.end_level = 500 |
---|
114 | self.certificate.study_mode = u'ug_ft' |
---|
115 | self.app['faculties']['fac1'] = Faculty() |
---|
116 | self.app['faculties']['fac1']['dep1'] = Department() |
---|
117 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
118 | self.certificate) |
---|
119 | self.certificate2 = createObject('waeup.Certificate') |
---|
120 | self.certificate2.code = 'CERT2' |
---|
121 | self.certificate2.application_category = 'pg_ft' |
---|
122 | self.certificate2.start_level = 100 |
---|
123 | self.certificate2.end_level = 500 |
---|
124 | self.certificate.study_mode = u'pg_ft' |
---|
125 | self.app['faculties']['fac1']['dep1'].certificates.addCertificate( |
---|
126 | self.certificate2) |
---|
127 | |
---|
128 | # Add (customized) applicants |
---|
129 | pgapplicant = createObject(u'waeup.Applicant') |
---|
130 | pgapplicant.firstname = u'Anna' |
---|
131 | pgapplicant.lastname = u'Post' |
---|
132 | self.app['applicants'][pgft_container_name].addApplicant(pgapplicant) |
---|
133 | self.pgapplication_number = pgapplicant.application_number |
---|
134 | self.pgapplicant = self.app['applicants'][pgft_container_name][ |
---|
135 | self.pgapplication_number] |
---|
136 | |
---|
137 | ugapplicant = createObject(u'waeup.Applicant') |
---|
138 | ugapplicant.firstname = u'Klaus' |
---|
139 | ugapplicant.lastname = u'Under' |
---|
140 | self.app['applicants'][app_container_name].addApplicant(ugapplicant) |
---|
141 | self.ugapplication_number = ugapplicant.application_number |
---|
142 | self.ugapplicant = self.app['applicants'][app_container_name][ |
---|
143 | self.ugapplication_number] |
---|
144 | |
---|
145 | cbtapplicant = createObject(u'waeup.Applicant') |
---|
146 | cbtapplicant.firstname = u'Anna' |
---|
147 | cbtapplicant.lastname = u'Cbt' |
---|
148 | self.app['applicants'][cbt_container_name].addApplicant(cbtapplicant) |
---|
149 | self.cbtapplication_number = cbtapplicant.application_number |
---|
150 | self.cbtapplicant = self.app['applicants'][cbt_container_name][ |
---|
151 | self.cbtapplication_number] |
---|
152 | IUserAccount(self.cbtapplicant).setPassword('apwd') |
---|
153 | |
---|
154 | self.login_path = 'http://localhost/app/login' |
---|
155 | self.logout_path = 'http://localhost/app/logout' |
---|
156 | self.pgapplicant_path = ('http://localhost/app/applicants/%s/%s' |
---|
157 | % (pgft_container_name, self.pgapplication_number)) |
---|
158 | self.ugapplicant_path = ('http://localhost/app/applicants/%s/%s' |
---|
159 | % (app_container_name, self.ugapplication_number)) |
---|
160 | self.cbtapplicant_path = ('http://localhost/app/applicants/%s/%s' |
---|
161 | % (cbt_container_name, self.cbtapplication_number)) |
---|
162 | |
---|
163 | self.browser = Browser() |
---|
164 | self.browser.handleErrors = False |
---|
165 | |
---|
166 | configuration = SessionConfiguration() |
---|
167 | configuration.academic_session = session_1 |
---|
168 | configuration.application_fee = 200.0 |
---|
169 | self.app['configuration'].addSessionConfiguration(configuration) |
---|
170 | |
---|
171 | def tearDown(self): |
---|
172 | super(ApplicantUITest, self).tearDown() |
---|
173 | shutil.rmtree(self.dc_root) |
---|
174 | clearSite() |
---|
175 | return |
---|
176 | |
---|
177 | def fill_correct_values(self): |
---|
178 | self.browser.getControl(name="form.reg_number").value = '1234' |
---|
179 | self.browser.getControl(name="form.firstname").value = 'John' |
---|
180 | self.browser.getControl(name="form.lastname").value = 'Tester' |
---|
181 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
182 | self.browser.getControl(name="form.lga").value = ['foreigner'] |
---|
183 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
184 | self.browser.getControl(name="form.sex").value = ['m'] |
---|
185 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
186 | |
---|
187 | def test_manage_and_view_applicant(self): |
---|
188 | # Managers can manage pg applicants. |
---|
189 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
190 | # The IPGApplicant interface is really used in all pages. |
---|
191 | self.browser.open(self.pgapplicant_path) |
---|
192 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
193 | self.assertTrue('Employer' in self.browser.contents) |
---|
194 | self.browser.open(self.pgapplicant_path + '/manage') |
---|
195 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
196 | self.assertTrue('Employer' in self.browser.contents) |
---|
197 | self.browser.open(self.pgapplicant_path + '/edit') |
---|
198 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
199 | self.assertTrue('Employer' in self.browser.contents) |
---|
200 | self.browser.open(self.pgapplicant_path + '/application_slip.pdf') |
---|
201 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
202 | # If we view the applicant in the ug container, |
---|
203 | # the employer field doesn't appear. |
---|
204 | self.browser.open(self.ugapplicant_path) |
---|
205 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
206 | self.assertFalse('Employer' in self.browser.contents) |
---|
207 | self.browser.open(self.ugapplicant_path + '/manage') |
---|
208 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
209 | # We can save the applicant. |
---|
210 | self.fill_correct_values() |
---|
211 | self.browser.getControl(name="form.course1").value = ['CERT1'] |
---|
212 | self.browser.getControl("Save").click() |
---|
213 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
214 | self.assertFalse('Employer' in self.browser.contents) |
---|
215 | self.browser.open(self.ugapplicant_path + '/edit') |
---|
216 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
217 | self.assertFalse('Employer' in self.browser.contents) |
---|
218 | self.browser.open(self.ugapplicant_path + '/application_slip.pdf') |
---|
219 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
220 | return |
---|
221 | |
---|
222 | def test_set_wrong_course1(self): |
---|
223 | self.ugapplicant.course1 = self.certificate |
---|
224 | self.assertRaises( |
---|
225 | ConstraintNotSatisfied, |
---|
226 | setattr, self.ugapplicant, 'course1', self.certificate2) |
---|
227 | self.pgapplicant.course1 = self.certificate2 |
---|
228 | self.assertRaises( |
---|
229 | ConstraintNotSatisfied, |
---|
230 | setattr, self.pgapplicant, 'course1', self.certificate) |
---|
231 | return |
---|
232 | |
---|
233 | def test_application_payment(self): |
---|
234 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
235 | |
---|
236 | # UG (UTME) applicant |
---|
237 | self.browser.open(self.ugapplicant_path) |
---|
238 | self.browser.open(self.ugapplicant_path + '/manage') |
---|
239 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
240 | self.fill_correct_values() |
---|
241 | self.browser.getControl(name="form.course1").value = ['CERT1'] |
---|
242 | self.browser.getControl("Save").click() |
---|
243 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
244 | self.browser.getControl("Add online payment ticket").click() |
---|
245 | self.assertMatches('...Payment ticket created...', |
---|
246 | self.browser.contents) |
---|
247 | self.assertMatches('...Amount Authorized...', |
---|
248 | self.browser.contents) |
---|
249 | payment_id = self.ugapplicant.keys()[0] |
---|
250 | payment = self.ugapplicant[payment_id] |
---|
251 | self.assertEqual(payment.p_item,'This is the %s container' % app_container_name) |
---|
252 | self.assertEqual(payment.p_session,session_1) |
---|
253 | self.assertEqual(payment.p_category,'application') |
---|
254 | self.assertEqual(payment.amount_auth, 200.0) |
---|
255 | |
---|
256 | # PG applicants pay more |
---|
257 | self.browser.open(self.pgapplicant_path) |
---|
258 | self.browser.open(self.pgapplicant_path + '/manage') |
---|
259 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
260 | self.fill_correct_values() |
---|
261 | self.browser.getControl(name="form.course1").value = ['CERT2'] |
---|
262 | self.browser.getControl(name="form.reg_number").value = '2345' |
---|
263 | self.browser.getControl(name="form.firstname").value = 'Anna' |
---|
264 | self.browser.getControl("Save").click() |
---|
265 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
266 | self.browser.getControl("Add online payment ticket").click() |
---|
267 | self.assertMatches('...Payment ticket created...', |
---|
268 | self.browser.contents) |
---|
269 | self.assertMatches('...Amount Authorized...', |
---|
270 | self.browser.contents) |
---|
271 | payment_id = self.pgapplicant.keys()[0] |
---|
272 | payment = self.pgapplicant[payment_id] |
---|
273 | self.assertEqual(payment.p_item,'This is the %s container' % pgft_container_name) |
---|
274 | self.assertEqual(payment.p_session,session_1) |
---|
275 | self.assertEqual(payment.p_category,'application') |
---|
276 | self.assertEqual(payment.amount_auth, 300.0) |
---|
277 | return |
---|
278 | |
---|
279 | def test_hide_screening_data(self): |
---|
280 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
281 | self.browser.open(self.ugapplicant_path + '/manage') |
---|
282 | self.assertEqual(self.browser.headers['Status'], '200 Ok') |
---|
283 | self.fill_correct_values() |
---|
284 | self.browser.getControl(name="form.screening_venue").value = 'Mensa' |
---|
285 | self.browser.getControl(name="form.screening_date").value = 'Easter' |
---|
286 | self.browser.getControl(name="form.course1").value = ['CERT1'] |
---|
287 | self.browser.getControl("Save").click() |
---|
288 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
289 | self.browser.getControl("Save").click() |
---|
290 | # Venue and date are not shown |
---|
291 | self.browser.open(self.ugapplicant_path) |
---|
292 | self.assertFalse('Screening' in self.browser.contents) |
---|
293 | IWorkflowState(self.ugapplicant).setState('paid') |
---|
294 | # Venue and date are shown if applicant has paid |
---|
295 | self.browser.open(self.ugapplicant_path) |
---|
296 | self.assertTrue('Screening' in self.browser.contents) |
---|
297 | return |
---|
298 | |
---|
299 | def test_register_applicant_update(self): |
---|
300 | # An applicant can register himself. |
---|
301 | self.ugapplicant.reg_number = u'1234' |
---|
302 | notify(grok.ObjectModifiedEvent(self.ugapplicant)) |
---|
303 | self.browser.open('http://localhost/app/applicants/%s/' % app_container_name) |
---|
304 | self.browser.getLink("Register for application").click() |
---|
305 | # Fill the edit form with suitable values |
---|
306 | self.browser.getControl(name="form.lastname").value = 'Under' |
---|
307 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
308 | self.browser.getControl(name="form.reg_number").value = '1234' |
---|
309 | self.browser.getControl("Send login credentials").click() |
---|
310 | self.assertMatches('...Your registration was successful...', |
---|
311 | self.browser.contents) |
---|
312 | self.assertFalse('...<td>Password:</td>...' in self.browser.contents) |
---|
313 | # The new applicant can be found in the catalog via the email address |
---|
314 | cat = getUtility(ICatalog, name='applicants_catalog') |
---|
315 | results = list( |
---|
316 | cat.searchResults(email=('xx@yy.zz', 'xx@yy.zz'))) |
---|
317 | applicant = results[0] |
---|
318 | self.assertEqual(applicant.lastname,'Under') |
---|
319 | # The applicant can be found in the catalog via the reg_number |
---|
320 | results = list( |
---|
321 | cat.searchResults( |
---|
322 | reg_number=(applicant.reg_number, applicant.reg_number))) |
---|
323 | self.assertEqual(applicant,results[0]) |
---|
324 | return |
---|
325 | |
---|
326 | def test_create_ugstudent(self): |
---|
327 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
328 | manage_path = 'http://localhost/app/applicants/%s/%s/%s' % ( |
---|
329 | app_container_name, self.ugapplicant.application_number, 'manage') |
---|
330 | self.browser.open(manage_path) |
---|
331 | self.fill_correct_values() |
---|
332 | self.browser.getControl("Save").click() |
---|
333 | IWorkflowState(self.ugapplicant).setState('admitted') |
---|
334 | self.browser.getControl(name="form.course1").value = ['CERT1'] |
---|
335 | self.browser.getControl(name="form.course_admitted").value = ['CERT1'] |
---|
336 | self.browser.getControl("Save").click() |
---|
337 | self.browser.getLink("Create student").click() |
---|
338 | student_id = self.app['students'].keys()[0] |
---|
339 | self.assertTrue(('Student %s created' % student_id) |
---|
340 | in self.browser.contents) |
---|
341 | student = self.app['students'][student_id] |
---|
342 | self.assertEqual(student.email, 'xx@yy.zz') |
---|
343 | self.assertEqual(student.firstname, 'John') |
---|
344 | self.assertEqual(student.lastname, 'Tester') |
---|
345 | # Also additional attributes have been copied. |
---|
346 | self.assertEqual(student.lga, 'foreigner') |
---|
347 | self.assertEqual(student.nationality, 'NG') |
---|
348 | return |
---|
349 | |
---|
350 | def test_applicant_access(self): |
---|
351 | # Applicants can edit their record |
---|
352 | self.browser.open(self.login_path) |
---|
353 | self.browser.getControl( |
---|
354 | name="form.login").value = self.cbtapplicant.applicant_id |
---|
355 | self.browser.getControl(name="form.password").value = 'apwd' |
---|
356 | self.browser.getControl("Login").click() |
---|
357 | self.assertTrue( |
---|
358 | 'You logged in.' in self.browser.contents) |
---|
359 | self.browser.getLink("Edit application record").click() |
---|
360 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
361 | self.browser.getControl(name="form.lga").value = ['foreigner'] |
---|
362 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
363 | self.browser.getControl(name="form.sex").value = ['m'] |
---|
364 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
365 | self.browser.getControl(name="form.course1").value = ['CERT1'] |
---|
366 | self.browser.getControl("Save").click() |
---|
367 | #self.assertMatches('...Not exactly 4 items selected...', self.browser.contents) |
---|
368 | # Since the testbrowser does not support Javascrip we can't test the |
---|
369 | # save action which clears jamb_subjects_list on the edit form page |
---|
370 | # An error would be raised. |
---|
371 | |
---|
372 | # If we login as manager, we can use the manage form page. |
---|
373 | self.browser.open(self.logout_path) |
---|
374 | self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') |
---|
375 | self.cbtapplicant.jamb_subjects_list = [ |
---|
376 | 'english_language', 'fine_art', 'mathematics', 'physics'] |
---|
377 | self.browser.open(self.cbtapplicant_path + '/manage') |
---|
378 | self.browser.getControl(name="form.date_of_birth").value = '09/09/1988' |
---|
379 | self.browser.getControl(name="form.lga").value = ['foreigner'] |
---|
380 | self.browser.getControl(name="form.nationality").value = ['NG'] |
---|
381 | self.browser.getControl(name="form.sex").value = ['m'] |
---|
382 | self.browser.getControl(name="form.email").value = 'xx@yy.zz' |
---|
383 | self.browser.getControl(name="form.course1").value = ['CERT1'] |
---|
384 | self.browser.getControl(name="form.reg_number").value = '1234' |
---|
385 | self.browser.getControl("Save").click() |
---|
386 | self.assertMatches('...Form has been saved...', self.browser.contents) |
---|
387 | # The save action on this form pages, if called with the testbrowser, |
---|
388 | # replaces jamb_subjects_list by an empty list (and not by None). |
---|
389 | self.assertEqual(self.cbtapplicant.jamb_subjects_list, []) |
---|
390 | |
---|
391 | class ApplicantExporterTest(ApplicantImportExportSetup): |
---|
392 | |
---|
393 | layer = FunctionalLayer |
---|
394 | |
---|
395 | def setUp(self): |
---|
396 | super(ApplicantExporterTest, self).setUp() |
---|
397 | self.outfile = os.path.join(self.workdir, 'myoutput.csv') |
---|
398 | self.cat = getUtility(ICatalog, name='applicants_catalog') |
---|
399 | self.intids = getUtility(IIntIds) |
---|
400 | return |
---|
401 | |
---|
402 | def setup_applicant(self, applicant): |
---|
403 | # set predictable values for `applicant` |
---|
404 | applicant.reg_number = u'123456' |
---|
405 | applicant.applicant_id = u'dp2011_654321' |
---|
406 | applicant.firstname = u'Anna' |
---|
407 | applicant.lastname = u'Tester' |
---|
408 | applicant.middlename = u'M.' |
---|
409 | applicant.nationality = u'NG' |
---|
410 | applicant.date_of_birth = datetime.date(1981, 2, 4) |
---|
411 | applicant.sex = 'f' |
---|
412 | applicant.email = 'anna@sample.com' |
---|
413 | applicant.phone = u'+234-123-12345' |
---|
414 | applicant.course1 = self.certificate |
---|
415 | applicant.course2 = self.certificate |
---|
416 | applicant.course_admitted = self.certificate |
---|
417 | applicant.notice = u'Some notice\nin lines.' |
---|
418 | applicant.jamb_subjects = u'Line 1\nLine 2' |
---|
419 | applicant.jamb_subjects_list = ['english_language', 'fine_art'] |
---|
420 | applicant.screening_score = 98 |
---|
421 | applicant.screening_venue = u'Exam Room' |
---|
422 | applicant.screening_date = u'Saturday, 16th June 2012 2:00:00 PM' |
---|
423 | applicant.password = 'any password' |
---|
424 | return applicant |
---|
425 | |
---|
426 | def test_export_reimport_all(self): |
---|
427 | # we can export all applicants in a portal |
---|
428 | # set values we can expect in export file |
---|
429 | self.applicant = self.setup_applicant(self.applicant) |
---|
430 | exporter = NigeriaApplicantExporter() |
---|
431 | exporter.export_all(self.app, self.outfile) |
---|
432 | result = open(self.outfile, 'rb').read() |
---|
433 | self.assertMatches(result, |
---|
434 | 'aggregate,applicant_id,course1,course2,course_admitted,' |
---|
435 | 'date_of_birth,email,emp2_end,emp2_position,emp2_reason,' |
---|
436 | 'emp2_start,emp_end,emp_position,emp_reason,emp_start,employer,' |
---|
437 | 'employer2,firstname,fst_sit_date,fst_sit_fname,fst_sit_no,' |
---|
438 | 'fst_sit_results,fst_sit_type,hq_degree,hq_disc,hq_fname,' |
---|
439 | 'hq_matric_no,hq_school,hq_session,hq_type,jamb_reg_number,' |
---|
440 | 'jamb_score,jamb_subjects,jamb_subjects_list,lastname,lga,' |
---|
441 | 'locked,middlename,nationality,notice,nysc_lga,nysc_year,' |
---|
442 | 'phone,presently_inst,programme_type,reg_number,result_uploaded,' |
---|
443 | 'scd_sit_date,scd_sit_fname,scd_sit_no,scd_sit_results,' |
---|
444 | 'scd_sit_type,screening_date,screening_score,screening_venue,' |
---|
445 | 'sex,special_application,student_id,suspended,password,state,' |
---|
446 | 'history,container_code,application_number,display_fullname,' |
---|
447 | 'application_date\r\n' |
---|
448 | |
---|
449 | ',dp2011_654321,CERT1,CERT1,CERT1,1981-02-04#,' |
---|
450 | 'anna@sample.com,,,,,,,,,,,Anna,,,,,,,,,,,,,,,' |
---|
451 | 'Line 1++Line 2,"[\'english_language\', \'fine_art\']",' |
---|
452 | 'Tester,,0,M.,NG,"Some notice\nin lines.",,,' |
---|
453 | '+234-123-12345#,,,123456,,,,,,,' |
---|
454 | '"Saturday, 16th June 2012 2:00:00 PM",98,Exam Room,f,,,' |
---|
455 | '0,any password,initialized,' |
---|
456 | '[u\'2016-06-23 10:58:23 WAT - Application initialized by system\'],' |
---|
457 | 'dp2011,654321,Anna M. Tester,\r\n') |
---|
458 | # We can import the same file if we ignore some columns. |
---|
459 | # Since the applicants_catalog hasn't been notified, the same |
---|
460 | # record with same reg_number can be imported twice. |
---|
461 | processor = NigeriaApplicantProcessor() |
---|
462 | result = processor.doImport( |
---|
463 | self.outfile, |
---|
464 | [ |
---|
465 | 'aggregate','ignore_applicant_id','course1','course2','course_admitted', |
---|
466 | 'date_of_birth','email','emp2_end','emp2_position','emp2_reason', |
---|
467 | 'emp2_start','emp_end','emp_position','emp_reason','emp_start','employer', |
---|
468 | 'employer2','firstname','fst_sit_date','fst_sit_fname','fst_sit_no', |
---|
469 | 'fst_sit_results','fst_sit_type','hq_degree','hq_disc','hq_fname', |
---|
470 | 'hq_matric_no','hq_school','hq_session','hq_type','jamb_reg_number', |
---|
471 | 'jamb_score','jamb_subjects','jamb_subjects_list','lastname','lga', |
---|
472 | 'locked','middlename','nationality','notice','nysc_lga','nysc_year', |
---|
473 | 'phone','presently_inst','programme_type','reg_number','result_uploaded', |
---|
474 | 'scd_sit_date','scd_sit_fname','scd_sit_no','scd_sit_results', |
---|
475 | 'scd_sit_type','screening_date','screening_score','screening_venue', |
---|
476 | 'sex','special_application','student_id','suspended','password','state', |
---|
477 | 'ignore_history','container_code','ignore_application_number','display_fullname', |
---|
478 | 'application_date' |
---|
479 | ], |
---|
480 | mode='create') |
---|
481 | num_succ, num_fail, finished_path, failed_path = result |
---|
482 | #content = open(failed_path).read() |
---|
483 | self.assertEqual(num_succ,1) |
---|
484 | self.assertEqual(num_fail,0) |
---|
485 | # Now we ignore also the container_code and import the same file |
---|
486 | # in update mode which means that INigeriaApplicantUpdateByRegNo |
---|
487 | # is used for field conversion. applicant_id must be ignored |
---|
488 | # too since the previous import has notified the applicants_catalog |
---|
489 | # so that the portal 'knows' that reg_number is in use. |
---|
490 | processor = NigeriaApplicantProcessor() |
---|
491 | result = processor.doImport( |
---|
492 | self.outfile, |
---|
493 | [ |
---|
494 | 'aggregate','ignore_applicant_id','course1','course2','course_admitted', |
---|
495 | 'date_of_birth','email','emp2_end','emp2_position','emp2_reason', |
---|
496 | 'emp2_start','emp_end','emp_position','emp_reason','emp_start','employer', |
---|
497 | 'employer2','firstname','fst_sit_date','fst_sit_fname','fst_sit_no', |
---|
498 | 'fst_sit_results','fst_sit_type','hq_degree','hq_disc','hq_fname', |
---|
499 | 'hq_matric_no','hq_school','hq_session','hq_type','jamb_reg_number', |
---|
500 | 'jamb_score','jamb_subjects','jamb_subjects_list','lastname','lga', |
---|
501 | 'locked','middlename','nationality','notice','nysc_lga','nysc_year', |
---|
502 | 'phone','presently_inst','programme_type','reg_number','result_uploaded', |
---|
503 | 'scd_sit_date','scd_sit_fname','scd_sit_no','scd_sit_results', |
---|
504 | 'scd_sit_type','screening_date','screening_score','screening_venue', |
---|
505 | 'sex','special_application','student_id','suspended','password','state', |
---|
506 | 'ignore_history','ignore_container_code','ignore_application_number', |
---|
507 | 'display_fullname','application_date' |
---|
508 | ], |
---|
509 | mode='update') |
---|
510 | num_succ, num_fail, finished_path, failed_path = result |
---|
511 | self.assertEqual(num_succ,1) |
---|
512 | self.assertEqual(num_fail,0) |
---|
513 | return |
---|