Index: main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py
===================================================================
--- main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12102)
+++ main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py	(revision 12103)
@@ -40,5 +40,6 @@
 from waeup.ikoba.customers.interfaces import ICustomersUtils
 from waeup.ikoba.customers.customer import Customer
-from waeup.ikoba.interfaces import IUserAccount, IJobManager, APPROVED
+from waeup.ikoba.interfaces import (
+    IUserAccount, IJobManager, APPROVED, SUBMITTED)
 from waeup.ikoba.authentication import LocalRoleSetEvent
 from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
@@ -111,10 +112,10 @@
         self.customer_id = customer.customer_id
         self.customer = self.app['customers'][self.customer_id]
-        document = createObject('waeup.CustomerSampleDocument')
-        document.title = u'My first document'
-        self.customer['documents'].addDocument(document)
-        contract = createObject('waeup.SampleContract')
-        contract.title = u'My first contract'
-        self.customer['contracts'].addContract(contract)
+        self.document = createObject('waeup.CustomerSampleDocument')
+        self.document.title = u'My first document'
+        self.customer['documents'].addDocument(self.document)
+        self.contract = createObject('waeup.SampleContract')
+        self.contract.title = u'My first contract'
+        self.customer['contracts'].addContract(self.contract)
 
         # Set password
@@ -1074,5 +1075,5 @@
         self.browser.getLink("Manage").click()
         self.browser.getControl(name="form.product").value = ['SAM']
-        self.browser.getControl(name="form.title").value = 'My second app'
+        self.browser.getControl(name="form.title").value = 'My second contract'
         self.browser.getControl("Save").click()
         self.assertTrue('Form has been saved.' in self.browser.contents)
@@ -1140,5 +1141,5 @@
         IWorkflowState(self.customer).setState(APPROVED)
         self.browser.open(self.contracts_path + '/c102/edit')
-        self.browser.getControl(name="form.title").value = 'My second app'
+        self.browser.getControl(name="form.title").value = 'My second contract'
         # SAM is in the correct contract_category ...
         self.assertTrue('<option value="SAM">' in self.browser.contents)
@@ -1149,9 +1150,23 @@
         self.browser.getControl(name="form.product").value = ['SAM']
         self.browser.getControl("Save").click()
-        # After saving the form, last_product_id is set.
+        # Document is a required field on edit form page.
+        self.assertTrue('Document: <span class="error">Required input is missing.</span>'
+            in self.browser.contents)
+        # But our document can't be selected because it's not submitted
+        self.assertFalse('My first document' in self.browser.contents)
+        IWorkflowState(self.document).setState(SUBMITTED)
+        self.browser.open(self.contracts_path + '/c102/edit')
+        self.browser.getControl(name="form.product").value = ['SAM']
+        self.browser.getControl(name="form.document").value = ['d101']
+        self.browser.getControl(name="form.title").value = 'My second contract'
+        self.browser.getControl("Save").click()
+        # After saving the form, last_product_id and other attributes are set
+        self.assertTrue('Form has been saved.' in self.browser.contents)
         self.assertEqual(self.customer['contracts']['c102'].last_product_id, 'SAM')
-        self.assertTrue('Form has been saved.' in self.browser.contents)
+        self.assertEqual(contract.title, 'My second contract')
+        self.assertEqual(contract.product, self.product)
+        self.assertEqual(contract.document, self.document)
         # Saving the form again does not unset last_product_id
-        self.assertEqual(contract.title, 'My second app')
+        self.browser.getControl(name="form.title").value = 'My third contract'
         self.browser.getControl("Save").click()
         self.assertEqual(self.customer['contracts']['c102'].last_product_id, 'SAM')
@@ -1161,7 +1176,7 @@
         # Customer can submit the form. The form is also saved.
         self.browser.getLink("Edit").click()
-        self.browser.getControl(name="form.title").value = 'My third app'
+        self.browser.getControl(name="form.title").value = 'My fourth contract'
         self.browser.getControl("Apply now").click()
-        self.assertEqual(contract.title, 'My third app')
+        self.assertEqual(contract.title, 'My fourth contract')
         self.assertEqual(contract.state, 'submitted')
         self.assertTrue('Contract State: submitted for approval' in self.browser.contents)
