[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/versioncontrol/ Fixed a bug in isResourceChanged

Jim Fulton jim at zope.com
Thu May 26 11:23:48 EDT 2005


Log message for revision 30513:
  Fixed a bug in isResourceChanged
  

Changed:
  U   Zope3/trunk/src/zope/app/versioncontrol/repository.py
  U   Zope3/trunk/src/zope/app/versioncontrol/tests.py

-=-
Modified: Zope3/trunk/src/zope/app/versioncontrol/repository.py
===================================================================
--- Zope3/trunk/src/zope/app/versioncontrol/repository.py	2005-05-26 15:22:36 UTC (rev 30512)
+++ Zope3/trunk/src/zope/app/versioncontrol/repository.py	2005-05-26 15:23:18 UTC (rev 30513)
@@ -121,6 +121,7 @@
         # *after* the version bookkeeping was saved. Note that this method is
         # not appropriate for detecting changes within a transaction!
         info = self.getVersionInfo(object)
+        info.version_id # deghostify info
         itime = getattr(info, '_p_serial', None)
         if itime is None:
             return False

Modified: Zope3/trunk/src/zope/app/versioncontrol/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/versioncontrol/tests.py	2005-05-26 15:22:36 UTC (rev 30512)
+++ Zope3/trunk/src/zope/app/versioncontrol/tests.py	2005-05-26 15:23:18 UTC (rev 30513)
@@ -19,11 +19,16 @@
 import unittest
 import persistent
 
+from zope import component, interface
 from zope.component.tests.placelesssetup import PlacelessSetup
 from zope.testing import doctest, module
 from transaction import abort
+import zope.app.annotation.interfaces
+import zope.app.annotation.attribute
 import zope.app.location
 import zope.app.versioncontrol.version
+from zope.app.versioncontrol import interfaces, nonversioned
+import zope.app.traversing.interfaces
 
 name = 'zope.app.versioncontrol.README'
 
@@ -43,7 +48,12 @@
 
 
 class L(persistent.Persistent, zope.app.location.Location):
-    pass
+    interface.implements(interfaces.IVersionable,
+                         zope.app.annotation.interfaces.IAttributeAnnotatable,
+                         zope.app.traversing.interfaces.IPhysicallyLocatable,
+                         )
+    def getPath(self):
+        return 'whatever'
 
 
 def testLocationSanity_for__findModificationTime():
@@ -115,8 +125,65 @@
     False
 
 """
+
+def test_isResourceChanged_works_with_ghosts():
+    """\
+
+There was a bug that caused isResourceChanged to give an incorrect
+answer when applied to an object who's verion info was a ghost.
+
+Let's create an object, put it under vc and make sure that
+isResourceChanged works as expected:
+
+    >>> from ZODB.tests import util
+    >>> import transaction
+    >>> db = util.DB()
+    >>> component.provideAdapter(
+    ...     zope.app.annotation.attribute.AttributeAnnotations)
+    >>> component.provideAdapter(
+    ...     nonversioned.StandardNonVersionedDataAdapter,
+    ...     [None])
+    >>> import zope.app.versioncontrol.repository
+    >>> import zope.interface.verify
+
+    >>> import zope.security.testing
+    >>> principal = zope.security.testing.Principal('bob')
+    >>> participation = zope.security.testing.Participation(principal)
+
+    >>> import zope.security.management
+    >>> zope.security.management.newInteraction(participation)
+
+    >>> repository = zope.app.versioncontrol.repository.Repository()
+    >>> ob = L()
+    >>> conn1 = db.open()
+    >>> conn1.root()['ob'] = ob
+    >>> repository.applyVersionControl(ob, 'initial')
+    >>> transaction.commit()
+    >>> repository.isResourceChanged(ob)
+    False
+
+    >>> ob.x = 1
+    >>> transaction.commit()
+    >>> repository.isResourceChanged(ob) # eek
+    True
+    >>> repository.checkoutResource(ob)
+    >>> repository.checkinResource(ob)
+    >>> transaction.commit()
+    >>> repository.isResourceChanged(ob)
+    False
+
+So far so good.  Now, we'll open a new connection and see if we get
+the right answer:
     
+    >>> conn2 = db.open()
+    >>> ob = conn2.root()['ob']
+    >>> repository.isResourceChanged(ob)
+    False
+    
+    >>> zope.security.management.endInteraction()
 
+"""
+
 def test_suite():
     return unittest.TestSuite((
         doctest.DocFileSuite('README.txt',



More information about the Zope3-Checkins mailing list