Index: main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py	(revision 6583)
+++ main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py	(revision 6585)
@@ -68,6 +68,6 @@
         setSite(app)
 
-        self.root_path = 'http://localhost/app/applicants/'
-        self.container_path = 'http://localhost/app/applicants/app2009/'
+        self.root_path = 'http://localhost/app/applicants'
+        self.container_path = 'http://localhost/app/applicants/app2009'
 
         # Add an applicants container
@@ -108,4 +108,8 @@
         self.applicant.access_code = self.pin_applicant
         app['applicants']['app2009'][self.pin_applicant] = self.applicant
+
+        # Add an officer
+        myusers = self.app['users']
+        myusers.addUser('bob', 'bobssecret')
         return
 
@@ -142,5 +146,5 @@
     def test_manage_access(self):
         # Managers can access the manage pages of applicants root and
-        # applicants containers
+        # applicants containers and can perform actions
         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
         self.browser.open(self.root_path)
@@ -155,12 +159,24 @@
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertEqual(self.browser.url, self.manage_container_path)
+        self.browser.getControl("Save").click()
+        self.assertTrue(
+            'Data saved' in self.browser.contents)
+        self.browser.getControl("Remove selected", index=0).click()
+        self.assertTrue(
+            'No applicant selected' in self.browser.contents)
+        self.browser.getControl("Cancel", index=0).click()
+        self.assertEqual(self.browser.url, self.container_path)
         return
 
     def test_add_delete_container(self):
         # Managers can add and delete applicants containers
-        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
-        self.browser.open(self.root_path)
+        self.manage_root_path = self.root_path + '/@@manage'
         self.add_container_path = self.root_path + '/@@add'
-        self.browser.open(self.add_container_path)
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.manage_root_path)
+        self.browser.getControl("Cancel").click()
+        self.assertEqual(self.browser.url, self.root_path)
+        self.browser.open(self.manage_root_path)
+        self.browser.getControl("Add applicants container").click()
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
         self.assertEqual(self.browser.url, self.add_container_path)
@@ -177,4 +193,14 @@
         self.browser.getControl("Add applicants container").click()
         self.assertTrue('Added:' in self.browser.contents)
+        self.browser.open(self.add_container_path)
+        self.browser.getControl(name="form.prefix").value = ['app']
+        self.browser.getControl(name="form.year").value = ['2010']
+        self.browser.getControl(name="form.provider").value = [
+            'waeup.sirp.applicants.ApplicantsContainer']
+        self.browser.getControl(name="form.ac_prefix").value = ['APP']
+        self.browser.getControl(name="form.application_category").value = ['basic']
+        self.browser.getControl("Add applicants container").click()
+        self.assertTrue('exists already in the database' in self.browser.contents)
+        self.browser.open(self.manage_root_path)
         ctrl = self.browser.getControl(name='val_id')
         ctrl.getControl(value='app2010').selected = True
@@ -203,5 +229,5 @@
         return
 
-    def test_manage_applicant(self):
+    def test_manage_and_view_applicant(self):
         # Managers can manage applicants
         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
@@ -210,9 +236,4 @@
         self.applicant_manage_path = self.applicant_path + '/edit_full'
         self.applicant_slip_path = self.applicant_path + '/application_slip.pdf'
-        self.browser.open(self.applicant_view_path)
-        self.assertEqual(self.browser.headers['Status'], '200 Ok')
-        self.browser.open(self.applicant_slip_path)
-        self.assertEqual(self.browser.headers['Status'], '200 Ok')
-        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
         self.browser.open(self.applicant_manage_path)
         self.assertEqual(self.browser.headers['Status'], '200 Ok')
@@ -226,4 +247,9 @@
         self.browser.getControl("Save").click()
         self.assertMatches('...Form has been saved...', self.browser.contents)
+        self.browser.open(self.applicant_view_path)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.browser.open(self.applicant_slip_path)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
         return
 
@@ -665,4 +691,52 @@
         self.assertTrue(passport0 != passport1)
         self.assertTrue(passport1 == passport2)
-        self.assertTrue(passport1 is not passport2)
-        return
+        self.assertTrue(passport1 is passport2)
+        return
+
+    def test_final_submit(self):
+        # Make sure that a correctly filled form with passport picture
+        # can be submitted
+        self.login() # Create applicant form
+        self.fill_correct_values() # fill other fields with correct values
+        # Create a pseudo image file and select it to be uploaded in form
+        pseudo_image = StringIO('I pretend to be a graphics file')
+        ctrl = self.browser.getControl(name='form.passport')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
+        self.browser.getControl("Final Submit").click() # (finally) submit form
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertTrue(
+            'Passport confirmation box not ticked' in self.browser.contents)
+        self.browser.getControl(name="confirm_passport").value = True
+        self.browser.getControl("Final Submit").click() # submit form again
+        self.assertTrue(
+            '... submitted ...' in self.browser.contents)
+        return
+
+    def test_locking(self):
+        # Make sure that locked forms can't be submitted
+        self.login() # Create applicant form
+        self.fill_correct_values() # fill other fields with correct values
+        # Create a pseudo image file and select it to be uploaded in form
+        pseudo_image = StringIO('I pretend to be a graphics file')
+        ctrl = self.browser.getControl(name='form.passport')
+        file_ctrl = ctrl.mech_control
+        file_ctrl.add_file(pseudo_image, filename='myphoto.jpg')
+        self.browser.getControl("Save").click()
+        self.browser.getLink("Logout").click()
+
+        # Login as manager and lock the form
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.edit_full_path)
+        self.browser.getControl(name="form.locked").value = True
+        self.browser.getControl("Save").click()
+        self.browser.getLink("Logout").click()
+
+        # Login as applicant again and try to open the edit form
+        self.login()
+        self.browser.open(self.edit_path)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        #print self.browser.contents
+        self.assertTrue(
+            'The requested form is locked' in self.browser.contents)
+        return
