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

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

Disable removal of payment tickets by students.

  • Property svn:keywords set to Id
File size: 29.8 KB
Line 
1## $Id: test_browser.py 13523 2015-12-02 12:01:00Z 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        return
181
182    def test_for_instalment_payments(self):
183        self.student['studycourse'].certificate.school_fee_1 = 6666.0
184        self.app['configuration']['2004'].union_fee = 1250.0
185        self.app['configuration']['2004'].welfare_fee = 750.0
186        self.student.nationality = u'NG'
187        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
188        self.browser.open(self.payments_path + '/addop')
189        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
190        self.browser.getControl("Create ticket").click()
191        self.assertTrue(
192            'Wrong state. Only students in state \'cleared\' are allowed to pay by instalments'
193            in self.browser.contents)
194        IWorkflowState(self.student).setState('cleared')
195        self.browser.open(self.payments_path + '/addop')
196        self.browser.getControl(name="form.p_category").value = ['schoolfee_1']
197        self.browser.getControl("Create ticket").click()
198        self.assertTrue('ticket created' in self.browser.contents)
199        # We can't add the 2nd instalment ticket because the
200        # first one has not yet been approved.
201        #self.browser.open(self.payments_path + '/addop')
202        #self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
203        #self.browser.getControl("Create ticket").click()
204        #self.assertMatches('...1st school fee instalment has not yet been paid...',
205        #                   self.browser.contents)
206        # Ok, then we approve the first instalment ...
207        self.browser.open(self.payments_path)
208        ctrl = self.browser.getControl(name='val_id')
209        p_id = ctrl.options[0]
210        self.browser.open(self.payments_path + '/' + p_id + '/approve')
211        # ... add the second instalment ...
212        self.browser.open(self.payments_path + '/addop')
213        self.browser.getControl(name="form.p_category").value = ['schoolfee_2']
214        self.browser.getControl("Create ticket").click()
215        self.assertTrue('ticket created' in self.browser.contents)
216        # ... approve the second instalment ...
217        ctrl = self.browser.getControl(name='val_id')
218        p_id = ctrl.options[1]
219        self.browser.open(self.payments_path + '/' + p_id + '/approve')
220        self.assertEqual(self.student['payments'].values()[0].p_category, 'schoolfee_1')
221        self.assertEqual(self.student['payments'].values()[1].p_category, 'schoolfee_2')
222        # 6666/2 + 1250 + 750 - 500
223        self.assertEqual(self.student['payments'].values()[0].amount_auth, 4833.0)
224        # 6666/2
225        self.assertEqual(self.student['payments'].values()[1].amount_auth, 3333.0)
226        return
227
228    def test_manage_payments_bypass_ac_creation(self):
229        self.student['studycourse'].certificate.school_fee_1 = 6666.0
230        self.student.nationality = u'NG'
231        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
232        self.browser.open(self.payments_path)
233        IWorkflowState(self.student).setState('cleared')
234        self.browser.getLink("Add current session payment ticket").click()
235        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
236        self.browser.getControl("Create ticket").click()
237        ctrl = self.browser.getControl(name='val_id')
238        value = ctrl.options[0]
239        self.browser.getLink(value).click()
240        payment_url = self.browser.url
241        logfile = os.path.join(
242            self.app['datacenter'].storage, 'logs', 'students.log')
243        # The ticket can be found in the payments_catalog
244        cat = queryUtility(ICatalog, name='payments_catalog')
245        results = list(cat.searchResults(p_state=('unpaid', 'unpaid')))
246        self.assertTrue(len(results), 1)
247        self.assertTrue(results[0] is self.student['payments'][value])
248        # Managers can approve the payment
249        self.browser.open(payment_url)
250        self.browser.getLink("Approve payment").click()
251        self.assertMatches('...Payment approved...',
252                          self.browser.contents)
253        # Approval is logged in students.log ...
254        logcontent = open(logfile).read()
255        self.assertTrue(
256            'zope.mgr - students.browser.OnlinePaymentApproveView '
257            '- E1000000 - schoolfee_incl payment approved'
258            in logcontent)
259        # ... and in payments.log
260        logfile = os.path.join(
261            self.app['datacenter'].storage, 'logs', 'payments.log')
262        logcontent = open(logfile).read()
263        self.assertTrue(
264            '"zope.mgr",E1000000,%s,schoolfee_incl,6666.0,AP,,,,,,\n' % value
265            in logcontent)
266        # Student is in state school fee paid, no activation
267        # code was necessary.
268        self.assertEqual(self.student.state, 'school fee paid')
269        self.assertEqual(len(self.app['accesscodes']['SFE-0']),0)
270        return
271
272class StudentUITests(StudentsFullSetup):
273    """Tests for customized student class views and pages
274    """
275
276    layer = FunctionalLayer
277
278    def setUp(self):
279        super(StudentUITests, self).setUp()
280
281        bedticket = BedTicket()
282        bedticket.booking_session = 2004
283        bedticket.bed_type = u'any bed type'
284        bedticket.bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
285        bedticket.bed_coordinates = u'My bed coordinates'
286        self.student['accommodation'].addBedTicket(bedticket)
287
288    def test_student_payments(self):
289        self.certificate.study_mode = 'ug_ft'
290        self.student['studycourse'].entry_session = 2013
291        self.student['studycourse'].certificate.school_fee_1 = 50250.0
292        self.app['configuration']['2004'].union_fee = 1250.0
293        self.app['configuration']['2004'].welfare_fee = 750.0
294        self.student.nationality = u'NG'
295        # Login
296        IWorkflowState(self.student).setState('cleared')
297        self.browser.open(self.login_path)
298        self.browser.getControl(name="form.login").value = self.student_id
299        self.browser.getControl(name="form.password").value = 'spwd'
300        self.browser.getControl("Login").click()
301        # Test school fee payments
302        self.browser.open(self.student_path + '/payments')
303        self.browser.getLink("Add current session payment ticket").click()
304        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
305        self.browser.getControl("Create ticket").click()
306        self.assertTrue('ticket created' in self.browser.contents)
307        value = self.student['payments'].keys()[0]
308        self.browser.getLink(value).click()
309        self.assertTrue('Amount Authorized' in self.browser.contents)
310        self.assertEqual(self.student['payments'][value].amount_auth, 51750.0)
311        self.browser.open(self.browser.url + '/payment_slip.pdf')
312        self.assertEqual(self.browser.headers['Status'], '200 Ok')
313        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
314        path = os.path.join(samples_dir(), 'payment_slip.pdf')
315        open(path, 'wb').write(self.browser.contents)
316        print "Sample PDF payment_slip.pdf written to %s" % path
317        # Test hostel maintenance payments
318        self.browser.open(self.student_path + '/payments')
319        self.browser.getLink("Add current session payment ticket").click()
320        self.browser.getControl(name="form.p_category").value = ['hostel_maintenance']
321        self.browser.getControl("Create ticket").click()
322        self.assertTrue('ticket created' in self.browser.contents)
323        value = self.student['payments'].keys()[1]
324        self.browser.getLink(value).click()
325        self.assertTrue('<span>My bed coordinates</span>' in self.browser.contents)
326        self.assertEqual(self.student['payments'][value].amount_auth, 876.0)
327        return
328
329    def test_late_registration(self):
330        # Login
331        delta = timedelta(days=10)
332        self.app['configuration'][
333            '2004'].coursereg_deadline = datetime.now(pytz.utc) - delta
334        IWorkflowState(self.student).setState('school fee paid')
335        # Current session is 2004. Here we test course registration for
336        # returning students.
337        self.student['studycourse'].entry_session = 2003
338        self.browser.open(self.login_path)
339        self.browser.getControl(name="form.login").value = self.student_id
340        self.browser.getControl(name="form.password").value = 'spwd'
341        self.browser.getControl("Login").click()
342        self.browser.open(self.payments_path)
343        self.browser.open(self.payments_path + '/addop')
344        self.browser.getControl(name="form.p_category").value = ['late_registration']
345        self.browser.getControl("Create ticket").click()
346        self.assertMatches('...ticket created...',
347                           self.browser.contents)
348        self.browser.getLink("Study Course").click()
349        self.browser.getLink("Add course list").click()
350        self.assertMatches('...Add current level 100 (Year 1)...',
351                           self.browser.contents)
352        self.browser.getControl("Create course list now").click()
353        self.browser.getLink("100").click()
354        self.browser.getLink("Edit course list").click()
355        self.browser.getControl("Register course list").click()
356        self.assertTrue('Course registration has ended. Please pay' in self.browser.contents)
357        self.student['payments'].values()[0].approve()
358        self.browser.getControl("Register course list").click()
359        self.assertTrue('Course list has been registered' in self.browser.contents)
360        self.assertEqual(self.student.state, 'courses registered')
361        # Reset student and check if fresh students are always allowed to
362        # register courses.
363        self.student['studycourse'].entry_session = 2004
364        del self.student['payments'][self.student['payments'].keys()[0]]
365        IWorkflowState(self.student).setState('school fee paid')
366        self.browser.open(self.studycourse_path + '/100/edit')
367        self.browser.getControl("Register course list").click()
368        self.assertTrue('Course list has been registered' in self.browser.contents)
369        return
370
371
372    def deactivated_test_student_course_registration(self):
373        # Add more courses
374        self.course2 = createObject('waeup.Course')
375        self.course2.code = 'COURSE2'
376        self.course2.semester = 2
377        self.course2.credits = 10
378        self.course2.passmark = 40
379        self.app['faculties']['fac1']['dep1'].courses.addCourse(
380            self.course2)
381        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
382            self.course2, level=100)
383        self.course3 = createObject('waeup.Course')
384        self.course3.code = 'COURSE3'
385        self.course3.semester = 3
386        self.course3.credits = 10
387        self.course3.passmark = 40
388        self.app['faculties']['fac1']['dep1'].courses.addCourse(
389            self.course3)
390        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
391            self.course3, level=100)
392
393        # Login as student
394        self.browser.open(self.login_path)
395        IWorkflowState(self.student).setState('school fee paid')
396        self.browser.open(self.login_path)
397        self.browser.getControl(name="form.login").value = self.student_id
398        self.browser.getControl(name="form.password").value = 'spwd'
399        self.browser.getControl("Login").click()
400        # Students can add the current study level
401        self.browser.getLink("Study Course").click()
402        self.browser.getLink("Add course list").click()
403        self.assertMatches('...Add current level 100 (Year 1)...',
404                           self.browser.contents)
405        self.browser.getControl("Create course list now").click()
406        # Student has not paid second instalment, therefore a level
407        # with two course ticket was created (semester 1 and combined)
408        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
409        self.browser.getLink("100").click()
410        self.browser.getLink("Edit course list").click()
411        self.browser.getControl("Add course ticket").click()
412        # Student can't add second semester course
413        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
414        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
415        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
416
417        # Let's remove level and see what happens after 2nd instalment payment
418        del(self.student['studycourse']['100'])
419        payment2 = createObject('waeup.StudentOnlinePayment')
420        payment2.p_category = u'schoolfee_2'
421        payment2.p_session = self.student.current_session
422        self.student['payments']['anykey'] = payment2
423        self.browser.open(self.studycourse_path)
424        self.browser.getLink("Add course list").click()
425        self.browser.getControl("Create course list now").click()
426        # Still only 2 tickets have been created since payment ticket
427        # was not paid
428        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
429        payment2.p_state = u'paid'
430        del(self.student['studycourse']['100'])
431        self.browser.open(self.studycourse_path)
432        self.browser.getLink("Add course list").click()
433        self.browser.getControl("Create course list now").click()
434        # Now 2nd semester course has been added
435        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
436        # Student can add second semester course
437        self.browser.getLink("100").click()
438        self.browser.getLink("Edit course list").click()
439        self.browser.getControl("Add course ticket").click()
440        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
441        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
442        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
443        return
444
445    def test_set_matric_number(self):
446        # Login as student
447        self.browser.open(self.login_path)
448        IWorkflowState(self.student).setState('school fee paid')
449        self.browser.open(self.login_path)
450        self.browser.getControl(name="form.login").value = self.student_id
451        self.browser.getControl(name="form.password").value = 'spwd'
452        self.browser.getControl("Login").click()
453        self.assertRaises(
454            LinkNotFoundError,
455            self.browser.getLink, 'Get Matriculation Number')
456        self.student.matric_number = None
457        site = grok.getSite()
458        site['configuration'].next_matric_integer = 1
459        self.student['studycourse'].certificate.study_mode = 'ug_pt'
460        self.browser.open(self.student_path)
461        self.assertRaises(
462            LinkNotFoundError,
463            self.browser.getLink, 'Download matriculation number slip')
464        self.browser.getLink("Get Matriculation Number").click()
465        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
466            in self.browser.contents)
467        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
468        self.assertRaises(
469            LinkNotFoundError,
470            self.browser.getLink, 'Get Matriculation Number')
471        # Setting matric number is logged.
472        logfile = os.path.join(
473            self.app['datacenter'].storage, 'logs', 'students.log')
474        logcontent = open(logfile).read()
475        self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - '
476                        'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent)
477        # Matric Number Slip can be downloaded
478        self.browser.getLink("Download matriculation number slip").click()
479        self.assertEqual(self.browser.headers['Status'], '200 Ok')
480        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
481        path = os.path.join(samples_dir(), 'matric_number_slip.pdf')
482        open(path, 'wb').write(self.browser.contents)
483        print "Sample PDF matric_number_slip.pdf written to %s" % path
484        return
485
486    def test_personal_data_slip(self):
487        # Login as student
488        self.browser.open(self.login_path)
489        IWorkflowState(self.student).setState('school fee paid')
490        self.browser.open(self.login_path)
491        self.browser.getControl(name="form.login").value = self.student_id
492        self.browser.getControl(name="form.password").value = 'spwd'
493        self.browser.getControl("Login").click()
494        self.browser.getLink("Personal Data").click()
495        self.assertRaises(
496            LinkNotFoundError,
497            self.browser.getLink, 'Download personal data slip')
498        self.student.father_name = u'Rudolf'
499        self.browser.open(self.personal_path)
500        self.browser.getLink("Download personal data slip").click()
501        self.assertEqual(self.browser.headers['Status'], '200 Ok')
502        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
503        path = os.path.join(samples_dir(), 'personal_data_slip.pdf')
504        open(path, 'wb').write(self.browser.contents)
505        print "Sample PDF personal_data_slip.pdf written to %s" % path
506        return
507
508    def test_student_course_registration(self):
509        IWorkflowState(self.student).setState('school fee paid')
510        self.browser.open(self.login_path)
511        self.browser.getControl(name="form.login").value = self.student_id
512        self.browser.getControl(name="form.password").value = 'spwd'
513        self.browser.getControl("Login").click()
514        # Now students can add the current study level
515        self.browser.getLink("Study Course").click()
516        self.browser.getLink("Add course list").click()
517        self.assertMatches('...Add current level 100 (Year 1)...',
518                           self.browser.contents)
519        self.browser.getControl("Create course list now").click()
520        # Students can't open the customized pdf course registration slip
521        self.browser.open(
522            self.student_path + '/studycourse/100/course_registration_slip.pdf')
523        self.assertTrue('Forbidden' in self.browser.contents)
524        # They can open slips from the previous session ...
525        self.student['studycourse'].current_level = 200
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        # or if they have registered their course list
531        self.student['studycourse'].current_level = 200
532        IWorkflowState(self.student).setState('courses registered')
533        self.browser.open(self.student_path + '/studycourse/100')
534        self.browser.getLink("Download course registration slip").click()
535        self.assertEqual(self.browser.headers['Status'], '200 Ok')
536        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
537
538    def test_student_clearance(self):
539        # Student cant login if their password is not set
540        IWorkflowInfo(self.student).fireTransition('admit')
541        self.browser.open(self.login_path)
542        self.browser.getControl(name="form.login").value = self.student_id
543        self.browser.getControl(name="form.password").value = 'spwd'
544        self.browser.getControl("Login").click()
545        self.assertMatches(
546            '...You logged in...', self.browser.contents)
547        # Admitted student can upload a passport picture
548        self.browser.open(self.student_path + '/change_portrait')
549        ctrl = self.browser.getControl(name='passportuploadedit')
550        file_obj = open(SAMPLE_IMAGE, 'rb')
551        file_ctrl = ctrl.mech_control
552        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
553        self.browser.getControl(
554            name='upload_passportuploadedit').click()
555        self.assertTrue(
556            'src="http://localhost/app/students/E1000000/passport.jpg"'
557            in self.browser.contents)
558        # Student is redirected to the personal data form because
559        # personal data form is not properly filled.
560        self.browser.open(self.student_path + '/start_clearance')
561        self.assertMatches('...Personal data form is not properly filled...',
562                           self.browser.contents)
563        self.assertEqual(self.browser.url, self.student_path + '/edit_personal')
564        self.student.father_name = u'Rudolf'
565        self.browser.open(self.student_path + '/start_clearance')
566        self.assertMatches(
567            '...<h1 class="kofa-content-label">Start clearance</h1>...',
568            self.browser.contents)
569
570    def test_student_accommodation(self):
571        del self.student['accommodation']['2004']
572        # All beds can be assigned
573        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
574        bed1.bed_type = u'regular_male_all'
575        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
576        bed2.bed_type = u'regular_female_all'
577        notify(grok.ObjectModifiedEvent(bed1))
578        notify(grok.ObjectModifiedEvent(bed2))
579        # Login
580        self.browser.open(self.login_path)
581        self.browser.getControl(name="form.login").value = self.student_id
582        self.browser.getControl(name="form.password").value = 'spwd'
583        self.browser.getControl("Login").click()
584        # Students can book accommodation without AC ...
585        self.browser.open(self.acco_path)
586        IWorkflowInfo(self.student).fireTransition('admit')
587        self.browser.getControl("Book accommodation").click()
588        self.assertFalse('Activation Code:' in self.browser.contents)
589        self.browser.getControl("Create bed ticket").click()
590        # Bed is randomly selected but, since there is only
591        # one bed for this student, we know that
592        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
593            'Hall 1, Block A, Room 101, Bed A (regular_male_all)')
594        # Only the hall name is displayed
595        self.assertEqual(self.student[
596            'accommodation']['2004'].display_coordinates,
597            'Hall 1')
598        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
599            in self.browser.contents)
600        self.assertTrue('<td>Hall 1</td>'
601            in self.browser.contents)
602        return
Note: See TracBrowser for help on using the repository browser.