logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

CVS: Products/CMFCore/tests - test_CatalogTool.py:1.7.14.1: msg#00055

web.zope.cmf.cvs

Subject: CVS: Products/CMFCore/tests - test_CatalogTool.py:1.7.14.1

Update of /cvs-repository/Products/CMFCore/tests
In directory cvs.zope.org:/tmp/cvs-serv25488/CMFCore/tests

Modified Files:
Tag: CMF-1_5-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.7 => 1.7.14.1 ===
--- Products/CMFCore/tests/test_CatalogTool.py:1.7 Mon Apr 26 08:14:17 2004
+++ Products/CMFCore/tests/test_CatalogTool.py Tue Nov 16 17:03:03 2004
@@ -4,9 +4,14 @@
Zope.startup()
from Interface.Verify import verifyClass

+from DateTime import DateTime
from Products.CMFCore.CatalogTool import CatalogTool
from Products.CMFCore.CatalogTool import IndexableObjectWrapper
from Products.CMFCore.tests.base.dummy import DummyContent
+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


class IndexableObjectWrapperTests(TestCase):
@@ -18,7 +23,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 ):
"""
@@ -42,6 +55,179 @@
verifyClass(IActionProvider, CatalogTool)
verifyClass(IZCatalog, 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():


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation