vendor/Five/1.2b-r20590

view browser/tests/adding.txt @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ============
2 Adding tests
3 ============
5 ObjectManagerNameChooser
6 ------------------------
8 First we need to import and setup some prerequisites:
10 >>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
11 >>> from Products.Five.browser.adding import ObjectManagerNameChooser
13 >>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
14 >>> chooser = ObjectManagerNameChooser(self.folder)
16 Now we can start. ``INameChooser`` defines a ``checkName()`` method
17 that checks whether a given name is valid in the container or not.
18 Under the hood, ``ObjectManagerNameChooser`` calls ``_checkId()`` of
19 the object manager. Valid names/ids are those that aren't in use yet
20 and don't contain invalid characters.
22 >>> chooser.checkName('abc', object())
24 >>> chooser.checkName('testoid', object())
25 Traceback (most recent call last):
26 ...
27 UserError: The id "testoid" is invalid - it is already in use.
29 >>> chooser.checkName('slash/slash', object())
30 Traceback (most recent call last):
31 ...
32 UserError: The id "slash/slash" contains characters illegal in URLs.
34 ``INameChooser`` also promises us a ``chooseName()`` method that
35 chooses a name for us in case we don't have one or that chooses a
36 different name in case the one we chose was invalid.
38 >>> chooser.chooseName('', self.folder.testoid)
39 'FiveTraversableFolder'
41 >>> chooser.chooseName('abc', self.folder.testoid)
42 'abc'
44 >>> chooser.chooseName('testoid', self.folder.testoid)
45 'testoid-1'
47 Of course, if we start out with something bad, it isn't going to
48 become good automagically:
50 >>> chooser.chooseName('slash/slash', object())
51 Traceback (most recent call last):
52 ...
53 UserError: The id "slash/slash" contains characters illegal in URLs.