Log message for revision 65809: Move test for the siteManagerAdapter out to Five.component (now a doctest in component.txt). Also clean up the test fixtures in test_localsite, based on the fact that ObjectManager is an IPossibleSite now.
Changed: A Products.Five/branches/philikon-local-components/component/component.txt U Products.Five/branches/philikon-local-components/component/tests.py U Products.Five/branches/philikon-local-components/site/tests/test_localsite.py -=- Added: Products.Five/branches/philikon-local-components/component/component.txt =================================================================== --- Products.Five/branches/philikon-local-components/component/component.txt 2006-03-05 00:19:55 UTC (rev 65808) +++ Products.Five/branches/philikon-local-components/component/component.txt 2006-03-05 00:22:38 UTC (rev 65809) @@ -0,0 +1,72 @@ +Local component look-up +======================= + +``IComponentLookup`` adapter +----------------------------- + +In order to do context-based component look-up, the Component +Architecture adapts the context to ``IComponentLookup``. Zope 3's +default adapter uses the ``ILocation`` API to walk up the object tree +and find a site that way. Five provides its own adapter that also +supports acquisitional parents. + +First, we register Five's adapter: + + >>> import zope.component + >>> from Products.Five.component import siteManagerAdapter + >>> zope.component.provideAdapter(siteManagerAdapter) + +Now we create a site object with a stub component registry: + + >>> from OFS.ObjectManager import ObjectManager + >>> from zope.interface import alsoProvides + >>> from zope.app.component.interfaces import ISite + + >>> components = object() + >>> site = ObjectManager() + >>> site.setSiteManager(components) + >>> alsoProvides(site, ISite) + +When we adapt the site itself, we obviously get its component +registry: + + >>> from zope.component.interfaces import IComponentLookup + >>> IComponentLookup(site) is components + True + +In case the adapted object has an acquisition context, acquisition +is used to retrieve the closest site: + + >>> ob = ObjectManager() + >>> ob2 = ObjectManager() + >>> ob = ob.__of__(site) + >>> ob2 = ob2.__of__(ob) + >>> IComponentLookup(ob2) is components + True + +The adapter also works using the ``ILocation`` API by inspecting the +``__parent__`` object instead of using the acquisition parent: + + >>> from zope.app.location import Location + >>> ob = Location() + >>> ob2 = Location() + >>> ob.__parent__ = site + >>> ob2.__parent__ = ob + >>> IComponentLookup(ob2) is components + True + +If it is unable to find a site and therefore a component registry, the +global component registry is returned: + + >>> from zope.component import getGlobalSiteManager + >>> orphan = ObjectManager() + >>> IComponentLookup(orphan) is getGlobalSiteManager() + True + + +Clean up: +--------- + +#XXX somehow this makes the zpt.txt tests fail +# >>> from zope.component.testing import tearDown +# >>> tearDown() Property changes on: Products.Five/branches/philikon-local-components/component/component.txt ___________________________________________________________________ Name: svn:eol-style + native Modified: Products.Five/branches/philikon-local-components/component/tests.py =================================================================== --- Products.Five/branches/philikon-local-components/component/tests.py 2006-03-05 00:19:55 UTC (rev 65808) +++ Products.Five/branches/philikon-local-components/component/tests.py 2006-03-05 00:22:38 UTC (rev 65809) @@ -22,6 +22,7 @@ def test_suite(): return unittest.TestSuite([ + DocFileSuite('component.txt', package="Products.Five.component") DocFileSuite('zpt.txt', package="Products.Five.component") ]) Modified: Products.Five/branches/philikon-local-components/site/tests/test_localsite.py =================================================================== --- Products.Five/branches/philikon-local-components/site/tests/test_localsite.py 2006-03-05 00:19:55 UTC (rev 65808) +++ Products.Five/branches/philikon-local-components/site/tests/test_localsite.py 2006-03-05 00:22:38 UTC (rev 65809) @@ -23,10 +23,9 @@ import unittest from Testing import ZopeTestCase -from zope.interface import implements -from zope.interface import directlyProvides, directlyProvidedBy +import zope.interface from zope.component import getGlobalSiteManager, getSiteManager -from zope.component.exceptions import ComponentLookupError +from zope.component.interfaces import ComponentLookupError from zope.component.interfaces import ISiteManager from zope.app.component.hooks import setSite, getSite, setHooks from zope.app.component.interfaces import IPossibleSite, ISite @@ -40,33 +39,25 @@ from Products.Five import zcml class SiteManager(Implicit): - implements(ISiteManager) + zope.interface.implements(ISiteManager) class Folder(ObjectManager): - implements(IPossibleSite) - sm = None - - def getId(self): - return self.id - - def getSiteManager(self, default=None): - return self.sm - def setSiteManager(self, sm): - self.sm = sm - directlyProvides(self, ISite, directlyProvidedBy(self)) + super(Folder, self).setSiteManager(sm) + zope.interface.alsoProvides(self, ISite) class Package(Implicit): pass class Root(Folder): - implements(IContainmentRoot, ISite) + zope.interface.implements(IContainmentRoot, ISite) + def getSiteManager(self): return getGlobalSiteManager() class SiteManagerStub(object): - implements(ISiteManager) + zope.interface.implements(ISiteManager) class SiteManagerTest(PlacelessSetup, unittest.TestCase): @@ -165,29 +156,6 @@ # # Check that getGlobalSiteManager() is not proxied # self.assert_(getNextSiteManager(sm) is getGlobalSiteManager()) - def test_siteManagerAdapter(self): - from Products.Five.site.localsite import siteManagerAdapter - - # If it is a site, return the service service. - sm = SiteManagerStub() - site = Folder() - site.setSiteManager(sm) - self.assertEqual(siteManagerAdapter(site), sm) - - # If it has an acquisition context, "acquire" the site - # and return the service service - ob = Folder() - ob = ob.__of__(site) - self.assertEqual(siteManagerAdapter(ob), sm) - ob2 = Folder() - ob2 = ob2.__of__(ob) - self.assertEqual(siteManagerAdapter(ob2), sm) - - # If it does we are unable to find a service service, raise - # ComponentLookupError - orphan = Folder() - self.failUnless(siteManagerAdapter(orphan) is getGlobalSiteManager()) - def test_setThreadSite_clearThreadSite(self): from zope.app.component.site import threadSiteSubscriber, clearSite from zope.app.publication.zopepublication import BeforeTraverseEvent _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins