Back to index

plone3  3.1.7
Public Member Functions
CMFPlone.tests.testCheckId.TestCheckId Class Reference
Inheritance diagram for CMFPlone.tests.testCheckId.TestCheckId:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.tests.testCheckId.TestCheckId:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def testGoodId
def testEmptyId
def testRequiredId
def testAlternativeId
def testBadId
def testCatalogIndex
def testCatalogMetadata
def testCollision
def testTempObjectCollision
def testReservedId
def testHiddenObjectId
def testCanOverrideParentNames
def testInvalidId
def testContainerHook
def testContainerHookRaisesUnauthorized
def testContainerHookRaisesConflictError
def testMissingUtils
def testMissingCatalog
def testMissingFactory
def testCatalogIndexSkipped
def testCollisionSkipped
def testReservedIdSkipped
def testInvalidIdSkipped
def testParentMethodAliasDisallowed
def testCheckingMethodAliasesOnPortalRoot
def testProxyRoles
def setRequestMethod
def getAuthenticator
def setupAuthenticator

Detailed Description

Tests the check_id script

Definition at line 53 of file testCheckId.py.


Member Function Documentation

Definition at line 30 of file PloneTestCase.py.

00030 
00031     def getAuthenticator(self):
00032         tag = AuthenticatorView('context', 'request').authenticator()
00033         pattern = '<input .*name="(\w+)".*value="(\w+)"'
00034         return match(pattern, tag).groups()

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.tests.PloneTestCase.PloneTestCase.setRequestMethod (   self,
  method 
) [inherited]
This is a stub now, but in case you want to try
   something fancy on Your Branch (tm), put it here.

Definition at line 26 of file PloneTestCase.py.

00026 
00027     def setRequestMethod(self, method):
00028         self.app.REQUEST.set('REQUEST_METHOD', method)
00029         self.app.REQUEST.method = method

Here is the caller graph for this function:

Definition at line 35 of file PloneTestCase.py.

00035 
00036     def setupAuthenticator(self):
00037         name, token = self.getAuthenticator()
00038         self.app.REQUEST.form[name] = token
00039 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 68 of file testCheckId.py.

00068 
00069     def testAlternativeId(self):
00070         r = self.folder.check_id('', alternative_id='foo')
00071         self.assertEqual(r, None)   # success

Definition at line 72 of file testCheckId.py.

00072 
00073     def testBadId(self):
00074         r = self.folder.check_id('=')
00075         #self.assertEqual(r, "'=' is not a legal name.")
00076         self.assertEqual(r, u'${name} is not a legal name. The following characters are invalid: ${characters}')
00077         self.assertEqual(r.mapping[u'name'], '=')
00078         self.assertEqual(r.mapping[u'characters'], '=')

Definition at line 126 of file testCheckId.py.

00126 
00127     def testCanOverrideParentNames(self):
00128         self.folder.invokeFactory('Document', id='item1')
00129         self.folder.invokeFactory('Folder', id='folder1')
00130         self.folder.invokeFactory('Document', id='foo')
00131         r = self.folder.folder1.foo.check_id('item1')
00132         self.assertEqual(r, None)

Definition at line 79 of file testCheckId.py.

00079 
00080     def testCatalogIndex(self):
00081         # TODO: Tripwire
00082         portal_membership = getToolByName(self.portal, 'portal_membership')
00083         have_permission = portal_membership.checkPermission
00084         self.failUnless(have_permission('Search ZCatalog', self.portal.portal_catalog),
00085                         'Expected permission "Search ZCatalog"')
00086 
00087         r = self.folder.check_id('created')
00088         self.assertEqual(r, u'${name} is reserved.')
00089         self.assertEqual(r.mapping[u'name'], 'created')

Here is the call graph for this function:

Definition at line 177 of file testCheckId.py.

00177 
00178     def testCatalogIndexSkipped(self):
00179         # Note that the check is skipped when we don't have
00180         # the "Search ZCatalogs" permission.
00181         self.portal.manage_permission('Search ZCatalog', ['Manager'], acquire=0)
00182 
00183         r = self.folder.check_id('created')
00184         # But now the final hasattr check picks this up
00185         self.assertEqual(r, u'${name} is reserved.')
00186         self.assertEqual(r.mapping[u'name'], 'created')

Definition at line 90 of file testCheckId.py.

00090 
00091     def testCatalogMetadata(self):
00092         portal_catalog = getToolByName(self.portal, 'portal_catalog')
00093         portal_catalog.addColumn('new_metadata')
00094         self.failUnless('new_metadata' in portal_catalog.schema())
00095         self.failIf('new_metadata' in portal_catalog.indexes())
00096         r = self.folder.check_id('new_metadata')
00097         self.assertEqual(r, u'${name} is reserved.')
00098         self.assertEqual(r.mapping[u'name'], 'new_metadata')

Here is the call graph for this function:

Definition at line 228 of file testCheckId.py.

00228 
00229     def testCheckingMethodAliasesOnPortalRoot(self):
00230         # Test for bug http://dev.plone.org/plone/ticket/4351
00231         self.setRoles(['Manager'])
00232         self.portal.manage_permission('Add portal content', ['Manager'], acquire=0)
00233 
00234         # Should not raise: Before we were using obj.getTypeInfo(), which is
00235         # not defined on the portal root.
00236         try:
00237             self.portal.check_id('foo')
00238         except AttributeError, e:
00239             self.fail(e)

Here is the call graph for this function:

Definition at line 99 of file testCheckId.py.

00099 
00100     def testCollision(self):
00101         self.folder.invokeFactory('Document', id='foo')
00102         self.folder.invokeFactory('Document', id='bar')
00103         r = self.folder.foo.check_id('bar')
00104         self.assertEqual(r, u'There is already an item named ${name} in this folder.')
00105         self.assertEqual(r.mapping[u'name'], 'bar')

Definition at line 187 of file testCheckId.py.

00187 
00188     def testCollisionSkipped(self):
00189         # Note that check is skipped when we don't have
00190         # the "Access contents information" permission.
00191         self.folder.manage_permission('Access contents information', [], acquire=0)
00192 
00193         self.folder._setObject('foo', dummy.Item('foo'))
00194         self.folder._setObject('bar', dummy.Item('bar'))
00195         r = self.folder.foo.check_id('bar')
00196         self.assertEqual(r, None)   # success

Definition at line 139 of file testCheckId.py.

00139 
00140     def testContainerHook(self):
00141         # Container may have a checkValidId method; make sure it is called
00142         self.folder._setObject('checkValidId', dummy.Raiser(dummy.Error))
00143         self.folder._setObject('foo', dummy.Item('foo'))
00144         r = self.folder.foo.check_id('whatever')
00145         self.assertEqual(r, u'${name} is reserved.')
00146         self.assertEqual(r.mapping[u'name'], 'whatever')

Definition at line 153 of file testCheckId.py.

00153 
00154     def testContainerHookRaisesConflictError(self):
00155         # check_id should not swallow ConflictErrors raised by hook
00156         self.folder._setObject('checkValidId', dummy.Raiser(ConflictError))
00157         self.folder._setObject('foo', dummy.Item('foo'))
00158         self.assertRaises(ConflictError, self.folder.foo.check_id, 'whatever')

Definition at line 147 of file testCheckId.py.

00147 
00148     def testContainerHookRaisesUnauthorized(self):
00149         # check_id should not swallow Unauthorized errors raised by hook
00150         self.folder._setObject('checkValidId', dummy.Raiser(Unauthorized))
00151         self.folder._setObject('foo', dummy.Item('foo'))
00152         self.assertRaises(Unauthorized, self.folder.foo.check_id, 'whatever')

Definition at line 60 of file testCheckId.py.

00060 
00061     def testEmptyId(self):
00062         r = self.folder.check_id('')
00063         self.assertEqual(r, None)   # success

Definition at line 56 of file testCheckId.py.

00056 
00057     def testGoodId(self):
00058         r = self.folder.check_id('foo')
00059         self.assertEqual(r, None)   # success

Definition at line 119 of file testCheckId.py.

00119 
00120     def testHiddenObjectId(self):
00121         # If a parallel object is not in content-space, should get 'reserved'
00122         # instead of 'taken'
00123         r = self.folder.check_id('portal_skins')
00124         self.assertEqual(r, u'${name} is reserved.')
00125         self.assertEqual(r.mapping[u'name'], 'portal_skins')

Definition at line 133 of file testCheckId.py.

00133 
00134     def testInvalidId(self):
00135         self.folder._setObject('foo', dummy.Item('foo'))
00136         r = self.folder.foo.check_id('_foo')
00137         self.assertEqual(r, u'${name} is reserved.')
00138         self.assertEqual(r.mapping[u'name'], '_foo')

Definition at line 208 of file testCheckId.py.

00208 
00209     def testInvalidIdSkipped(self):
00210         # Note that the check is skipped when we don't have
00211         # the "Add portal content" permission.
00212         self.folder.manage_permission('Add portal content', [], acquire=0)
00213 
00214         self.folder._setObject('foo', dummy.Item('foo'))
00215         r = self.folder.foo.check_id('_foo')
00216         self.assertEqual(r, None)   # success

Definition at line 165 of file testCheckId.py.

00165 
00166     def testMissingCatalog(self):
00167         # check_id should not bomb out if the portal_catalog tool is missing
00168         self.portal._delObject('portal_catalog')
00169         r = self.folder.check_id('foo')
00170         self.assertEqual(r, None)   # success

Definition at line 171 of file testCheckId.py.

00171 
00172     def testMissingFactory(self):
00173         # check_id should not bomb out if the portal_factory tool is missing
00174         self.portal._delObject('portal_factory')
00175         r = self.folder.check_id('foo')
00176         self.assertEqual(r, None)   # success

Definition at line 159 of file testCheckId.py.

00159 
00160     def testMissingUtils(self):
00161         # check_id should not bomb out if the plone_utils tool is missing
00162         self.portal._delObject('plone_utils')
00163         r = self.folder.check_id('foo')
00164         self.assertEqual(r, None)   # success

Definition at line 217 of file testCheckId.py.

00217 
00218     def testParentMethodAliasDisallowed(self):
00219         # Note that the check is skipped when we don't have
00220         # the "Add portal content" permission.
00221         self.folder.manage_permission('Add portal content', ['Manager'], acquire=0)
00222 
00223         self.folder._setObject('foo', dummy.Item('foo'))
00224         for alias in self.folder.getTypeInfo().getMethodAliases().keys():
00225             r = self.folder.foo.check_id(alias)
00226             self.assertEqual(r, u'${name} is reserved.')
00227             self.assertEqual(r.mapping[u'name'], alias)

Definition at line 240 of file testCheckId.py.

00240 
00241     def testProxyRoles(self):
00242         # Proxy roles should cover missing view permission for all but the
00243         # most unusual workflows.
00244         proxy_roles = self.folder.check_id._proxy_roles
00245         self.failUnless('Manager' in proxy_roles)
00246         self.failUnless('Owner' in proxy_roles)
00247         self.failUnless('Authenticated' in proxy_roles)
00248         self.failUnless('Anonymous' in proxy_roles)

Definition at line 64 of file testCheckId.py.

00064 
00065     def testRequiredId(self):
00066         r = self.folder.check_id('', required=1)
00067         self.assertEqual(r, u'Please enter a name.')

Definition at line 113 of file testCheckId.py.

00113 
00114     def testReservedId(self):
00115         self.folder._setObject('foo', dummy.Item('foo'))
00116         r = self.folder.foo.check_id('portal_catalog')
00117         self.assertEqual(r, u'${name} is reserved.')
00118         self.assertEqual(r.mapping[u'name'], 'portal_catalog')

Definition at line 197 of file testCheckId.py.

00197 
00198     def testReservedIdSkipped(self):
00199         # This check is picked up by the checkIdAvailable, unless we don't have
00200         # the "Add portal content" permission, in which case it is picked up by
00201         # the final hasattr check.
00202         self.folder.manage_permission('Add portal content', [], acquire=0)
00203 
00204         self.folder._setObject('foo', dummy.Item('foo'))
00205         r = self.folder.foo.check_id('portal_catalog')
00206         self.assertEqual(r, u'${name} is reserved.')
00207         self.assertEqual(r.mapping[u'name'], 'portal_catalog')

Definition at line 106 of file testCheckId.py.

00106 
00107     def testTempObjectCollision(self):
00108         foo = self.folder.restrictedTraverse('portal_factory/Document/foo')
00109         self.folder._setObject('bar', dummy.Item('bar'))
00110         r = foo.check_id('bar')
00111         self.assertEqual(r, u'${name} is reserved.')
00112         self.assertEqual(r.mapping[u'name'], 'bar')


The documentation for this class was generated from the following file: