[Checkins] SVN: grok/trunk/ Test the catalog as an example of a local persistent utility.

Philipp von Weitershausen philikon at philikon.de
Sun Jan 7 12:41:53 EST 2007


Log message for revision 71781:
  Test the catalog as an example of a local persistent utility.
  

Changed:
  U   grok/trunk/buildout.cfg
  A   grok/trunk/src/grok/ftests/catalog/
  A   grok/trunk/src/grok/ftests/catalog/__init__.py
  A   grok/trunk/src/grok/ftests/catalog/catalog.py
  U   grok/trunk/src/grok/ftests/test_grok_functional.py

-=-
Modified: grok/trunk/buildout.cfg
===================================================================
--- grok/trunk/buildout.cfg	2007-01-07 17:28:37 UTC (rev 71780)
+++ grok/trunk/buildout.cfg	2007-01-07 17:41:52 UTC (rev 71781)
@@ -33,6 +33,9 @@
        zope.app.securitypolicy
        zope.app.securitypolicy-meta
        zope.app.authentication
+       zope.app.catalog
+       zope.app.intid
+       zope.app.keyreference
        grok
        grok-meta
 
@@ -45,25 +48,8 @@
        grokwiki
        grokblog
 
-zcml = zope.annotation
-       zope.copypastemove
-       zope.formlib
-       zope.i18n-meta
-       zope.i18n.locales
-       zope.publisher
-       zope.security-meta
-       zope.size
-       zope.traversing
-       zope.traversing.browser
-       zope.app    
-       zope.app-meta
-       zope.app.securitypolicy
-       zope.app.securitypolicy-meta
-       zope.app.authentication
+zcml = ${testinstance:zcml}
        zope.app.twisted
-
-       grok
-       grok-meta
        grokwiki
        grokblog
 

Added: grok/trunk/src/grok/ftests/catalog/__init__.py
===================================================================
--- grok/trunk/src/grok/ftests/catalog/__init__.py	2007-01-07 17:28:37 UTC (rev 71780)
+++ grok/trunk/src/grok/ftests/catalog/__init__.py	2007-01-07 17:41:52 UTC (rev 71781)
@@ -0,0 +1 @@
+# make this directory a package


Property changes on: grok/trunk/src/grok/ftests/catalog/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: grok/trunk/src/grok/ftests/catalog/catalog.py
===================================================================
--- grok/trunk/src/grok/ftests/catalog/catalog.py	2007-01-07 17:28:37 UTC (rev 71780)
+++ grok/trunk/src/grok/ftests/catalog/catalog.py	2007-01-07 17:41:52 UTC (rev 71781)
@@ -0,0 +1,52 @@
+"""
+  >>> import grok
+  >>> from grok.ftests.catalog.catalog import Mammoth, Herd
+  >>> grok.grok('grok.ftests.catalog.catalog')
+
+Let's setup a site in which we manage a couple of objects:
+
+  >>> herd = Herd()
+  >>> getRootFolder()['herd'] = herd
+  >>> from zope.app.component.hooks import setSite
+  >>> setSite(herd)
+
+Now we add some indexable objects to the site:
+
+  >>> herd['manfred'] = Mammoth('Manfred')
+  >>> herd['ellie'] = Mammoth('Ellie')
+
+Then we are able to query the catalog:
+
+  >>> from zope.app.catalog.interfaces import ICatalog
+  >>> from zope.component import getUtility
+  >>> catalog = getUtility(ICatalog)
+  >>> for obj in catalog.searchResults(name=('Ellie', 'Ellie')):
+  ...     print obj.name
+  Ellie
+
+"""
+
+import grok
+from zope import schema, interface
+from zope.app.intid import IntIds
+from zope.app.intid.interfaces import IIntIds
+from zope.app.catalog.catalog import Catalog
+from zope.app.catalog.interfaces import ICatalog
+from zope.app.catalog.field import FieldIndex
+
+def setup_catalog(catalog):
+    catalog['name'] = FieldIndex('name', IMammoth)
+
+class IMammoth(interface.Interface):
+
+    name = schema.TextLine()
+
+class Mammoth(grok.Model):
+    grok.implements(IMammoth)
+
+    def __init__(self, name):
+        self.name = name
+
+class Herd(grok.Container, grok.Site):
+    grok.local_utility(IntIds, provides=IIntIds)
+    grok.local_utility(Catalog, provides=ICatalog, setup=setup_catalog)


Property changes on: grok/trunk/src/grok/ftests/catalog/catalog.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: grok/trunk/src/grok/ftests/test_grok_functional.py
===================================================================
--- grok/trunk/src/grok/ftests/test_grok_functional.py	2007-01-07 17:28:37 UTC (rev 71780)
+++ grok/trunk/src/grok/ftests/test_grok_functional.py	2007-01-07 17:41:52 UTC (rev 71781)
@@ -57,7 +57,7 @@
 def test_suite():
     suite = unittest.TestSuite()
     for name in ['view', 'static', 'xmlrpc', 'traversal', 'form', 'url',
-                 'security', 'utility']:
+                 'security', 'utility', 'catalog']:
         suite.addTest(suiteFromPackage(name))
     return suite
 



More information about the Checkins mailing list