[Zope3-checkins] CVS: Zope3/src/zope/app/catalog - ftests.py:1.1 tests.py:1.1 README.txt:1.2 catalog.py:1.18 configure.zcml:1.6

Philipp von Weitershausen philikon at philikon.de
Mon Mar 1 06:46:53 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/catalog
In directory cvs.zope.org:/tmp/cvs-serv30793/catalog

Modified Files:
	README.txt catalog.py configure.zcml 
Added Files:
	ftests.py tests.py 
Log Message:
Catalog, its interfaces and its browser views are now located in
zope.app.catalog.


=== Added File Zope3/src/zope/app/catalog/ftests.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Functional tests for catalog

$Id: ftests.py,v 1.1 2004/03/01 11:46:22 philikon Exp $
"""
import unittest

from zope.testing.functional import BrowserTestCase

class TestCatalogAdd(BrowserTestCase):

    def testAddCatalog(self):
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'zope.app.catalog', 
                                      'id':u'felix_the'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                                         'http://localhost/@@contents.html')

        response = self.publish('/')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find('felix_the') != -1)
        response = self.publish('/felix_the/@@index.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find('Advanced Catalog Thingies') != -1)

        # first test the multi-page add screens work
        response = self.publish("/felix_the/+/action.html", 
                        basic='mgr:mgrpw', 
                        form={'type_name':u'AddFieldIndexToCatalog',
                              'id':u'dctitle',})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                 'http://localhost/felix_the/+/AddFieldIndexToCatalog=dctitle')
        response = self.publish("/felix_the/+/AddFieldIndexToCatalog=dctitle",
                        basic='mgr:mgrpw', 
                        form={'field.interface': 
                              u'zope.app.interfaces.dublincore.IZopeDublinCore',
                              'field.field_name':u'Title', 
                              'UPDATE_SUBMIT': u'Submit'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                 'http://localhost/felix_the/@@contents.html')

        # and a couple more indexes now - first a full text index
        response = self.publish("/felix_the/+/AddTextIndexToCatalog=fulltext",
                        basic='mgr:mgrpw', 
                        form={'field.interface':
                               'zope.app.interfaces.index.text.ISearchableText',
                              'field.field_name':'getSearchableText',
                              'UPDATE_SUBMIT': u'Submit'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                 'http://localhost/felix_the/@@contents.html')

        # Single page submit
        response = self.publish("/felix_the/+/AddFieldIndexToCatalog=name",
                        basic='mgr:mgrpw', 
                        form={'field.interface.search': '',
                              'field.field_name':'id',
                               'UPDATE_SUBMIT': u'Submit'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                 'http://localhost/felix_the/@@contents.html')

        # keyword index 
        response = self.publish("/felix_the/+/AddKeywordIndexToCatalog=dccreator",
                        basic='mgr:mgrpw', 
                        form={'field.interface': 
                              u'zope.app.interfaces.dublincore.IZopeDublinCore',
                              'field.field_name':u'Creator', 
                              'UPDATE_SUBMIT': u'Submit'})
        self.assertEqual(response.getStatus(), 302)
        self.assertEqual(response.getHeader('Location'),
                 'http://localhost/felix_the/@@contents.html')

        # Check the indexes are there and visible
        response = self.publish('/felix_the/@@contents.html', basic='mgr:mgrpw')
        self.assertEqual(response.getStatus(), 200)
        self.assert_(response.getBody().find('dctitle') != -1)
        self.assert_(response.getBody().find('dccreator') != -1)
        
        # Now add some content
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'File', 
                                      'id':u'First'})
        self.assertEqual(response.getStatus(), 302)
        response = self.publish("/First/@@EditMetaData.html",basic='mgr:mgrpw',
                                form={'dctitle':u'First File',
                                      'dcdescription':u'a file with stuff',
                                      'save':u'Save Changes',
                                      })
        self.assertEqual(response.getStatus(), 200)
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'File', 
                                      'id':u'Second'})
        self.assertEqual(response.getStatus(), 302)
        response = self.publish("/Second/@@EditMetaData.html",basic='mgr:mgrpw',
                                form={'dctitle':u'Second File',
                                      'dcdescription':u'another file of stuff',
                                      'save':u'Save Changes',
                                      })
        self.assertEqual(response.getStatus(), 200)

        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'File', 
                                      'id':u'Third'})
        self.assertEqual(response.getStatus(), 302)
        response = self.publish("/Third/@@EditMetaData.html",basic='mgr:mgrpw',
                                form={'dctitle':u'Third File',
                                      'dcdescription':u'something else',
                                      'save':u'Save Changes',
                                      })
        self.assertEqual(response.getStatus(), 200)
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'File', 
                                      'id':u'Thirda'})
        self.assertEqual(response.getStatus(), 302)
        response = self.publish("/Thirda/@@EditMetaData.html",basic='mgr:mgrpw',
                                form={'dctitle':u'Third File',
                                      'dcdescription':u'something else',
                                      'save':u'Save Changes',
                                      })
        self.assertEqual(response.getStatus(), 200)
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'ZPTPage', 
                                      'id':u'Page1'})
        self.assertEqual(response.getStatus(), 302)
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'ZPTPage', 
                                      'id':u'Page2'})
        self.assertEqual(response.getStatus(), 302)
        response = self.publish("/+/action.html", basic='mgr:mgrpw', 
                                form={'type_name':u'ZPTPage', 
                                      'id':u'Page3'})
        self.assertEqual(response.getStatus(), 302)

        response = self.publish("/Page1/@@edit.html", basic='mgr:mgrpw', 
                                form={'field.source':u'Some sample text',
                                      'field.expand':u'',
                                      'field.expand.used':u'',
                                      'UPDATE_SUBMIT':u'Submit'})
        self.assertEqual(response.getStatus(), 200)
        response = self.publish("/Page2/@@edit.html", basic='mgr:mgrpw', 
                                form={'field.source':u'Some other text',
                                      'field.expand':u'',
                                      'field.expand.used':u'',
                                      'UPDATE_SUBMIT':u'Submit'})
        self.assertEqual(response.getStatus(), 200)
        response = self.publish("/Page3/@@edit.html", basic='mgr:mgrpw', 
                                form={'field.source':u'Different sample text',
                                      'field.expand':u'',
                                      'field.expand.used':u'',
                                      'UPDATE_SUBMIT':u'Submit'})
        self.assertEqual(response.getStatus(), 200)
        response = self.publish("/Page3/@@EditMetaData.html",basic='mgr:mgrpw',
                                form={'dctitle':u'Third File',
                                      'dcdescription':u'something else',
                                      'save':u'Save Changes',
                                      })
        self.assertEqual(response.getStatus(), 200)

        root = self.getRootFolder()
        cat = root['felix_the']
        name = cat['dctitle']
        self.assert_(name.documentCount()==8)
        res = cat.searchResults(dctitle='Second File')
        self.assert_(len(res)==1)
        res = cat.searchResults(dctitle='Third File')
        self.assert_(len(res)==3)
        res = cat.searchResults(fulltext='sample')
        self.assert_(len(res)==2)
        res = cat.searchResults(fulltext='sample', dctitle='Third File')
        self.assert_(len(res)==1)
        res = cat.searchResults(fulltext='fnargle', dctitle='Third File')
        self.assert_(len(res)==0)
        res = cat.searchResults(fulltext='sample', dctitle='Zeroth File')
        self.assert_(len(res)==0)
        res = cat.searchResults(dccreator='zope.mgr', dctitle='Third File')
        self.assert_(len(res)==3)

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestCatalogAdd))
    return suite

if __name__=='__main__':
    unittest.main(defaultTest='test_suite')



=== Added File Zope3/src/zope/app/catalog/tests.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests for catalog

Note that indexes &c already have test suites, we only have to check that
a catalog passes on events that it receives.

$Id: tests.py,v 1.1 2004/03/01 11:46:22 philikon Exp $
"""

import unittest

from zope.interface import implements
from zope.app.interfaces.index.field import IUIFieldCatalogIndex
from zope.app.interfaces.event import ISubscriber
from zope.app.interfaces.services.hub import IObjectHub
from zope.app.catalog.interfaces.index import ICatalogIndex
from zope.index.interfaces import ISimpleQuery

from zope.app.catalog.catalog import Catalog
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.component import getServiceManager
from zope.app.services.servicenames import HubIds
from BTrees.IIBTree import IISet

from zope.app.index.tests.test_objectretrievingprocessor import FakeObjectHub

import zope.app.services.hub as Hub

regEvt = Hub.ObjectRegisteredHubEvent
unregEvt = Hub.ObjectUnregisteredHubEvent
modEvt = Hub.ObjectModifiedHubEvent

class CFakeObjectHub(FakeObjectHub):
    def iterObjectRegistrations(self):
        def gen(things):
            for hubid, obj in things:
                loc = "/%s"%hubid
                yield loc,hubid,obj
        return gen(self.data.items())

class StubIndex(object):
    implements(ISimpleQuery, ISubscriber, ICatalogIndex, IUIFieldCatalogIndex)

    def __init__(self, field_name, interface=None):
	self._field_name = field_name
	self.interface = interface
	self._notifies = []

    def notify(self, event):
	self._notifies.append(event)

    def clear(self):
	self._notifies = []

    def _getterms(self):
        d = {}
        for e in self._notifies:
            ob = e.object
            term = getattr(e.object ,self._field_name, '')
            d.setdefault(term, []).append(e.hubid)
        return d

    def query(self, term, start=0, count=None):
        termdict = self._getterms()
        res = termdict.get(term, [])
        return IISet(res)

class stoopid(object):
    def __init__(self, **kw):
        self.__dict__ = kw

class Test(PlacelessSetup, unittest.TestCase):

    def test_catalog_add_del_indexes(self):
	catalog = Catalog()
	index = StubIndex('author', None)
	catalog['author'] = index
	self.assertEqual(catalog.keys(), ['author'])
	index = StubIndex('title', None)
	catalog['title'] = index
	indexes = catalog.keys()
	indexes.sort()
	self.assertEqual(indexes, ['author', 'title'])
	del catalog['author']
	self.assertEqual(catalog.keys(), ['title'])

    def test_catalog_notification_passing(self):
	catalog = Catalog()
	catalog['author'] = StubIndex('author', None)
	catalog['title'] = StubIndex('title', None)
        catalog.notify(regEvt(None, None, 'reg1', 1))
        catalog.notify(regEvt(None, None, 'reg2', 2))
        catalog.notify(regEvt(None, None, 'reg3', 3))
        catalog.notify(unregEvt(None, None, 'unreg4', 4))
        catalog.notify(unregEvt(None, None, 'unreg5', 5))
        catalog.notify(modEvt(None, None, 'mod6', 6))
        for index in catalog.values():
            checkNotifies = index._notifies
            self.assertEqual(len(checkNotifies), 6)
            notifLocs = [ x.location for x in checkNotifies ]
            self.assertEqual(notifLocs, ['reg1', 'reg2', 'reg3', 
                                         'unreg4', 'unreg5','mod6' ])
            self.assertEqual(notifLocs, ['reg1', 'reg2', 'reg3', 
                                         'unreg4', 'unreg5','mod6' ])
        catalog.clearIndexes()
        for index in catalog.values():
            checkNotifies = index._notifies
            self.assertEqual(len(checkNotifies), 0)

    def _frob_objecthub(self, ints=1, apes=1):
        hub = CFakeObjectHub()
        service_manager = getServiceManager(None)
        service_manager.defineService(HubIds, IObjectHub)
        service_manager.provideService(HubIds, hub)
        # whack some objects in our little objecthub
        if ints:
            for i in range(10):
                hub.register("<object %s>"%i)
        if apes:
            hub.register(stoopid(simiantype='monkey', name='bobo'))
            hub.register(stoopid(simiantype='monkey', name='bubbles'))
            hub.register(stoopid(simiantype='monkey', name='ginger'))
            hub.register(stoopid(simiantype='bonobo', name='ziczac'))
            hub.register(stoopid(simiantype='bonobo', name='bobo'))
            hub.register(stoopid(simiantype='punyhuman', name='anthony'))
            hub.register(stoopid(simiantype='punyhuman', name='andy'))
            hub.register(stoopid(simiantype='punyhuman', name='kev'))

    def test_updateindexes(self):
        "test a full refresh"
        self._frob_objecthub()
        catalog = Catalog()
	catalog['author'] = StubIndex('author', None)
	catalog['title'] = StubIndex('author', None)
        catalog.updateIndexes()
        for index in catalog.values():
            checkNotifies = index._notifies
            self.assertEqual(len(checkNotifies), 18)
            notifLocs = [ x.location for x in checkNotifies ]
            notifLocs.sort()
            expected = [ "/%s"%(i+1) for i in range(18) ]
            expected.sort()
            self.assertEqual(notifLocs, expected)

    def test_basicsearch(self):
        "test the simple searchresults interface"
        self._frob_objecthub(ints=0)
        catalog = Catalog()
	catalog['simiantype'] = StubIndex('simiantype', None)
	catalog['name'] = StubIndex('name', None)
        catalog.updateIndexes()
        res = catalog.searchResults(simiantype='monkey')
        names = [ x.name for x in res ]
        names.sort()
        self.assertEqual(len(names), 3)
        self.assertEqual(names, ['bobo', 'bubbles', 'ginger'])
        res = catalog.searchResults(name='bobo')
        names = [ x.simiantype for x in res ]
        names.sort()
        self.assertEqual(len(names), 2)
        self.assertEqual(names, ['bonobo', 'monkey'])
        res = catalog.searchResults(simiantype='punyhuman', name='anthony')
        self.assertEqual(len(res), 1)
        ob = iter(res).next()
        self.assertEqual((ob.name,ob.simiantype), ('anthony', 'punyhuman'))
        res = catalog.searchResults(simiantype='ape', name='bobo')
        self.assertEqual(len(res), 0)
        res = catalog.searchResults(simiantype='ape', name='mwumi')
        self.assertEqual(len(res), 0)
        self.assertRaises(ValueError, catalog.searchResults, 
                            simiantype='monkey', hat='beret')
        res = list(res)

def test_suite():
    return unittest.makeSuite(Test)


if __name__ == "__main__":
    unittest.main()
	


=== Zope3/src/zope/app/catalog/README.txt 1.1 => 1.2 ===
--- Zope3/src/zope/app/catalog/README.txt:1.1	Mon Mar  1 06:05:55 2004
+++ Zope3/src/zope/app/catalog/README.txt	Mon Mar  1 06:46:22 2004
@@ -37,7 +37,7 @@
 
 """
 from zope.app import zapi 
-from zope.app.interfaces.catalog.catalog import ICatalogQuery
+from zope.app.catalog.interfaces.catalog import ICatalogQuery
 
 class CatalogView: 
     def search(self): 


=== Zope3/src/zope/app/catalog/catalog.py 1.17 => 1.18 ===
--- Zope3/src/zope/app/catalog/catalog.py:1.17	Mon Mar  1 06:09:56 2004
+++ Zope3/src/zope/app/catalog/catalog.py	Mon Mar  1 06:46:22 2004
@@ -33,7 +33,7 @@
 import zope.app.interfaces.services.hub as IHub
 import zope.app.services.hub as Hub
 from zope.app.container.sample import SampleContainer
-from zope.app.interfaces.catalog.catalog import ICatalog
+from zope.app.catalog.interfaces.catalog import ICatalog
 
 class ResultSet:
     "Lazily accessed set of objects"


=== Zope3/src/zope/app/catalog/configure.zcml 1.5 => 1.6 ===
--- Zope3/src/zope/app/catalog/configure.zcml:1.5	Fri Aug 22 16:02:11 2003
+++ Zope3/src/zope/app/catalog/configure.zcml	Mon Mar  1 06:46:22 2004
@@ -1,17 +1,18 @@
-<configure xmlns="http://namespaces.zope.org/zope"
-               xmlns:browser="http://namespaces.zope.org/browser"
->
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    >
 
 <content class=".catalog.Catalog">
   <implements 
            interface="zope.app.interfaces.annotation.IAttributeAnnotatable"/>
   <factory id="zope.app.catalog" 
            permission="zope.ManageContent"/>
-  <require interface="zope.app.interfaces.catalog.catalog.ICatalogView"
+  <require interface="zope.app.catalog.interfaces.catalog.ICatalogView"
            permission="zope.View" />
-  <require interface="zope.app.interfaces.catalog.catalog.ICatalogQuery"
+  <require interface="zope.app.catalog.interfaces.catalog.ICatalogQuery"
            permission="zope.Public" />
-  <require interface="zope.app.interfaces.catalog.catalog.ICatalogEdit"
+  <require interface="zope.app.catalog.interfaces.catalog.ICatalogEdit"
            permission="zope.ManageContent" />
   <require interface="zope.app.interfaces.container.IContainer"
            permission="zope.ManageContent" />
@@ -20,11 +21,11 @@
 <content class=".catalog.CatalogUtility">
   <factory id="zope.app.catalogutility" 
            permission="zope.ManageContent"/>
-  <require interface="zope.app.interfaces.catalog.catalog.ICatalogView"
+  <require interface="zope.app.catalog.interfaces.catalog.ICatalogView"
            permission="zope.View"/>
-  <require interface="zope.app.interfaces.catalog.catalog.ICatalogQuery"
+  <require interface="zope.app.catalog.interfaces.catalog.ICatalogQuery"
            permission="zope.View"/>
-  <require interface="zope.app.interfaces.catalog.catalog.ICatalogEdit"
+  <require interface="zope.app.catalog.interfaces.catalog.ICatalogEdit"
            permission="zope.ManageContent"/>
   <require interface="zope.app.interfaces.container.IContainer"
            permission="zope.ManageContent"/>
@@ -34,5 +35,10 @@
   <require attributes="__iter__ __len__"
            permission="zope.Public"/>
 </content>
+
+
+  <!-- Include browser package -->
+
+  <include package=".browser" />
 
 </configure>




More information about the Zope3-Checkins mailing list