source: main/waeup.aaue/trunk/src/waeup/aaue/students/tests/test_browser.py @ 13441

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

revert to the old Interswitch surcharge.

  • Property svn:keywords set to Id
File size: 29.5 KB
Line 
1## $Id: test_browser.py 13438 2015-11-11 19:49:12Z 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 pytz
22import grok
23from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
24from datetime import datetime, timedelta, date
25from mechanize import LinkNotFoundError
26from hurry.workflow.interfaces import IWorkflowState
27from zope.event import notify
28from zope.component.hooks import setSite, clearSite
29from zope.component import getUtility, createObject, queryUtility
30from zope.catalog.interfaces import ICatalog
31from waeup.kofa.app import University
32from waeup.kofa.students.tests.test_browser import StudentsFullSetup
33from waeup.kofa.students.accommodation import BedTicket
34from waeup.kofa.testing import FunctionalTestCase
35from waeup.kofa.browser.tests.test_pdf import samples_dir
36from waeup.aaue.testing import FunctionalLayer
37
38SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), 'test_image.jpg')
39
40
41class StudentProcessorTest(FunctionalTestCase):
42    """Perform some batching tests.
43    """
44
45    layer = FunctionalLayer
46
47    def setUp(self):
48        super(StudentProcessorTest, self).setUp()
49        # Setup a sample site for each test
50        app = University()
51        self.dc_root = tempfile.mkdtemp()
52        app['datacenter'].setStoragePath(self.dc_root)
53
54        # Prepopulate the ZODB...
55        self.getRootFolder()['app'] = app
56        # we add the site immediately after creation to the
57        # ZODB. Catalogs and other local utilities are not setup
58        # before that step.
59        self.app = self.getRootFolder()['app']
60        # Set site here. Some of the following setup code might need
61        # to access grok.getSite() and should get our new app then
62        setSite(app)
63
64
65    def tearDown(self):
66        super(StudentProcessorTest, self).tearDown()
67        shutil.rmtree(self.workdir)
68        shutil.rmtree(self.dc_root)
69        clearSite()
70        return
71
72class OfficerUITests(StudentsFullSetup):
73    # Tests for Student class views and pages
74
75    layer = FunctionalLayer
76
77    def test_gpa_calculation(self):
78        studylevel = createObject(u'waeup.StudentStudyLevel')
79        studylevel.level = 100
80        studylevel.level_session = 2005
81        self.student['studycourse'].entry_mode = 'ug_ft'
82        self.student['studycourse'].addStudentStudyLevel(
83            self.certificate, studylevel)
84        # First course has been added automatically.
85        # Set score.
86        studylevel['COURSE1'].score = 55
87        # GPA is 3.0.
88        self.assertEqual(studylevel.gpa_params[0], 3.0)
89        courseticket = createObject('waeup.CourseTicket')
90        courseticket.code = 'ANYCODE'
91        courseticket.title = u'Any TITLE'
92        courseticket.credits = 13
93        courseticket.score = 66
94        courseticket.semester = 1
95        courseticket.dcode = u'ANYDCODE'
96        courseticket.fcode = u'ANYFCODE'
97        studylevel['COURSE2'] = courseticket
98        # total credits
99        self.assertEqual(self.student['studycourse']['100'].gpa_params[1], 23)
100        # weigheted credits = 3 * 10 + 4 * 13
101        self.assertEqual(self.student['studycourse']['100'].gpa_params[2], 82.0)
102        # sgpa = 82 / 23
103        self.assertEqual(self.student['studycourse']['100'].gpa_params[0], 3.565)
104        return
105
106    def test_manage_payments(self):
107        # Add missing configuration data
108        self.app['configuration']['2004'].gown_fee = 150.0
109        self.app['configuration']['2004'].transfer_fee = 90.0
110        self.app['configuration']['2004'].booking_fee = 150.0
111        self.app['configuration']['2004'].maint_fee = 180.0
112        self.app['configuration']['2004'].late_fee = 80.0
113
114        # Managers can add online payment tickets
115        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
116        self.browser.open(self.payments_path)
117        self.browser.getLink("Add current session payment ticket").click()
118        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
119        self.browser.getControl("Create ticket").click()
120        self.assertMatches('...Wrong state...',
121                           self.browser.contents)
122        IWorkflowState(self.student).setState('cleared')
123        self.browser.open(self.payments_path + '/addop')
124        self.browser.getControl("Create ticket").click()
125        self.assertMatches('...Amount could not be determined...',
126                           self.browser.contents)
127        #self.browser.getControl(name="form.p_category").value = ['schoolfee']
128        # Accepotance fee must be paid first
129        #self.browser.getControl("Create ticket").click()
130        #self.assertMatches('...Please pay acceptance fee first...',
131        #                   self.browser.contents)
132        self.app['configuration']['2004'].clearance_fee = 666.0
133        self.browser.getControl(name="form.p_category").value = ['clearance_incl']
134        self.browser.getControl("Create ticket").click()
135        ctrl = self.browser.getControl(name='val_id')
136        cpt_value = ctrl.options[0]
137        # School fee payment ticket can be added ...
138        self.student['studycourse'].certificate.school_fee_1 = 6666.0
139        self.student.nationality = u'NG'
140        self.browser.open(self.payments_path + '/addop')
141        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
142        self.browser.getControl("Create ticket").click()
143        self.assertMatches('...ticket created...',
144                           self.browser.contents)
145        # ... but not paid through the query_history page.
146        ctrl = self.browser.getControl(name='val_id')
147        sfpt_value = ctrl.options[1]
148        self.student['studycourse'].entry_session = 2013
149        self.browser.open(self.payments_path + '/' + sfpt_value)
150        self.browser.getLink("Query eTranzact History").click()
151        self.assertMatches('...alert-danger">Please pay acceptance fee first...',
152                           self.browser.contents)
153        # If clearance/acceptance fee is paid ...
154        self.student['payments'][cpt_value].approveStudentPayment()
155        self.browser.getLink("Query eTranzact History").click()
156        # ... query_history page is accessible.
157        self.assertMatches(
158            '...<h1 class="kofa-content-label">Requery eTranzact History</h1>...',
159            self.browser.contents)
160        # Managers can open school fee payment slip
161        self.browser.open(self.payments_path + '/' + sfpt_value)
162        self.browser.getLink("Download payment slip").click()
163        self.assertEqual(self.browser.headers['Status'], '200 Ok')
164        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
165        # If school fee ticket is paid, the student is automatically set to
166        # school fee paid...
167        ticket = self.student['payments'][sfpt_value].approveStudentPayment()
168        self.assertEqual(self.student.state, 'school fee paid')
169        # ... no further school fee ticket can be added.
170        self.browser.open(self.payments_path + '/addop')
171        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
172        self.browser.getControl("Create ticket").click()
173        self.assertMatches('...Wrong state...',
174                           self.browser.contents)
175        self.browser.open(self.payments_path + '/addop')
176        self.browser.getControl(name="form.p_category").value = ['late_registration']
177        self.browser.getControl("Create ticket").click()
178        self.assertMatches('...ticket created...',
179                           self.browser.contents)
180
181    def deactivated_test_for_instalment_payments(self):
182        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
183        self.browser.open(self.payments_path)
184        self.browser.open(self.payments_path + '/addop')
185        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
186        self.browser.getControl("Create ticket").click()
187        self.assertMatches('...ticket created...',
188                           self.browser.contents)
189        # We can't add the 2nd instalment ticket because the
190        # first one has not yet been approved.
191        self.browser.open(self.payments_path + '/addop')
192        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
193        self.browser.getControl("Create ticket").click()
194        self.assertMatches('...1st school fee instalment has not yet been paid...',
195                           self.browser.contents)
196        # Ok, then we approve the first instalment ...
197        self.browser.open(self.payments_path)
198        ctrl = self.browser.getControl(name='val_id')
199        p_id = ctrl.options[0]
200        self.browser.open(self.payments_path + '/' + p_id + '/approve')
201        # ... add the second instalment ...
202        self.browser.open(self.payments_path + '/addop')
203        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
204        self.browser.getControl("Create ticket").click()
205        self.assertMatches('...ticket created...',
206                           self.browser.contents)
207        # ... approve the second instalment ...
208        ctrl = self.browser.getControl(name='val_id')
209        p_id = ctrl.options[1]
210        self.browser.open(self.payments_path + '/' + p_id + '/approve')
211        # ... and finally add the 1st instalment for the next session
212        # provided that student is returning.
213        IWorkflowState(self.student).setState('returning')
214        self.browser.open(self.payments_path + '/addop')
215        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
216        self.browser.getControl("Create ticket").click()
217        self.assertMatches('...Session configuration object is not...',
218                           self.browser.contents)
219        # Uups, we forgot to add a session configuration for next session
220        configuration = createObject('waeup.SessionConfiguration')
221        configuration.academic_session = 2005
222        self.app['configuration'].addSessionConfiguration(configuration)
223        self.app['configuration']['2005'].school_base = 7777.0
224        self.browser.open(self.payments_path + '/addop')
225        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
226        self.browser.getControl("Create ticket").click()
227        self.assertMatches('...ticket created...',
228                           self.browser.contents)
229        # If the session configuration doesn't exist an error message will
230        # be shown. No other requirement is being checked.
231        del self.app['configuration']['2004']
232        self.browser.open(self.payments_path)
233        self.browser.getLink("Add current session payment ticket").click()
234        self.browser.getControl("Create ticket").click()
235        self.assertMatches('...Session configuration object is not...',
236                           self.browser.contents)
237
238    def test_manage_payments_bypass_ac_creation(self):
239        self.student['studycourse'].certificate.school_fee_1 = 6666.0
240        self.student.nationality = u'NG'
241        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
242        self.browser.open(self.payments_path)
243        IWorkflowState(self.student).setState('cleared')
244        self.browser.getLink("Add current session payment ticket").click()
245        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
246        self.browser.getControl("Create ticket").click()
247        ctrl = self.browser.getControl(name='val_id')
248        value = ctrl.options[0]
249        self.browser.getLink(value).click()
250        payment_url = self.browser.url
251        logfile = os.path.join(
252            self.app['datacenter'].storage, 'logs', 'students.log')
253        # The ticket can be found in the payments_catalog
254        cat = queryUtility(ICatalog, name='payments_catalog')
255        results = list(cat.searchResults(p_state=('unpaid', 'unpaid')))
256        self.assertTrue(len(results), 1)
257        self.assertTrue(results[0] is self.student['payments'][value])
258        # Managers can approve the payment
259        self.browser.open(payment_url)
260        self.browser.getLink("Approve payment").click()
261        self.assertMatches('...Payment approved...',
262                          self.browser.contents)
263        # Approval is logged in students.log ...
264        logcontent = open(logfile).read()
265        self.assertTrue(
266            'zope.mgr - students.browser.OnlinePaymentApproveView '
267            '- E1000000 - schoolfee_incl payment approved'
268            in logcontent)
269        # ... and in payments.log
270        logfile = os.path.join(
271            self.app['datacenter'].storage, 'logs', 'payments.log')
272        logcontent = open(logfile).read()
273        self.assertTrue(
274            '"zope.mgr",E1000000,%s,schoolfee_incl,6666.0,AP,,,,,,\n' % value
275            in logcontent)
276        # Student is in state school fee paid, no activation
277        # code was necessary.
278        self.assertEqual(self.student.state, 'school fee paid')
279        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
280        return
281
282class StudentUITests(StudentsFullSetup):
283    """Tests for customized student class views and pages
284    """
285
286    layer = FunctionalLayer
287
288    def setUp(self):
289        super(StudentUITests, self).setUp()
290
291        bedticket = BedTicket()
292        bedticket.booking_session = 2004
293        bedticket.bed_type = u'any bed type'
294        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
295        bedticket.bed_coordinates = u'My bed coordinates'
296        self.student['accommodation'].addBedTicket(bedticket)
297
298    def test_student_payments(self):
299        self.certificate.study_mode = 'ug_ft'
300        self.student['studycourse'].entry_session = 2013
301        self.student['studycourse'].certificate.school_fee_1 = 50250.0
302        self.app['configuration']['2004'].union_fee = 1250.0
303        self.app['configuration']['2004'].welfare_fee = 750.0
304        self.student.nationality = u'NG'
305        # Login
306        IWorkflowState(self.student).setState('cleared')
307        self.browser.open(self.login_path)
308        self.browser.getControl(name="form.login").value = self.student_id
309        self.browser.getControl(name="form.password").value = 'spwd'
310        self.browser.getControl("Login").click()
311        # Test school fee payments
312        self.browser.open(self.student_path + '/payments')
313        self.browser.getLink("Add current session payment ticket").click()
314        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
315        self.browser.getControl("Create ticket").click()
316        self.assertTrue('ticket created' in self.browser.contents)
317        ctrl = self.browser.getControl(name='val_id')
318        value = ctrl.options[0]
319        self.browser.getLink(value).click()
320        self.assertTrue('Amount Authorized' in self.browser.contents)
321        self.assertEqual(self.student['payments'][value].amount_auth, 51750.0)
322        self.browser.open(self.browser.url + '/payment_slip.pdf')
323        self.assertEqual(self.browser.headers['Status'], '200 Ok')
324        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
325        path = os.path.join(samples_dir(), 'payment_slip.pdf')
326        open(path, 'wb').write(self.browser.contents)
327        print "Sample PDF payment_slip.pdf written to %s" % path
328        # Test hostel maintenance payments
329        self.browser.open(self.student_path + '/payments')
330        self.browser.getLink("Add current session payment ticket").click()
331        self.browser.getControl(name="form.p_category").value = ['hostel_maintenance']
332        self.browser.getControl("Create ticket").click()
333        self.assertTrue('ticket created' in self.browser.contents)
334        ctrl = self.browser.getControl(name='val_id')
335        value = ctrl.options[1]
336        self.browser.getLink(value).click()
337        self.assertTrue('<span>My bed coordinates</span>' in self.browser.contents)
338        self.assertEqual(self.student['payments'][value].amount_auth, 876.0)
339        return
340
341    def test_late_registration(self):
342        # Login
343        delta = timedelta(days=10)
344        self.app['configuration'][
345            '2004'].coursereg_deadline = datetime.now(pytz.utc) - delta
346        IWorkflowState(self.student).setState('school fee paid')
347        # Current session is 2004. Here we test course registration for
348        # returning students.
349        self.student['studycourse'].entry_session = 2003
350        self.browser.open(self.login_path)
351        self.browser.getControl(name="form.login").value = self.student_id
352        self.browser.getControl(name="form.password").value = 'spwd'
353        self.browser.getControl("Login").click()
354        self.browser.open(self.payments_path)
355        self.browser.open(self.payments_path + '/addop')
356        self.browser.getControl(name="form.p_category").value = ['late_registration']
357        self.browser.getControl("Create ticket").click()
358        self.assertMatches('...ticket created...',
359                           self.browser.contents)
360        self.browser.open(self.payments_path)
361        ctrl = self.browser.getControl(name='val_id')
362        value = ctrl.options[0]
363        self.browser.getLink("Study Course").click()
364        self.browser.getLink("Add course list").click()
365        self.assertMatches('...Add current level 100 (Year 1)...',
366                           self.browser.contents)
367        self.browser.getControl("Create course list now").click()
368        self.browser.getLink("100").click()
369        self.browser.getLink("Edit course list").click()
370        self.browser.getControl("Register course list").click()
371        self.assertTrue('Course registration has ended. Please pay' in self.browser.contents)
372        self.student['payments'][value].approve()
373        self.browser.getControl("Register course list").click()
374        self.assertTrue('Course list has been registered' in self.browser.contents)
375        self.assertEqual(self.student.state, 'courses registered')
376        # Reset student and check if fresh students are always allowed to
377        # register courses.
378        self.student['studycourse'].entry_session = 2004
379        del self.student['payments'][value]
380        IWorkflowState(self.student).setState('school fee paid')
381        self.browser.open(self.studycourse_path + '/100/edit')
382        self.browser.getControl("Register course list").click()
383        self.assertTrue('Course list has been registered' in self.browser.contents)
384        return
385
386
387    def deactivated_test_student_course_registration(self):
388        # Add more courses
389        self.course2 = createObject('waeup.Course')
390        self.course2.code = 'COURSE2'
391        self.course2.semester = 2
392        self.course2.credits = 10
393        self.course2.passmark = 40
394        self.app['faculties']['fac1']['dep1'].courses.addCourse(
395            self.course2)
396        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
397            self.course2, level=100)
398        self.course3 = createObject('waeup.Course')
399        self.course3.code = 'COURSE3'
400        self.course3.semester = 3
401        self.course3.credits = 10
402        self.course3.passmark = 40
403        self.app['faculties']['fac1']['dep1'].courses.addCourse(
404            self.course3)
405        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
406            self.course3, level=100)
407
408        # Login as student
409        self.browser.open(self.login_path)
410        IWorkflowState(self.student).setState('school fee paid')
411        self.browser.open(self.login_path)
412        self.browser.getControl(name="form.login").value = self.student_id
413        self.browser.getControl(name="form.password").value = 'spwd'
414        self.browser.getControl("Login").click()
415        # Students can add the current study level
416        self.browser.getLink("Study Course").click()
417        self.browser.getLink("Add course list").click()
418        self.assertMatches('...Add current level 100 (Year 1)...',
419                           self.browser.contents)
420        self.browser.getControl("Create course list now").click()
421        # Student has not paid second instalment, therefore a level
422        # with two course ticket was created (semester 1 and combined)
423        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
424        self.browser.getLink("100").click()
425        self.browser.getLink("Edit course list").click()
426        self.browser.getControl("Add course ticket").click()
427        # Student can't add second semester course
428        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
429        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
430        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
431
432        # Let's remove level and see what happens after 2nd instalment payment
433        del(self.student['studycourse']['100'])
434        payment2 = createObject('waeup.StudentOnlinePayment')
435        payment2.p_category = u'schoolfee_2'
436        payment2.p_session = self.student.current_session
437        self.student['payments']['anykey'] = payment2
438        self.browser.open(self.studycourse_path)
439        self.browser.getLink("Add course list").click()
440        self.browser.getControl("Create course list now").click()
441        # Still only 2 tickets have been created since payment ticket
442        # was not paid
443        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
444        payment2.p_state = u'paid'
445        del(self.student['studycourse']['100'])
446        self.browser.open(self.studycourse_path)
447        self.browser.getLink("Add course list").click()
448        self.browser.getControl("Create course list now").click()
449        # Now 2nd semester course has been added
450        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
451        # Student can add second semester course
452        self.browser.getLink("100").click()
453        self.browser.getLink("Edit course list").click()
454        self.browser.getControl("Add course ticket").click()
455        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
456        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
457        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
458        return
459
460    def test_set_matric_number(self):
461        # Login as student
462        self.browser.open(self.login_path)
463        IWorkflowState(self.student).setState('school fee paid')
464        self.browser.open(self.login_path)
465        self.browser.getControl(name="form.login").value = self.student_id
466        self.browser.getControl(name="form.password").value = 'spwd'
467        self.browser.getControl("Login").click()
468        self.assertRaises(
469            LinkNotFoundError,
470            self.browser.getLink, 'Get Matriculation Number')
471        self.student.matric_number = None
472        site = grok.getSite()
473        site['configuration'].next_matric_integer = 1
474        self.student['studycourse'].certificate.study_mode = 'ug_pt'
475        self.browser.open(self.student_path)
476        self.assertRaises(
477            LinkNotFoundError,
478            self.browser.getLink, 'Download matriculation number slip')
479        self.browser.getLink("Get Matriculation Number").click()
480        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
481            in self.browser.contents)
482        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
483        self.assertRaises(
484            LinkNotFoundError,
485            self.browser.getLink, 'Get Matriculation Number')
486        # Setting matric number is logged.
487        logfile = os.path.join(
488            self.app['datacenter'].storage, 'logs', 'students.log')
489        logcontent = open(logfile).read()
490        self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - '
491                        'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent)
492        # Matric Number Slip can be downloaded
493        self.browser.getLink("Download matriculation number slip").click()
494        self.assertEqual(self.browser.headers['Status'], '200 Ok')
495        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
496        path = os.path.join(samples_dir(), 'matric_number_slip.pdf')
497        open(path, 'wb').write(self.browser.contents)
498        print "Sample PDF matric_number_slip.pdf written to %s" % path
499        return
500
501    def test_student_course_registration(self):
502        IWorkflowState(self.student).setState('school fee paid')
503        self.browser.open(self.login_path)
504        self.browser.getControl(name="form.login").value = self.student_id
505        self.browser.getControl(name="form.password").value = 'spwd'
506        self.browser.getControl("Login").click()
507        # Now students can add the current study level
508        self.browser.getLink("Study Course").click()
509        self.browser.getLink("Add course list").click()
510        self.assertMatches('...Add current level 100 (Year 1)...',
511                           self.browser.contents)
512        self.browser.getControl("Create course list now").click()
513        # Students can't open the customized pdf course registration slip
514        self.browser.open(
515            self.student_path + '/studycourse/100/course_registration_slip.pdf')
516        self.assertTrue('Forbidden' in self.browser.contents)
517        # They can open slips from the previous session ...
518        self.student['studycourse'].current_level = 200
519        self.browser.open(self.student_path + '/studycourse/100')
520        self.browser.getLink("Download course registration slip").click()
521        self.assertEqual(self.browser.headers['Status'], '200 Ok')
522        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
523        # or if they have registered their course list
524        self.student['studycourse'].current_level = 200
525        IWorkflowState(self.student).setState('courses registered')
526        self.browser.open(self.student_path + '/studycourse/100')
527        self.browser.getLink("Download course registration slip").click()
528        self.assertEqual(self.browser.headers['Status'], '200 Ok')
529        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
530
531    def test_student_clearance(self):
532        # Student cant login if their password is not set
533        IWorkflowInfo(self.student).fireTransition('admit')
534        self.browser.open(self.login_path)
535        self.browser.getControl(name="form.login").value = self.student_id
536        self.browser.getControl(name="form.password").value = 'spwd'
537        self.browser.getControl("Login").click()
538        self.assertMatches(
539            '...You logged in...', self.browser.contents)
540        # Admitted student can upload a passport picture
541        self.browser.open(self.student_path + '/change_portrait')
542        ctrl = self.browser.getControl(name='passportuploadedit')
543        file_obj = open(SAMPLE_IMAGE, 'rb')
544        file_ctrl = ctrl.mech_control
545        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
546        self.browser.getControl(
547            name='upload_passportuploadedit').click()
548        self.assertTrue(
549            'src="http://localhost/app/students/E1000000/passport.jpg"'
550            in self.browser.contents)
551        # Student is redirected to the personal data form because
552        # personal data form is not properly filled.
553        self.browser.open(self.student_path + '/start_clearance')
554        self.assertMatches('...Personal data form is not properly filled...',
555                           self.browser.contents)
556        self.assertEqual(self.browser.url, self.student_path + '/edit_personal')
557        self.student.father_name = u'Rudolf'
558        self.browser.open(self.student_path + '/start_clearance')
559        self.assertMatches('...<h1 class="kofa-content-label">Start clearance</h1>...',
560                   self.browser.contents)
561
562    def test_student_accommodation(self):
563        del self.student['accommodation']['2004']
564        # All beds can be assigned
565        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
566        bed1.bed_type = u'regular_male_all'
567        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
568        bed2.bed_type = u'regular_female_all'
569        notify(grok.ObjectModifiedEvent(bed1))
570        notify(grok.ObjectModifiedEvent(bed2))
571        # Login
572        self.browser.open(self.login_path)
573        self.browser.getControl(name="form.login").value = self.student_id
574        self.browser.getControl(name="form.password").value = 'spwd'
575        self.browser.getControl("Login").click()
576        # Students can book accommodation without AC ...
577        self.browser.open(self.acco_path)
578        IWorkflowInfo(self.student).fireTransition('admit')
579        self.browser.getLink("Book accommodation").click()
580        self.assertFalse('Activation Code:' in self.browser.contents)
581        self.browser.getControl("Create bed ticket").click()
582        # Bed is randomly selected but, since there is only
583        # one bed for this student, we know that
584        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
585            'Hall 1, Block A, Room 101, Bed A (regular_male_all)')
586        # Only the hall name is displayed
587        self.assertEqual(self.student['accommodation']['2004'].display_coordinates,
588            'Hall 1')
589        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
590            in self.browser.contents)
591        self.assertTrue('<td>Hall 1</td>'
592            in self.browser.contents)
593        return
Note: See TracBrowser for help on using the repository browser.