Index: main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 6989)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 7005)
@@ -39,4 +39,5 @@
 from waeup.sirp.university.department import Department
 from waeup.sirp.interfaces import IUserAccount
+from waeup.sirp.hostels.hostel import Hostel, Bed, NOT_OCCUPIED
 
 PH_LEN = 2059  # Length of placeholder file
@@ -87,4 +88,5 @@
         student.reg_number = u'123'
         student.matric_number = u'234'
+        student.sex = u'm'
         self.app['students'].addStudent(student)
         self.student_id = student.student_id
@@ -105,8 +107,7 @@
         self.edit_clearance_student_path = self.student_path + '/edit_clearance'
         self.edit_personal_student_path = self.student_path + '/edit_personal'
-
         self.studycourse_student_path = self.student_path + '/studycourse'
         self.payments_student_path = self.student_path + '/payments'
-        self.accommodation_student_path = self.student_path + '/accommodation'
+        self.acco_student_path = self.student_path + '/accommodation'
         self.history_student_path = self.student_path + '/history'
 
@@ -151,7 +152,29 @@
             self.course, level=100)
 
+        # Configure university
+        self.app['configuration'].accommodation_states = ['admitted']
+        self.app['configuration'].accommodation_session = 2004
+        configuration = SessionConfiguration()
+        configuration.academic_session = 2004
+        configuration.fee_1 = 20000
+        configuration.boocking_fee = 500
+        self.app['configuration'].addSessionConfiguration(configuration)
+
+        # Create a hostel with bed
+        hostel = Hostel()
+        hostel.hostel_id = u'hall-1'
+        hostel.hostel_name = u'Hall 1'
+        self.app['hostels'].addHostel(hostel)
+        bed = Bed()
+        bed.bed_id = u'hall-1_A_101_A'
+        bed.bed_number = 1
+        bed.owner = NOT_OCCUPIED
+        bed.bed_type = u'regular_male_fr'
+        self.app['hostels'][hostel.hostel_id].addBed(bed)
+
         # Set study course attributes of test student
         self.student['studycourse'].certificate = self.certificate
         self.student['studycourse'].current_session = 2004
+        self.student['studycourse'].entry_session = 2004
         self.student['studycourse'].current_verdict = 'A'
         self.student['studycourse'].current_level = 100
@@ -308,5 +331,5 @@
         self.browser.getLink("Accommodation").click()
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
-        self.assertEqual(self.browser.url, self.accommodation_student_path)
+        self.assertEqual(self.browser.url, self.acco_student_path)
         self.browser.open(self.student_path)
         self.browser.getLink("History").click()
@@ -653,10 +676,4 @@
 
     def test_manage_payments(self):
-        # Set up SessionConfiguration object
-        configuration = SessionConfiguration()
-        configuration.academic_session = 2004
-        configuration.fee_1 = 20000
-        self.app['configuration'].addSessionConfiguration(configuration)
-
         # Managers can add online school fee payment tickets
         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
@@ -726,11 +743,6 @@
 
 
-
     def test_student_payments(self):
         # Set up SessionConfiguration object
-        configuration = SessionConfiguration()
-        configuration.academic_session = 2004
-        configuration.fee_1 = 20000
-        self.app['configuration'].addSessionConfiguration(configuration)
         self.browser.open(self.login_path)
         self.browser.getControl(name="form.login").value = self.student_id
@@ -822,2 +834,63 @@
                            self.browser.contents)
         self.assertTrue(self.student.state,'school fee paid')
+
+    def test_manage_accommodation(self):
+        # Managers can add online booking fee payment tickets and open the
+        # callback view (see test_manage_payments)
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.payments_student_path)
+        self.browser.getControl("Add online payment ticket").click()
+        self.browser.getControl(name="form.p_category").value = ['bed_allocation']
+        self.browser.getControl("Create ticket").click()
+        ctrl = self.browser.getControl(name='val_id')
+        value = ctrl.options[0]
+        self.browser.getLink(value).click()
+        self.browser.open(self.browser.url + '/callback')
+        # The new HOS-0 pin has been created
+        self.assertEqual(len(self.app['accesscodes']['HOS-0']),1)
+        pin = self.app['accesscodes']['HOS-0'].keys()[0]
+        ac = self.app['accesscodes']['HOS-0'][pin]
+        ac.owner = self.student_id
+        parts = pin.split('-')[1:]
+        sfeseries, sfenumber = parts
+        # Managers can use HOS code and book a bed space with it
+        self.browser.open(self.acco_student_path)
+        self.browser.getControl("Add bed ticket").click()
+        self.assertMatches('...Wrong state...',
+                           self.browser.contents)
+        IWorkflowInfo(self.student).fireTransition('admit')
+        self.browser.getControl("Add bed ticket").click()
+        self.assertMatches('...Activation Code:...',
+                           self.browser.contents)
+        self.browser.getControl(name="ac_series").value = sfeseries
+        self.browser.getControl(name="ac_number").value = sfenumber
+        self.browser.getControl("Create bed ticket").click()
+        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
+                           self.browser.contents)
+        # Bed has been allocated
+        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
+        self.assertTrue(bed.owner,self.student_id)
+        # BedTicketAddPage is now blocked
+        self.browser.getControl("Add bed ticket").click()
+        self.assertMatches('...Ticket for 2004 already created...',
+            self.browser.contents)
+        # The bed ticket displays the data correctly
+        self.browser.open(self.acco_student_path + '/2004')
+        self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
+                           self.browser.contents)
+        self.assertMatches('...2004/2005...', self.browser.contents)
+        self.assertMatches('...regular_male_fr...', self.browser.contents)
+        self.assertMatches('...%s...' % pin, self.browser.contents)
+        # Managers cab delete bed tickets
+        self.browser.open(self.acco_student_path)
+        ctrl = self.browser.getControl(name='val_id')
+        value = ctrl.options[0]
+        ctrl.getControl(value=value).selected = True
+        self.browser.getControl("Remove selected", index=0).click()
+        self.assertTrue('Successfully removed' in self.browser.contents)
+        # Due to an event handler also the bed has been released properly
+        bed = self.app['hostels']['hall-1']['hall-1_A_101_A']
+        self.assertTrue(bed.owner == NOT_OCCUPIED)
+
+    def test_student_accommodation(self):
+        pass
