Commit 324c96f5 authored by Hanno Schlichting's avatar Hanno Schlichting

Stop importing BTreeFolder2 from inside core Zope2

parent 5e8d35aa
......@@ -34,7 +34,7 @@ We'll use a few simple classes (defined in python code for picklability)
for our tests.
>>> from OFS.tests.test_event import MyApp, MyContent
>>> from OFS.tests.test_event import MyFolder, MyBTreeFolder
>>> from OFS.tests.test_event import MyFolder
>>> from OFS.tests.test_event import MyOrderedFolder
>>> app = MyApp('')
......@@ -44,10 +44,6 @@ for our tests.
old manage_afterAdd folder folder
'folder'
>>> folder = app.folder
>>> btfolder = MyBTreeFolder('btfolder')
>>> app._setObject('btfolder', btfolder) # doctest: +NORMALIZE_WHITESPACE
old manage_afterAdd btfolder btfolder
'btfolder'
To observe what object events are dispatched, we'll have some
subscribers print them. We'll actually do that for a specific interface,
......@@ -235,22 +231,6 @@ Old behavior with events for a clone::
>>> res.getId()
'strawberry'
Events are also sent when we work with a BTreeFolder::
>>> ob = MyContent('luckyluke')
>>> btfolder._setObject('luckyluke', ob)
ObjectWillBeAddedEvent luckyluke
ObjectAddedEvent luckyluke
old manage_afterAdd luckyluke luckyluke btfolder
ContainerModifiedEvent btfolder
'luckyluke'
>>> btfolder.manage_delObjects('luckyluke')
ObjectWillBeRemovedEvent luckyluke
old manage_beforeDelete luckyluke luckyluke btfolder
ObjectRemovedEvent luckyluke
ContainerModifiedEvent btfolder
Here is what happens for a tree of objects. Let's create a simple one::
>>> subfolder = MyFolder('subfolder')
......@@ -374,23 +354,6 @@ Or copy using manage_clone::
>>> res.getId()
'phb'
Also on a BTreeFolder::
>>> ob = MyNewContent('alice')
>>> btfolder._setObject('alice', ob)
ObjectWillBeAddedEvent alice
ObjectAddedEvent alice
ContainerModifiedEvent btfolder
'alice'
>>> btfolder.manage_renameObject('alice', 'rabbit')
ObjectWillBeMovedEvent alice
ObjectMovedEvent rabbit
ContainerModifiedEvent btfolder
>>> btfolder.manage_delObjects('rabbit')
ObjectWillBeRemovedEvent rabbit
ObjectRemovedEvent rabbit
ContainerModifiedEvent btfolder
Now for a tree of objects. Let's create a simple one::
>>> subfolder = MyNewFolder('subfolder')
......
......@@ -22,7 +22,6 @@ $Id$
from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder
from OFS.OrderedFolder import OrderedFolder
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from zope.component import testing, eventtesting
......@@ -64,10 +63,6 @@ class MyFolder(NotifyBase, Folder):
class MyOrderedFolder(NotifyBase, OrderedFolder):
pass
class MyBTreeFolder(NotifyBase, BTreeFolder2):
def _verifyObjectPaste(self, object, validate_src=1):
pass
class MyContent(NotifyBase, SimpleItem):
def __init__(self, id):
self._setId(id)
......
......@@ -7,18 +7,12 @@ ObjectManagerNameChooser
First we need to import and setup some prerequisites:
>>> from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
>>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
>>> from Products.Five.browser.adding import ObjectManagerNameChooser
>>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
>>> chooser = ObjectManagerNameChooser(self.folder)
>>> id = self.folder._setObject('btreefolder', BTreeFolder2('btreefolder'))
>>> btreefolder = self.folder[id]
>>> manage_addFiveTraversableFolder(btreefolder, 'testoid', 'Testoid')
>>> chooser2 = ObjectManagerNameChooser(btreefolder)
Now we can start. ``INameChooser`` defines a ``checkName()`` method
that checks whether a given name is valid in the container or not.
Under the hood, ``ObjectManagerNameChooser`` calls ``_checkId()`` of
......@@ -26,25 +20,16 @@ the object manager. Valid names/ids are those that aren't in use yet
and don't contain invalid characters.
>>> chooser.checkName('abc', object())
>>> chooser2.checkName('abc', object())
>>> chooser.checkName('testoid', object())
Traceback (most recent call last):
...
UserError: The id "testoid" is invalid - it is already in use.
>>> chooser2.checkName('testoid', object())
Traceback (most recent call last):
...
UserError: The id "testoid" is invalid - it is already in use.
>>> chooser.checkName('slash/slash', object())
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
>>> chooser2.checkName('slash/slash', object())
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
``INameChooser`` also promises us a ``chooseName()`` method that
chooses a name for us in case we don't have one or that chooses a
......@@ -52,18 +37,12 @@ different name in case the one we chose was invalid.
>>> chooser.chooseName('', self.folder.testoid)
'FiveTraversableFolder'
>>> chooser2.chooseName('', self.folder.testoid)
'FiveTraversableFolder'
>>> chooser.chooseName('abc', self.folder.testoid)
'abc'
>>> chooser2.chooseName('abc', self.folder.testoid)
'abc'
>>> chooser.chooseName('testoid', self.folder.testoid)
'testoid-1'
>>> chooser2.chooseName('testoid', self.folder.testoid)
'testoid-1'
Of course, if we start out with something bad, it isn't going to
become good automagically:
......@@ -72,7 +51,3 @@ become good automagically:
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
>>> chooser2.chooseName('slash/slash', object())
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment