[Erp5-report] r38368 romain - /erp5/trunk/products/ERP5Security/tests/testERP5Security.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Sep 14 16:20:56 CEST 2010


Author: romain
Date: Tue Sep 14 16:20:53 2010
New Revision: 38368

URL: http://svn.erp5.org?rev=38368&view=rev
Log:
Check that the same person's reference can not be set on 2 different persons.

Modified:
    erp5/trunk/products/ERP5Security/tests/testERP5Security.py

Modified: erp5/trunk/products/ERP5Security/tests/testERP5Security.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Security/tests/testERP5Security.py?rev=38368&r1=38367&r2=38368&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Security/tests/testERP5Security.py [utf8] (original)
+++ erp5/trunk/products/ERP5Security/tests/testERP5Security.py [utf8] Tue Sep 14 16:20:53 2010
@@ -244,6 +244,57 @@ class TestUserManagement(ERP5TypeTestCas
     self._makePerson(reference='new_person')
     self.assertRaises(RuntimeError, self._makePerson, reference='new_person')
 
+  def test_MultiplePersonReferenceWithoutCommit(self):
+    """
+    Tests that it's refused to create two Persons with same reference.
+    Check if both persons are created in the same transaction
+    """
+    person_module = self.getPersonModule()
+    new_person = person_module.newContent(
+                     portal_type='Person', reference='new_person')
+    self.assertRaises(RuntimeError, person_module.newContent,
+                     portal_type='Person', reference='new_person')
+
+  def test_MultiplePersonReferenceWithoutTic(self):
+    """
+    Tests that it's refused to create two Persons with same reference.
+    Check if both persons are created in 2 different transactions.
+    """
+    person_module = self.getPersonModule()
+    new_person = person_module.newContent(
+                     portal_type='Person', reference='new_person')
+    transaction.commit()
+    self.assertRaises(RuntimeError, person_module.newContent,
+                     portal_type='Person', reference='new_person')
+
+  def test_MultiplePersonReferenceConcurrentTransaction(self):
+    """
+    Tests that it's refused to create two Persons with same reference.
+    Check if both persons are created in 2 concurrent transactions. 
+    For now, just verify that serialize is called on person_module.
+    """
+    class DummyTestException(Exception):
+      pass
+
+    def verify_serialize_call(self):
+      # Check that serialize is called on person module
+      if self.getRelativeUrl() == 'person_module':
+        raise DummyTestException
+      else:
+        return self.serialize_call()
+
+    # Replace serialize by a dummy method
+    from Products.ERP5Type.Base import Base
+    Base.serialize_call = Base.serialize
+    Base.serialize = verify_serialize_call
+
+    person_module = self.getPersonModule()
+    try:
+      self.assertRaises(DummyTestException, person_module.newContent,
+                       portal_type='Person', reference='new_person')
+    finally:
+      Base.serialize = Base.serialize_call
+
   def test_PersonCopyAndPaste(self):
     """If we copy and paste a person, login must not be copyied."""
     person = self._makePerson(reference='new_person')




More information about the Erp5-report mailing list