[CMF-checkins] CVS: Products/CMFCore/tests -
test_CatalogTool.py:1.3.14.1
Florent Guillaume
fg at nuxeo.com
Tue Nov 16 16:52:37 EST 2004
Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv22645/tests
Modified Files:
Tag: CMF-1_4-branch
test_CatalogTool.py
Log Message:
Collector #120: Take into account query restrictions on 'effective' or
'expires' attributes during a search.
=== Products/CMFCore/tests/test_CatalogTool.py 1.3 => 1.3.14.1 ===
--- Products/CMFCore/tests/test_CatalogTool.py:1.3 Mon Jan 6 15:40:46 2003
+++ Products/CMFCore/tests/test_CatalogTool.py Tue Nov 16 16:52:07 2004
@@ -2,11 +2,22 @@
import Zope
try:
+ Zope.startup()
+except AttributeError:
+ pass
+
+try:
from Interface.Verify import verifyClass
except ImportError:
# for Zope versions before 2.6.0
from Interface import verify_class_implementation as verifyClass
+from DateTime import DateTime
+from Products.CMFCore.tests.base.testcase import SecurityTest
+from Products.CMFCore.tests.base.security import UserWithRoles
+from Products.CMFCore.tests.base.security import OmnipotentUser
+from AccessControl.SecurityManagement import newSecurityManager
+
from Products.CMFCore.tests.base.dummy import \
DummyContent
@@ -23,7 +34,15 @@
verifyClass(IIndexableObjectWrapper, IndexableObjectWrapper)
-class CatalogToolTests( TestCase ):
+class CatalogToolTests(SecurityTest):
+
+ def loginWithRoles(self, *roles):
+ user = UserWithRoles(*roles).__of__(self.root)
+ newSecurityManager(None, user)
+
+ def loginManager(self):
+ user = OmnipotentUser().__of__(self.root)
+ newSecurityManager(None, user)
def test_processActions( self ):
"""
@@ -45,6 +64,179 @@
verifyClass(ICatalogTool, CatalogTool)
verifyClass(IActionProvider, CatalogTool)
+ def test_search_anonymous(self):
+ catalog = CatalogTool()
+ dummy = DummyContent(catalog=1)
+ catalog.catalog_object(dummy, '/dummy')
+
+ self.assertEqual(1, len(catalog._catalog.searchResults()))
+ self.assertEqual(0, len(catalog.searchResults()))
+
+ def test_search_inactive(self):
+ catalog = CatalogTool()
+ now = DateTime()
+ dummy = DummyContent(catalog=1)
+ dummy._View_Permission = ('Blob',)
+
+ self.loginWithRoles('Blob')
+
+ # not yet effective
+ dummy.effective = now+1
+ dummy.expires = now+2
+ catalog.catalog_object(dummy, '/dummy')
+ self.assertEqual(1, len(catalog._catalog.searchResults()))
+ self.assertEqual(0, len(catalog.searchResults()))
+
+ # already expired
+ dummy.effective = now-2
+ dummy.expires = now-1
+ catalog.catalog_object(dummy, '/dummy')
+ self.assertEqual(1, len(catalog._catalog.searchResults()))
+ self.assertEqual(0, len(catalog.searchResults()))
+
+ def test_search_restrict_manager(self):
+ catalog = CatalogTool()
+ now = DateTime()
+ dummy = DummyContent(catalog=1)
+
+ self.loginManager()
+
+ # already expired
+ dummy.effective = now-4
+ dummy.expires = now-2
+ catalog.catalog_object(dummy, '/dummy')
+ self.assertEqual(1, len(catalog._catalog.searchResults()))
+ self.assertEqual(1, len(catalog.searchResults()))
+
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': now-3, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now-1, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now-3, 'range': 'max'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': now-1, 'range': 'max'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': (now-3, now-1), 'range': 'min:max'})))
+
+ def test_search_restrict_inactive(self):
+ catalog = CatalogTool()
+ now = DateTime()
+ dummy = DummyContent(catalog=1)
+ dummy._View_Permission = ('Blob',)
+
+ self.loginWithRoles('Blob')
+
+ # already expired
+ dummy.effective = now-4
+ dummy.expires = now-2
+ catalog.catalog_object(dummy, '/dummy')
+ self.assertEqual(1, len(catalog._catalog.searchResults()))
+ self.assertEqual(0, len(catalog.searchResults()))
+
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now-3, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now-3, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now+3, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now+3, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': (now-3, now-1), 'range': 'min:max'})))
+
+ def test_search_restrict_visible(self):
+ catalog = CatalogTool()
+ now = DateTime()
+ dummy = DummyContent(catalog=1)
+ dummy._View_Permission = ('Blob',)
+
+ self.loginWithRoles('Blob')
+
+ # visible
+ dummy.effective = now-2
+ dummy.expires = now+2
+ catalog.catalog_object(dummy, '/dummy')
+ self.assertEqual(1, len(catalog._catalog.searchResults()))
+ self.assertEqual(1, len(catalog.searchResults()))
+
+ self.assertEqual(0, len(catalog.searchResults(
+ effective={'query': now-1, 'range': 'min'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ effective={'query': now-1, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ effective={'query': now+1, 'range': 'min'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ effective={'query': now+1, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ effective={'query': (now-1, now+1), 'range': 'min:max'})))
+
+ self.assertEqual(1, len(catalog.searchResults(
+ effective={'query': now-3, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ effective={'query': now-3, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ effective={'query': now+3, 'range': 'min'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ effective={'query': now+3, 'range': 'max'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ effective={'query': (now-3, now+3), 'range': 'min:max'})))
+
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': now-1, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now-1, 'range': 'max'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': now+1, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now+1, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': (now-1, now+1), 'range': 'min:max'})))
+
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': now-3, 'range': 'min'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now-3, 'range': 'max'})))
+ self.assertEqual(0, len(catalog.searchResults(
+ expires={'query': now+3, 'range': 'min'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': now+3, 'range': 'max'})))
+ self.assertEqual(1, len(catalog.searchResults(
+ expires={'query': (now-3, now+3), 'range': 'min:max'})))
+
+ self.assertEqual(1, len(catalog.searchResults(
+ effective={'query': now-1, 'range': 'max'},
+ expires={'query': now+1, 'range': 'min'})))
+
+ self.assertEqual(0, len(catalog.searchResults(
+ effective={'query': now+1, 'range': 'max'},
+ expires={'query': now+3, 'range': 'min'})))
+
+ def test_convertQuery(self):
+ convert = CatalogTool()._convertQuery
+
+ kw = {}
+ convert(kw)
+ self.assertEqual(kw, {})
+
+ kw = {'expires': 5, 'expires_usage': 'brrr:min'}
+ self.assertRaises(ValueError, convert, kw)
+
+ kw = {'foo': 'bar'}
+ convert(kw)
+ self.assertEqual(kw, {'foo': 'bar'})
+
+ kw = {'expires': 5, 'expires_usage': 'range:min'}
+ convert(kw)
+ self.assertEqual(kw, {'expires': {'query': 5, 'range': 'min'}})
+
+ kw = {'expires': 5, 'expires_usage': 'range:max'}
+ convert(kw)
+ self.assertEqual(kw, {'expires': {'query': 5, 'range': 'max'}})
+
+ kw = {'expires': (5,7), 'expires_usage': 'range:min:max'}
+ convert(kw)
+ self.assertEqual(kw, {'expires': {'query': (5,7), 'range': 'min:max'}})
def test_suite():
return TestSuite((
More information about the CMF-checkins
mailing list