Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
4652368b
Commit
4652368b
authored
Jun 25, 2009
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fixed ObjectManagerNameChooser: BTreeFolder2 raises KeyError, not AttributeError
parent
5301e7f2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
4 deletions
+29
-4
src/Products/Five/browser/adding.py
src/Products/Five/browser/adding.py
+4
-4
src/Products/Five/browser/tests/adding.txt
src/Products/Five/browser/tests/adding.txt
+25
-0
No files found.
src/Products/Five/browser/adding.py
View file @
4652368b
...
@@ -248,7 +248,7 @@ class ObjectManagerNameChooser:
...
@@ -248,7 +248,7 @@ class ObjectManagerNameChooser:
i
+=
1
i
+=
1
try
:
try
:
self
.
context
.
_getOb
(
n
)
self
.
context
.
_getOb
(
n
)
except
AttributeError
:
except
(
AttributeError
,
KeyError
)
:
break
break
n
=
name
+
'-'
+
str
(
i
)
+
suffix
n
=
name
+
'-'
+
str
(
i
)
+
suffix
...
...
src/Products/Five/browser/tests/adding.txt
View file @
4652368b
...
@@ -7,12 +7,18 @@ ObjectManagerNameChooser
...
@@ -7,12 +7,18 @@ ObjectManagerNameChooser
First we need to import and setup some prerequisites:
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.tests.testing import manage_addFiveTraversableFolder
>>> from Products.Five.browser.adding import ObjectManagerNameChooser
>>> from Products.Five.browser.adding import ObjectManagerNameChooser
>>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
>>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
>>> chooser = ObjectManagerNameChooser(self.folder)
>>> 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
Now we can start. ``INameChooser`` defines a ``checkName()`` method
that checks whether a given name is valid in the container or not.
that checks whether a given name is valid in the container or not.
Under the hood, ``ObjectManagerNameChooser`` calls ``_checkId()`` of
Under the hood, ``ObjectManagerNameChooser`` calls ``_checkId()`` of
...
@@ -20,16 +26,25 @@ the object manager. Valid names/ids are those that aren't in use yet
...
@@ -20,16 +26,25 @@ the object manager. Valid names/ids are those that aren't in use yet
and don't contain invalid characters.
and don't contain invalid characters.
>>> chooser.checkName('abc', object())
>>> chooser.checkName('abc', object())
>>> chooser2.checkName('abc', object())
>>> chooser.checkName('testoid', object())
>>> chooser.checkName('testoid', object())
Traceback (most recent call last):
Traceback (most recent call last):
...
...
UserError: The id "testoid" is invalid - it is already in use.
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())
>>> chooser.checkName('slash/slash', object())
Traceback (most recent call last):
Traceback (most recent call last):
...
...
UserError: The id "slash/slash" contains characters illegal in URLs.
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
``INameChooser`` also promises us a ``chooseName()`` method that
chooses a name for us in case we don't have one or that chooses a
chooses a name for us in case we don't have one or that chooses a
...
@@ -37,12 +52,18 @@ different name in case the one we chose was invalid.
...
@@ -37,12 +52,18 @@ different name in case the one we chose was invalid.
>>> chooser.chooseName('', self.folder.testoid)
>>> chooser.chooseName('', self.folder.testoid)
'FiveTraversableFolder'
'FiveTraversableFolder'
>>> chooser2.chooseName('', self.folder.testoid)
'FiveTraversableFolder'
>>> chooser.chooseName('abc', self.folder.testoid)
>>> chooser.chooseName('abc', self.folder.testoid)
'abc'
'abc'
>>> chooser2.chooseName('abc', self.folder.testoid)
'abc'
>>> chooser.chooseName('testoid', self.folder.testoid)
>>> chooser.chooseName('testoid', self.folder.testoid)
'testoid-1'
'testoid-1'
>>> chooser2.chooseName('testoid', self.folder.testoid)
'testoid-1'
Of course, if we start out with something bad, it isn't going to
Of course, if we start out with something bad, it isn't going to
become good automagically:
become good automagically:
...
@@ -51,3 +72,7 @@ become good automagically:
...
@@ -51,3 +72,7 @@ become good automagically:
Traceback (most recent call last):
Traceback (most recent call last):
...
...
UserError: The id "slash/slash" contains characters illegal in URLs.
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.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment