[CMF-checkins] CVS: CMF/CMFUid/tests - test_uidgeneration.py:1.2 test_uidhandling.py:1.2

Grégoire Weber zope.org at incept.ch
Tue Jul 20 20:01:45 EDT 2004


Update of /cvs-repository/CMF/CMFUid/tests
In directory cvs.zope.org:/tmp/cvs-serv12926/tests

Modified Files:
	test_uidgeneration.py test_uidhandling.py 
Log Message:
- moved properties 'remove_on_add' and 'remove_on_clone' to generator tool
- replaced all exceptions raised by 'UniqueIdError' exception


=== CMF/CMFUid/tests/test_uidgeneration.py 1.1.1.1 => 1.2 ===
--- CMF/CMFUid/tests/test_uidgeneration.py:1.1.1.1	Tue Jul 20 18:06:16 2004
+++ CMF/CMFUid/tests/test_uidgeneration.py	Tue Jul 20 20:01:45 2004
@@ -17,9 +17,13 @@
 __version__ = "$Revision$"
 
 from unittest import TestCase, TestSuite, makeSuite, main
-#import Testing
-#import Zope
-#Zope.startup()
+import Testing
+import Zope
+Zope.startup()
+
+from Products.CMFCore.tests.base.dummy import DummyContent
+
+from Products.CMFCore.tests.base.testcase import SecurityTest
 
 from Products.CMFUid.interfaces \
     import IUniqueIdGenerator, IAnnotatedUniqueId
@@ -34,27 +38,33 @@
     def setUid(self, uid):
         setattr(self, UID_ATTRNAME, uid)
 
-def addDummyItemWithUid(remove_on_add=None, remove_on_clone=None):
-    generator = UniqueIdGeneratorTool()
-    item = DummyItem()
-    setattr(item, UID_ATTRNAME, generator())
-    uid = getattr(item, UID_ATTRNAME)
-    if remove_on_add is not None:
-        uid.remove_on_add = remove_on_add
-    if remove_on_clone is not None:
-        uid.remove_on_clone = remove_on_clone
-    uid.setId(UID_ATTRNAME)
-    return item, uid
-
-class UniqueIdGeneratorTests(TestCase):
+class UniqueIdGeneratorTests(SecurityTest):
 
+    def setUp(self):
+        SecurityTest.setUp(self)
+        self.root._setObject('portal_uidgenerator', UniqueIdGeneratorTool())
+        self.root._setObject('dummy', DummyContent(id='dummy'))
+    
+    def addDummyContent(self, remove_on_add=None, remove_on_clone=None):
+        # attach a unique id to dummy content
+        dummy = self.root.dummy
+        generator = self.root.portal_uidgenerator
+        setattr(dummy, UID_ATTRNAME, generator())
+        uid = getattr(dummy, UID_ATTRNAME)
+        uid.setId(UID_ATTRNAME)
+        if remove_on_add is not None:
+            generator.remove_on_add = remove_on_add
+        if remove_on_clone is not None:
+            generator.remove_on_clone = remove_on_clone
+        return dummy, uid
+        
     def test_interface(self):
-        generator = UniqueIdGeneratorTool()
+        generator = self.root.portal_uidgenerator
         IUniqueIdGenerator.isImplementedBy(generator)
         IAnnotatedUniqueId.isImplementedBy(generator())
         
     def test_returnedUidsAreDifferent(self):
-        generator = UniqueIdGeneratorTool()
+        generator = self.root.portal_uidgenerator
         uid1 = generator()
         uid2 = generator()
         self.failIfEqual(uid1, uid2)
@@ -62,7 +72,7 @@
         self.failIfEqual(uid1(), None)
         
     def test_getIdOfUidObject(self):
-        generator = UniqueIdGeneratorTool()
+        generator = self.root.portal_uidgenerator
         uid1 = generator()
         uid1.setId('blah')
         self.assertEqual(uid1.getId(), 'blah')
@@ -81,38 +91,39 @@
     #   obj.manage_afterClone(obj_at_target, obj_at_target)
         
     def test_simulateItemAddRemovingUid(self):
-        item, uid = addDummyItemWithUid()
+        item, uid = self.addDummyContent()
         uid.manage_afterAdd(item, None)
         self.assertRaises(AttributeError, getattr, item, UID_ATTRNAME)
         
     def test_simulateItemAddDoesNotTouchUid(self):
-        item, uid = addDummyItemWithUid(remove_on_add=False)
+        item, uid = self.addDummyContent(remove_on_add=False)
         uid.manage_afterAdd(item, None)
         self.assertEqual(getattr(item, UID_ATTRNAME)(), 1)
         
     def test_simulateItemRename(self):
-        item, uid = addDummyItemWithUid()
+        item, uid = self.addDummyContent()
         uid.manage_beforeDelete(item, None)
         uid.manage_afterAdd(item, None)
         self.assertEqual(getattr(item, UID_ATTRNAME)(), 1)
         
     def test_simulateItemCloneRemovingUid1(self):
-        item, uid = addDummyItemWithUid()
+        item, uid = self.addDummyContent()
         uid.manage_afterAdd(item, None)
         uid.manage_afterClone(item)
         self.assertRaises(AttributeError, getattr, item, UID_ATTRNAME)
         
     def test_simulateItemCloneRemovingUid2(self):
-        item, uid = addDummyItemWithUid(remove_on_add=False)
+        item, uid = self.addDummyContent(remove_on_add=False)
         uid.manage_afterAdd(item, None)
         uid.manage_afterClone(item)
         self.assertRaises(AttributeError, getattr, item, UID_ATTRNAME)
         
     def test_simulateItemCloneDoesNotTouchUid(self):
-        item, uid = addDummyItemWithUid(remove_on_clone=False)
+        item, uid = self.addDummyContent(remove_on_clone=False)
         uid.manage_afterAdd(item, None)
         uid.manage_afterClone(item)
         self.assertEqual(getattr(item, UID_ATTRNAME)(), 1)
+
 
 def test_suite():
     return TestSuite((


=== CMF/CMFUid/tests/test_uidhandling.py 1.1.1.1 => 1.2 ===
--- CMF/CMFUid/tests/test_uidhandling.py:1.1.1.1	Tue Jul 20 18:06:16 2004
+++ CMF/CMFUid/tests/test_uidhandling.py	Tue Jul 20 20:01:45 2004
@@ -55,26 +55,28 @@
         setupIndexes(self.root.portal_catalog, self.uid_attr_name)
     
     def test_interface(self):
-        handler = UniqueIdHandlerTool()
+        handler = self.root.portal_uidhandler
         IUniqueIdHandler.isImplementedBy(handler)
     
     def test_getUidOfNotYetRegisteredObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
+        UniqueIdError = handler.UniqueIdError
         
         self.assertEqual(handler.queryUid(dummy, None), None)
-        self.assertRaises(KeyError, handler.getUid, dummy)
+        self.assertRaises(UniqueIdError, handler.getUid, dummy)
     
     def test_getInvalidUid(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
+        UniqueIdError = handler.UniqueIdError
         
         self.assertEqual(handler.queryObject(100, None), None)
-        self.assertRaises(KeyError, handler.getObject, 100)
+        self.assertRaises(UniqueIdError, handler.getObject, 100)
     
         uid = handler.register(dummy)
         self.assertEqual(handler.queryObject(uid+1, None), None)
-        self.assertRaises(KeyError, handler.getObject, uid+1)
+        self.assertRaises(UniqueIdError, handler.getObject, uid+1)
     
     def test_getUidOfRegisteredObject(self):
         handler = self.root.portal_uidhandler
@@ -93,20 +95,42 @@
     def test_getUnregisteredObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
+        UniqueIdError = handler.UniqueIdError
         
         uid = handler.register(dummy)
         handler.unregister(dummy)
         self.assertEqual(handler.queryObject(uid, None), None)
-        self.assertRaises(KeyError, handler.getObject, uid)
+        self.assertRaises(UniqueIdError, handler.getObject, uid)
 
     def test_getUidOfUnregisteredObject(self):
         handler = self.root.portal_uidhandler
         dummy = self.root.dummy
+        UniqueIdError = handler.UniqueIdError
         
         uid = handler.register(dummy)
         handler.unregister(dummy)
         self.assertEqual(handler.queryUid(dummy, None), None)
-        self.assertRaises(KeyError, handler.getUid, dummy)
+        self.assertRaises(UniqueIdError, handler.getUid, dummy)
+
+    def test_reregisterObject(self):
+        handler = self.root.portal_uidhandler
+        dummy = self.root.dummy
+        
+        uid1_reg = handler.register(dummy)
+        uid1_get = handler.getUid(dummy)
+        uid2_reg = handler.register(dummy)
+        uid2_get = handler.getUid(dummy)
+        self.assertEqual(uid1_reg, uid2_reg)
+        self.assertEqual(uid1_get, uid2_get)
+        self.assertEqual(uid1_reg, uid1_get)
+    
+    def test_unregisterObjectWithoutUid(self):
+        handler = self.root.portal_uidhandler
+        dummy = self.root.dummy
+        UniqueIdError = handler.UniqueIdError
+        
+        self.assertRaises(UniqueIdError, handler.unregister, dummy)
+
 
 def test_suite():
     return TestSuite((



More information about the CMF-checkins mailing list