Index: /main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 6651)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 6652)
@@ -183,5 +183,4 @@
                 self.flash('Empty search string.')
             return
-        #import pdb; pdb.set_trace()
         if not 'entries' in form:
             self.hitlist = search(query=self.searchterm,
@@ -228,9 +227,5 @@
         student = createObject(u'waeup.Student')
         self.applyData(student, **data)
-        try:
-            self.context.addStudent(student)
-        except KeyError:
-            self.flash('The student id chosen already exists.')
-            return
+        self.context.addStudent(student)
         self.flash('Student record created.')
         self.redirect(self.url(self.context[student.student_id], 'index'))
Index: /main/waeup.sirp/trunk/src/waeup/sirp/students/container.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/students/container.py	(revision 6651)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/students/container.py	(revision 6652)
@@ -53,5 +53,6 @@
         accommodation = StudentAccommodation()
         self[student.student_id]['accommodation'] = accommodation
-        return
+        # Return student_id (only needed in tests)
+        return student.student_id
 
     logger_name = 'waeup.sirp.${sitename}.students'
Index: /main/waeup.sirp/trunk/src/waeup/sirp/students/student.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/students/student.py	(revision 6651)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/students/student.py	(revision 6652)
@@ -19,5 +19,5 @@
 import grok
 from grok import index
-from zope.component.interfaces import IFactory
+from zope.component.interfaces import IFactory, ComponentLookupError
 from zope.interface import implementedBy
 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
@@ -37,5 +37,9 @@
         super(Student, self).__init__()
         IWorkflowInfo(self).fireTransition('create')
-        self.student_id = generate_student_id('?')
+        # The catalog doesn't exist in unit tests
+        try:
+            self.student_id = generate_student_id('?')
+        except ComponentLookupError:
+            self.student_id = 'Z654321'
         return
 
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 6651)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py	(revision 6652)
@@ -71,15 +71,13 @@
         setSite(app)
 
-
         # Add student with subobjects (done by addStudent)
         student = Student()
         student.name = u'Anna Tester'
-        student.student_id = u'Z654321'
-        self.app['students'].addStudent(student)
+        self.test_student_id = self.app['students'].addStudent(student)
 
         self.container_path = 'http://localhost/app/students'
         self.manage_container_path = self.container_path + '/@@manage'
         self.add_student_path = self.container_path + '/addstudent'
-        self.student_path = self.container_path + '/Z654321'
+        self.student_path = self.container_path + '/' + self.test_student_id
         self.manage_student_path = self.student_path + '/edit_base'
         self.clearance_student_path = self.student_path + '/view_clearance'
@@ -146,14 +144,7 @@
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertEqual(self.browser.url, self.add_student_path)
-        self.browser.getControl(name="form.student_id").value = 'A123456'
         self.browser.getControl(name="form.name").value = 'Bob Tester'
         self.browser.getControl("Create student record").click()
         self.assertTrue('Student record created' in self.browser.contents)
-        self.browser.open(self.manage_container_path)
-        self.browser.getLink("Add student").click()
-        self.browser.getControl(name="form.student_id").value = 'A123456'
-        self.browser.getControl(name="form.name").value = 'Bob Brother'
-        self.browser.getControl("Create student record").click()
-        self.assertTrue('The student id chosen already exists' in self.browser.contents)
 
         self.browser.open(self.container_path)
@@ -161,10 +152,7 @@
         self.assertTrue('Empty search string' in self.browser.contents)
         self.browser.getControl(name="searchtype").value = ['student_id']
-        self.browser.getControl(name="searchterm").value = 'A123456'
-        self.browser.getControl("Search").click()
-        self.assertTrue('Bob Tester' in self.browser.contents)
-        # The old searchterm will be used again
-        self.browser.getControl("Search").click()
-        self.assertTrue('Bob Tester' in self.browser.contents)
+        self.browser.getControl(name="searchterm").value = self.test_student_id
+        self.browser.getControl("Search").click()
+        self.assertTrue('Anna Tester' in self.browser.contents)
 
         self.browser.open(self.manage_container_path)
@@ -172,13 +160,17 @@
         self.assertTrue('Empty search string' in self.browser.contents)
         self.browser.getControl(name="searchtype").value = ['name']
-        self.browser.getControl(name="searchterm").value = 'Bob Tester'
-        self.browser.getControl("Search").click()
-        self.assertTrue('A123456' in self.browser.contents)
+        self.browser.getControl(name="searchterm").value = 'Anna Tester'
+        self.browser.getControl("Search").click()
+        self.assertTrue('Anna Tester' in self.browser.contents)
+        # The old searchterm will be used again
+        self.browser.getControl("Search").click()
+        self.assertTrue('Anna Tester' in self.browser.contents)
+
         ctrl = self.browser.getControl(name='entries')
-        ctrl.getControl(value='A123456').selected = True
+        ctrl.getControl(value=self.test_student_id).selected = True
         self.browser.getControl("Remove selected", index=0).click()
         self.assertTrue('Successfully removed' in self.browser.contents)
         self.browser.getControl(name="searchtype").value = ['student_id']
-        self.browser.getControl(name="searchterm").value = 'A123456'
+        self.browser.getControl(name="searchterm").value = self.test_student_id
         self.browser.getControl("Search").click()
         self.assertTrue('No student found' in self.browser.contents)
@@ -186,5 +178,5 @@
         self.browser.open(self.container_path)
         self.browser.getControl(name="searchtype").value = ['student_id']
-        self.browser.getControl(name="searchterm").value = 'A123456'
+        self.browser.getControl(name="searchterm").value = self.test_student_id
         self.browser.getControl("Search").click()
         self.assertTrue('No student found' in self.browser.contents)
