[CMF-checkins] CVS: Products/CMFCore/tests -
test_CMFCatalogAware.py:1.1.4.2
Florent Guillaume
fg at nuxeo.com
Fri Apr 22 14:50:32 EDT 2005
Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv9874/CMFCore/tests
Modified Files:
Tag: CMF-1_5-branch
test_CMFCatalogAware.py
Log Message:
Use _unrestrictedGetObject when available, and LOG when the object
cannot be retrieved.
=== Products/CMFCore/tests/test_CMFCatalogAware.py 1.1.4.1 => 1.1.4.2 ===
--- Products/CMFCore/tests/test_CMFCatalogAware.py:1.1.4.1 Thu Apr 14 15:53:39 2005
+++ Products/CMFCore/tests/test_CMFCatalogAware.py Fri Apr 22 14:50:32 2005
@@ -19,14 +19,16 @@
import Testing
try:
- import Zope2
+ import Zope2
except ImportError:
# BBB: for Zope 2.7
import Zope as Zope2
Zope2.startup()
+from zExceptions import NotFound
from OFS.Folder import Folder
from OFS.SimpleItem import SimpleItem
+from Products.ZCatalog import CatalogBrains
from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
@@ -42,7 +44,31 @@
def getPhysicalRoot(self):
return self
+class DummyOldBrain:
+ def __init__(self, ob, path):
+ self.ob = ob
+ self.id = ob.getId()
+ self.path = path
+ def getPath(self):
+ return self.path
+ def getObject(self):
+ if self.id == 'missing':
+ if self.ob.GETOBJECT_RAISES:
+ raise NotFound("missing")
+ else:
+ return None
+ if self.id == 'hop':
+ raise ValueError("security problem for this object")
+ return self.ob
+
+class DummyBrain(DummyOldBrain):
+ def _unrestrictedGetObject(self):
+ if self.id == 'missing':
+ return self.getObject()
+ return self.ob
+
class DummyCatalog(SimpleItem):
+ brain_class = DummyBrain
def __init__(self):
self.log = []
self.obs = []
@@ -62,20 +88,9 @@
if obpath == path:
# Normal PathIndex skips initial value
continue
- res.append(DummyBrain(ob, obpath))
+ res.append(self.brain_class(ob, obpath))
return res
-class DummyBrain:
- def __init__(self, ob, path):
- self.ob = ob
- self.path = path
- def getPath(self):
- return self.path
- def getObject(self):
- if self.ob.getId() == 'hop':
- raise ValueError("security problem for this object")
- return self.ob
-
class TheClass(CMFCatalogAware, Folder):
def __init__(self, id):
@@ -139,6 +154,63 @@
self.failIf(foo.notified)
self.failIf(bar.notified)
self.failIf(hop.notified)
+
+ def test_reindexObjectSecurity_oldbrain(self):
+ self.site.portal_catalog.brain_class = DummyOldBrain
+ foo = self.site.foo
+ self.site.foo.bar = TheClass('bar')
+ bar = self.site.foo.bar
+ self.site.foo.hop = TheClass('hop')
+ hop = self.site.foo.hop
+ cat = self.site.portal_catalog
+ cat.setObs([foo, bar, hop])
+ foo.reindexObjectSecurity()
+ l = list(cat.log)
+ l.sort()
+ self.assertEquals(l, [
+ "reindex /site/foo ['allowedRolesAndUsers']",
+ "reindex /site/foo/bar ['allowedRolesAndUsers']",
+ "reindex /site/foo/hop ['allowedRolesAndUsers']",
+ ])
+ self.failIf(foo.notified)
+ self.failIf(bar.notified)
+ self.failIf(hop.notified)
+
+ def test_reindexObjectSecurity_missing_raise(self):
+ # Exception raised for missing object (Zope 2.8 brains)
+ foo = self.site.foo
+ missing = TheClass('missing').__of__(foo)
+ missing.GETOBJECT_RAISES = True
+ cat = self.site.portal_catalog
+ cat.setObs([foo, missing])
+ self.assertRaises(NotFound, foo.reindexObjectSecurity)
+
+ def test_reindexObjectSecurity_missing_noraise(self):
+ # Raising disabled
+ foo = self.site.foo
+ missing = TheClass('missing').__of__(foo)
+ missing.GETOBJECT_RAISES = False
+ cat = self.site.portal_catalog
+ cat.setObs([foo, missing])
+ foo.reindexObjectSecurity()
+ self.assertEquals(cat.log,
+ ["reindex /site/foo ['allowedRolesAndUsers']"])
+ self.failIf(foo.notified)
+ self.failIf(missing.notified)
+
+ def test_reindexObjectSecurity_missing_oldbrain(self):
+ # Missing object is swallowed by old Zope brains
+ self.site.portal_catalog.brain_class = DummyOldBrain
+ foo = self.site.foo
+ missing = TheClass('missing').__of__(foo)
+ missing.GETOBJECT_RAISES = True
+ cat = self.site.portal_catalog
+ cat.setObs([foo, missing])
+ foo.reindexObjectSecurity()
+ self.assertEquals(cat.log,
+ ["reindex /site/foo ['allowedRolesAndUsers']"])
+ self.failIf(foo.notified)
+ self.failIf(missing.notified)
# FIXME: more tests needed
More information about the CMF-checkins
mailing list