On Mon, Jun 18, 2007 at 12:20:57PM +0200, Christophe Combelles wrote:
> Hi,
> 
> I've experienced a dangerous behaviour with namechoosers :
> 
> If the namechooser computes a name which is the same as the current name,
> the object is deleted!
> 
> This is simple to reproduce :
> - register a name chooser that only returns "foobar"
> - create your object → ok it's name is foobar
> - from the Contents view of it's container, try to rename it (with a 
> different name)
> - → deleted
> 
> Someone should try to reproduce that, to be sure that's not a side effect 
> of my app, but I don't think so.

I can reproduce it with a unit test:

[EMAIL PROTECTED]:~/src/Zope3 $ ./test.py -pv -s zope.copypastemove
Running tests at level 1
Running unit tests:
  Running:
    46/46 (100.0%) doctest_renaming_with_obstinate_name_chooser 
(zope.copypastemove.tests.test_rename)

Failure in test doctest_renaming_with_obstinate_name_chooser 
(zope.copypastemove.tests.test_rename)
Failed doctest test for 
zope.copypastemove.tests.test_rename.doctest_renaming_with_obstinate_name_chooser
  File "/home/mg/src/Zope3/src/zope/copypastemove/tests/test_rename.py", line 
32, in doctest_renaming_with_obstinate_name_chooser

----------------------------------------------------------------------
File "/home/mg/src/Zope3/src/zope/copypastemove/tests/test_rename.py", line 67, 
in 
zope.copypastemove.tests.test_rename.doctest_renaming_with_obstinate_name_chooser
Failed example:
    list(container)
Expected:
    [u'foobar']
Got:
    []


  Ran 46 tests with 1 failures and 0 errors in 0.081 seconds.


Here's the test I added:


Index: src/zope/copypastemove/tests/test_rename.py
===================================================================
--- src/zope/copypastemove/tests/test_rename.py (revision 76767)
+++ src/zope/copypastemove/tests/test_rename.py (working copy)
@@ -28,10 +28,55 @@
     eventtesting.setUp()
     container_setup.setUp()
 
+
+def doctest_renaming_with_obstinate_name_chooser():
+    """Test ObjectMover when the name chooser returns the same name
+
+    This is a regression test for a bug reported by Christophe Combelles
+
+    Setup: register the IObjectMover adapter
+
+        >>> from zope.copypastemove import ContainerItemRenamer, ObjectMover
+        >>> from zope.component import adapts, provideAdapter
+        >>> provideAdapter(ObjectMover)
+
+    Suppose you have a NameChooser that always chooses the same name
+
+        >>> from zope.app.container.sample import SampleContainer
+        >>> class MyContainer(SampleContainer):
+        ...     pass
+        >>> from zope.app.container.contained import NameChooser
+        >>> class ObstinateNameChooser(NameChooser):
+        ...     adapts(MyContainer)
+        ...     def chooseName(self, name, object):
+        ...         return u'foobar'
+        >>> provideAdapter(ObstinateNameChooser)
+
+    Let's add an object to a container
+
+        >>> from zope.app.container.contained import Contained
+        >>> container = MyContainer()
+        >>> container[u'foobar'] = Contained()
+
+    Try to rename it
+
+        >>> ContainerItemRenamer(container).renameItem(u'foobar', u'newname')
+
+    The rename did not succeed, because the name chooser did not allow it:
+
+        >>> list(container)
+        [u'foobar']
+
+    There was a bug once: in this particular case the object mover adapter
+    would remove the item altogether.
+    """
+
+
 def test_suite():
     return unittest.TestSuite((
         DocTestSuite('zope.copypastemove',
                      setUp=setUp, tearDown=testing.tearDown),
+        DocTestSuite(setUp=setUp, tearDown=testing.tearDown),
         ))
 
 if __name__=='__main__':


Marius Gedminas
-- 
If nothing else helps, read the documentation.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to