Index: main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py	(revision 6985)
+++ main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py	(revision 6988)
@@ -15,5 +15,5 @@
 ##
 """
-Tests for hostels. and their UI components
+Tests for hostels and their UI components.
 """
 import shutil
@@ -157,4 +157,7 @@
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertTrue('Hostel created' in self.browser.contents)
+        self.browser.open(self.container_path + '/addhostel')
+        self.browser.getControl("Create hostel").click()
+        self.assertTrue('The hostel already exists' in self.browser.contents)
         hall = self.app['hostels']['hall-1']
         hall.blocks_for_female = ['A','B']
@@ -172,45 +175,59 @@
         self.assertTrue(len(hall.blocks_for_female) == 0)
         hall.blocks_for_female = ['A','B']
-        hall.beds_for_fresh = ['A','B']
+        hall.beds_for_fresh = ['A']
+        hall.beds_for_returning = ['B']
+        hall.beds_for_final = ['C']
         hall.beds_for_all = ['D','E']
         self.browser.getControl("Update all beds").click()
-        expected = '...0 empty beds removed, 8 beds added, 0 occupied beds modified...'
+        expected = '...0 empty beds removed, 10 beds added, 0 occupied beds modified ()...'
         self.assertMatches(expected,self.browser.contents)
         cat = queryUtility(ICatalog, name='beds_catalog')
         results = cat.searchResults(
             bed_type=('regular_female_all', 'regular_female_all'))
-        #import pdb; pdb.set_trace()
         results = [x for x in results]
         assert len(results) == 4
-        # Set bed reserved
-        ctrl = self.browser.getControl(name='val_id')
+        # Reserve bed
+        self.browser.getControl("Switch reservation", index=0).click()
+        self.assertTrue('No item selected' in self.browser.contents)
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value='hall-1_A_101_A').selected = True
+        ctrl.getControl(value='hall-1_A_101_B').selected = True
+        ctrl.getControl(value='hall-1_A_101_C').selected = True
         ctrl.getControl(value='hall-1_A_101_D').selected = True
         self.browser.getControl("Switch reservation", index=0).click()
-        self.assertTrue('Successfully switched beds: hall-1_A_101_D'
+        self.assertTrue('Successfully switched beds: hall-1_A_101_A (reserved)'
             in self.browser.contents)
-        assert self.app[
-            'hostels'][
-            'hall-1'][
+        assert self.app['hostels']['hall-1'][
             'hall-1_A_101_D'].bed_type == 'regular_female_reserved'
-        expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_D"  />'
+        expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_A"  />'
         self.assertTrue(expected in self.browser.contents)
-        # Release bed
+        # Provoke exception
+        self.app['hostels']['hall-1']['hall-1_A_101_D'].bed_type = u'nonsense'
         ctrl = self.browser.getControl(name='val_id')
         ctrl.getControl(value='hall-1_A_101_D').selected = True
         self.browser.getControl("Switch reservation", index=0).click()
-        assert self.app[
-            'hostels'][
-            'hall-1'][
-            'hall-1_A_101_D'].bed_type == 'regular_female_all'
-        self.assertFalse(expected in self.browser.contents)
+        self.assertMatches(
+            '...need more than 1 value to unpack...', self.browser.contents)
+        self.app['hostels']['hall-1'][
+            'hall-1_A_101_D'].bed_type = u'regular_female_reserved'
         # Change hostel configuration
         hall.beds_for_all = ['D']
         self.browser.getControl("Update all beds").click()
-        expected = '...8 empty beds removed, 6 beds added, 0 occupied beds modified...'
+        expected = '...10 empty beds removed, 8 beds added, 0 occupied beds modified...'
         self.assertMatches(expected,self.browser.contents)
         results = cat.searchResults(
             bed_type=('regular_female_all', 'regular_female_all'))
         results = [x for x in results]
-        assert len(results) == 2
+        assert len(results) == 1
+        # Unreserve bed
+        ctrl = self.browser.getControl(name='val_id')
+        ctrl.getControl(value='hall-1_A_101_A').selected = True
+        ctrl.getControl(value='hall-1_A_101_B').selected = True
+        ctrl.getControl(value='hall-1_A_101_C').selected = True
+        ctrl.getControl(value='hall-1_A_101_D').selected = True
+        self.browser.getControl("Switch reservation", index=0).click()
+        assert self.app['hostels']['hall-1'][
+            'hall-1_A_101_D'].bed_type == 'regular_female_all'
+        self.assertFalse(expected in self.browser.contents)
         # Remove entire hostel
         self.browser.open(self.manage_container_path)
