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

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

Customize getAccommodationDetails.

  • Property svn:keywords set to Id
File size: 28.7 KB
Line 
1## $Id: test_browser.py 13416 2015-11-09 10:56:53Z 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']
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']
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']
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']
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']
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 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,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 = 1000.0
303        self.app['configuration']['2004'].welfare_fee = 500.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        self.browser.open(self.student_path + '/payments')
312        self.browser.getLink("Add current session payment ticket").click()
313        self.browser.getControl(name="form.p_category").value = ['schoolfee_incl']
314        self.browser.getControl("Create ticket").click()
315        self.assertTrue('ticket created' in self.browser.contents)
316        ctrl = self.browser.getControl(name='val_id')
317        value = ctrl.options[0]
318        self.browser.getLink(value).click()
319        self.assertTrue('Amount Authorized' in self.browser.contents)
320        self.assertEqual(self.student['payments'][value].amount_auth, 51250.0)
321        self.browser.open(self.browser.url + '/payment_slip.pdf')
322        self.assertEqual(self.browser.headers['Status'], '200 Ok')
323        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
324        path = os.path.join(samples_dir(), 'payment_slip.pdf')
325        open(path, 'wb').write(self.browser.contents)
326        print "Sample PDF payment_slip.pdf written to %s" % path
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.open(self.payments_path)
349        ctrl = self.browser.getControl(name='val_id')
350        value = ctrl.options[0]
351        self.browser.getLink("Study Course").click()
352        self.browser.getLink("Add course list").click()
353        self.assertMatches('...Add current level 100 (Year 1)...',
354                           self.browser.contents)
355        self.browser.getControl("Create course list now").click()
356        self.browser.getLink("100").click()
357        self.browser.getLink("Edit course list").click()
358        self.browser.getControl("Register course list").click()
359        self.assertTrue('Course registration has ended. Please pay' in self.browser.contents)
360        self.student['payments'][value].approve()
361        self.browser.getControl("Register course list").click()
362        self.assertTrue('Course list has been registered' in self.browser.contents)
363        self.assertEqual(self.student.state, 'courses registered')
364        # Reset student and check if fresh students are always allowed to
365        # register courses.
366        self.student['studycourse'].entry_session = 2004
367        del self.student['payments'][value]
368        IWorkflowState(self.student).setState('school fee paid')
369        self.browser.open(self.studycourse_path + '/100/edit')
370        self.browser.getControl("Register course list").click()
371        self.assertTrue('Course list has been registered' in self.browser.contents)
372        return
373
374
375    def deactivated_test_student_course_registration(self):
376        # Add more courses
377        self.course2 = createObject('waeup.Course')
378        self.course2.code = 'COURSE2'
379        self.course2.semester = 2
380        self.course2.credits = 10
381        self.course2.passmark = 40
382        self.app['faculties']['fac1']['dep1'].courses.addCourse(
383            self.course2)
384        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
385            self.course2, level=100)
386        self.course3 = createObject('waeup.Course')
387        self.course3.code = 'COURSE3'
388        self.course3.semester = 3
389        self.course3.credits = 10
390        self.course3.passmark = 40
391        self.app['faculties']['fac1']['dep1'].courses.addCourse(
392            self.course3)
393        self.app['faculties']['fac1']['dep1'].certificates['CERT1'].addCertCourse(
394            self.course3, level=100)
395
396        # Login as student
397        self.browser.open(self.login_path)
398        IWorkflowState(self.student).setState('school fee paid')
399        self.browser.open(self.login_path)
400        self.browser.getControl(name="form.login").value = self.student_id
401        self.browser.getControl(name="form.password").value = 'spwd'
402        self.browser.getControl("Login").click()
403        # Students can add the current study level
404        self.browser.getLink("Study Course").click()
405        self.browser.getLink("Add course list").click()
406        self.assertMatches('...Add current level 100 (Year 1)...',
407                           self.browser.contents)
408        self.browser.getControl("Create course list now").click()
409        # Student has not paid second instalment, therefore a level
410        # with two course ticket was created (semester 1 and combined)
411        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
412        self.browser.getLink("100").click()
413        self.browser.getLink("Edit course list").click()
414        self.browser.getControl("Add course ticket").click()
415        # Student can't add second semester course
416        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
417        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
418        self.assertFalse('<option value="COURSE2">' in self.browser.contents)
419
420        # Let's remove level and see what happens after 2nd instalment payment
421        del(self.student['studycourse']['100'])
422        payment2 = createObject('waeup.StudentOnlinePayment')
423        payment2.p_category = u'schoolfee_2'
424        payment2.p_session = self.student.current_session
425        self.student['payments']['anykey'] = payment2
426        self.browser.open(self.studycourse_path)
427        self.browser.getLink("Add course list").click()
428        self.browser.getControl("Create course list now").click()
429        # Still only 2 tickets have been created since payment ticket
430        # was not paid
431        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 2)
432        payment2.p_state = u'paid'
433        del(self.student['studycourse']['100'])
434        self.browser.open(self.studycourse_path)
435        self.browser.getLink("Add course list").click()
436        self.browser.getControl("Create course list now").click()
437        # Now 2nd semester course has been added
438        self.assertEqual(self.student['studycourse']['100'].number_of_tickets, 3)
439        # Student can add second semester course
440        self.browser.getLink("100").click()
441        self.browser.getLink("Edit course list").click()
442        self.browser.getControl("Add course ticket").click()
443        self.assertTrue('<option value="COURSE1">' in self.browser.contents)
444        self.assertTrue('<option value="COURSE2">' in self.browser.contents)
445        self.assertTrue('<option value="COURSE3">' in self.browser.contents)
446        return
447
448    def test_set_matric_number(self):
449        # Login as student
450        self.browser.open(self.login_path)
451        IWorkflowState(self.student).setState('school fee paid')
452        self.browser.open(self.login_path)
453        self.browser.getControl(name="form.login").value = self.student_id
454        self.browser.getControl(name="form.password").value = 'spwd'
455        self.browser.getControl("Login").click()
456        self.assertRaises(
457            LinkNotFoundError,
458            self.browser.getLink, 'Get Matriculation Number')
459        self.student.matric_number = None
460        site = grok.getSite()
461        site['configuration'].next_matric_integer = 1
462        self.student['studycourse'].certificate.study_mode = 'ug_pt'
463        self.browser.open(self.student_path)
464        self.assertRaises(
465            LinkNotFoundError,
466            self.browser.getLink, 'Download matriculation number slip')
467        self.browser.getLink("Get Matriculation Number").click()
468        self.assertTrue('Matriculation number PTP/fac1/dep1/04/00001 assigned.'
469            in self.browser.contents)
470        self.assertEqual(self.student.matric_number, 'PTP/fac1/dep1/04/00001')
471        self.assertRaises(
472            LinkNotFoundError,
473            self.browser.getLink, 'Get Matriculation Number')
474        # Setting matric number is logged.
475        logfile = os.path.join(
476            self.app['datacenter'].storage, 'logs', 'students.log')
477        logcontent = open(logfile).read()
478        self.assertTrue('E1000000 - waeup.aaue.students.browser.StudentGetMatricNumberPage - '
479                        'E1000000 - PTP/fac1/dep1/04/00001 assigned' in logcontent)
480        # Matric Number Slip can be downloaded
481        self.browser.getLink("Download matriculation number slip").click()
482        self.assertEqual(self.browser.headers['Status'], '200 Ok')
483        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
484        path = os.path.join(samples_dir(), 'matric_number_slip.pdf')
485        open(path, 'wb').write(self.browser.contents)
486        print "Sample PDF matric_number_slip.pdf written to %s" % path
487        return
488
489    def test_student_course_registration(self):
490        IWorkflowState(self.student).setState('school fee paid')
491        self.browser.open(self.login_path)
492        self.browser.getControl(name="form.login").value = self.student_id
493        self.browser.getControl(name="form.password").value = 'spwd'
494        self.browser.getControl("Login").click()
495        # Now students can add the current study level
496        self.browser.getLink("Study Course").click()
497        self.browser.getLink("Add course list").click()
498        self.assertMatches('...Add current level 100 (Year 1)...',
499                           self.browser.contents)
500        self.browser.getControl("Create course list now").click()
501        # Students can't open the customized pdf course registration slip
502        self.browser.open(
503            self.student_path + '/studycourse/100/course_registration_slip.pdf')
504        self.assertTrue('Forbidden' in self.browser.contents)
505        # They can open slips from the previous session ...
506        self.student['studycourse'].current_level = 200
507        self.browser.open(self.student_path + '/studycourse/100')
508        self.browser.getLink("Download course registration slip").click()
509        self.assertEqual(self.browser.headers['Status'], '200 Ok')
510        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
511        # or if they have registered their course list
512        self.student['studycourse'].current_level = 200
513        IWorkflowState(self.student).setState('courses registered')
514        self.browser.open(self.student_path + '/studycourse/100')
515        self.browser.getLink("Download course registration slip").click()
516        self.assertEqual(self.browser.headers['Status'], '200 Ok')
517        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
518
519    def test_student_clearance(self):
520        # Student cant login if their password is not set
521        IWorkflowInfo(self.student).fireTransition('admit')
522        self.browser.open(self.login_path)
523        self.browser.getControl(name="form.login").value = self.student_id
524        self.browser.getControl(name="form.password").value = 'spwd'
525        self.browser.getControl("Login").click()
526        self.assertMatches(
527            '...You logged in...', self.browser.contents)
528        # Admitted student can upload a passport picture
529        self.browser.open(self.student_path + '/change_portrait')
530        ctrl = self.browser.getControl(name='passportuploadedit')
531        file_obj = open(SAMPLE_IMAGE, 'rb')
532        file_ctrl = ctrl.mech_control
533        file_ctrl.add_file(file_obj, filename='my_photo.jpg')
534        self.browser.getControl(
535            name='upload_passportuploadedit').click()
536        self.assertTrue(
537            'src="http://localhost/app/students/E1000000/passport.jpg"'
538            in self.browser.contents)
539        # Student is redirected to the personal data form because
540        # personal data form is not properly filled.
541        self.browser.open(self.student_path + '/start_clearance')
542        self.assertMatches('...Personal data form is not properly filled...',
543                           self.browser.contents)
544        self.assertEqual(self.browser.url, self.student_path + '/edit_personal')
545        self.student.father_name = u'Rudolf'
546        self.browser.open(self.student_path + '/start_clearance')
547        self.assertMatches('...<h1 class="kofa-content-label">Start clearance</h1>...',
548                   self.browser.contents)
549
550    def test_student_accommodation(self):
551        del self.student['accommodation']['2004']
552        # All beds can be assigned
553        bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A']
554        bed1.bed_type = u'regular_male_all'
555        bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B']
556        bed2.bed_type = u'regular_female_all'
557        notify(grok.ObjectModifiedEvent(bed1))
558        notify(grok.ObjectModifiedEvent(bed2))
559        # Login
560        self.browser.open(self.login_path)
561        self.browser.getControl(name="form.login").value = self.student_id
562        self.browser.getControl(name="form.password").value = 'spwd'
563        self.browser.getControl("Login").click()
564        # Students can book accommodation without AC ...
565        self.browser.open(self.acco_path)
566        IWorkflowInfo(self.student).fireTransition('admit')
567        self.browser.getLink("Book accommodation").click()
568        self.assertFalse('Activation Code:' in self.browser.contents)
569        self.browser.getControl("Create bed ticket").click()
570        # Bed is randomly selected but, since there is only
571        # one bed for this student, we know that
572        self.assertEqual(self.student['accommodation']['2004'].bed_coordinates,
573            'Hall 1, Block A, Room 101, Bed A (regular_male_all)')
574        # Only the hall name is displayed
575        self.assertEqual(self.student['accommodation']['2004'].display_coordinates,
576            'Hall 1')
577        self.assertFalse('Hall 1, Block A, Room 101, Bed A'
578            in self.browser.contents)
579        self.assertTrue('<td>Hall 1</td>'
580            in self.browser.contents)
581        return
Note: See TracBrowser for help on using the repository browser.