Skip to content

Commit

Permalink
Backported
Browse files Browse the repository at this point in the history
r26510 | srichter | 2004-07-13 17:49:44 -0400 (Tue, 13 Jul 2004) | 4 lines
r26511 | srichter | 2004-07-13 18:25:30 -0400 (Tue, 13 Jul 2004) | 2 lines
r26512 | srichter | 2004-07-13 18:27:31 -0400 (Tue, 13 Jul 2004) | 5 lines
r26513 | srichter | 2004-07-13 19:23:17 -0400 (Tue, 13 Jul 2004) | 2 lines
r26514 | srichter | 2004-07-13 19:25:04 -0400 (Tue, 13 Jul 2004) | 3 lines
r26515 | srichter | 2004-07-13 19:47:28 -0400 (Tue, 13 Jul 2004) | 2 lines
r26516 | srichter | 2004-07-13 19:48:45 -0400 (Tue, 13 Jul 2004) | 5 lines
r26518 | srichter | 2004-07-13 20:25:17 -0400 (Tue, 13 Jul 2004) | 3 lines
  • Loading branch information
strichter committed Aug 12, 2004
1 parent 77edf7c commit cef7ec5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 80 deletions.
15 changes: 0 additions & 15 deletions configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@
factory="zope.app.utility.vocabulary.UtilityVocabulary"
interface="zope.interface.interfaces.IInterface" />

<hook
module="zope.component"
name="getServices"
implementation="zope.app.component.hooks.getServices_hook" />

<hook
module="zope.component"
name="adapter_hook"
implementation="zope.app.component.hooks.adapter_hook" />

<hook
module="zope.component"
name="queryView"
implementation="zope.app.component.hooks.queryView" />

<interface interface="zope.interface.Interface" />

<adapter
Expand Down
11 changes: 11 additions & 0 deletions hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$Id$
"""
import zope.component
from zope.component import getService
from zope.component.interfaces import IServiceService
from zope.app.site.interfaces import ISite
Expand Down Expand Up @@ -86,11 +87,18 @@ def getServices_hook(context=None):
except ComponentLookupError:
return serviceManager

# Hook up a new implementation of looking up services.
zope.component.getServices.sethook(getServices_hook)

def adapter_hook(interface, object, name='', default=None):
try:
return siteinfo.adapter_hook(interface, object, name, default)
except ComponentLookupError:
return default

# Hook up a new implementation of looking up adapters.
zope.component.adapter_hook.sethook(adapter_hook)


def queryView(object, name, request, default=None,
providing=Interface, context=None):
Expand All @@ -101,3 +109,6 @@ def queryView(object, name, request, default=None,
locate(view, object, name)

return view

# Hook up a new implementation of looking up views.
zope.component.queryView.sethook(queryView)
117 changes: 52 additions & 65 deletions tests/test_servicedirective.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,53 +60,49 @@ def testServiceConfigNoType(self):
UndefinedService,
xmlconfig,
StringIO(template % (
"""
'''
<service
serviceType="Foo"
component="
zope.app.component.tests.service.fooService"
/>
"""
serviceType="Foo"
component="zope.app.component.tests.service.fooService"
/>
'''
)))

def testDuplicateServiceConfig(self):
self.assertRaises(
ConfigurationConflictError,
xmlconfig,
StringIO(template % (
"""
<serviceType id="Foo"
interface="
zope.app.component.tests.service.IFooService"
/>
'''
<serviceType
id="Foo"
interface="zope.app.component.tests.service.IFooService"
/>
<service
serviceType="Foo"
component="
zope.app.component.tests.service.fooService"
component="zope.app.component.tests.service.fooService"
/>
<service
serviceType="Foo"
component="
zope.app.component.tests.service.foo2"
component="zope.app.component.tests.service.foo2"
/>
"""
'''
)))

def testServiceConfig(self):
self.assertRaises(ComponentLookupError, getService, "Foo")

xmlconfig(StringIO(template % (
"""
<serviceType id="Foo"
interface="
zope.app.component.tests.service.IFooService"
/>
'''
<serviceType
id="Foo"
interface="zope.app.component.tests.service.IFooService"
/>
<service
serviceType="Foo"
component="
zope.app.component.tests.service.fooService"
/>
"""
serviceType="Foo"
component="zope.app.component.tests.service.fooService"
/>
'''
)))

service = getService("Foo")
Expand All @@ -118,17 +114,16 @@ def testServiceFactoryConfig(self):
self.assertRaises(ComponentLookupError, getService, "Foo")

xmlconfig(StringIO(template % (
"""
<serviceType id="Foo"
interface="
zope.app.component.tests.service.IFooService"
/>
'''
<serviceType
id="Foo"
interface="zope.app.component.tests.service.IFooService"
/>
<service
serviceType="Foo"
factory="
zope.app.component.tests.service.FooService"
/>
"""
serviceType="Foo"
factory="zope.app.component.tests.service.FooService"
/>
'''
)))

service = getService("Foo")
Expand All @@ -140,18 +135,17 @@ def testPublicProtectedServiceConfig(self):
self.assertRaises(ComponentLookupError, getService, "Foo")

xmlconfig(StringIO(template % (
"""
<serviceType id="Foo"
interface="
zope.app.component.tests.service.IFooService"
/>
'''
<serviceType
id="Foo"
interface="zope.app.component.tests.service.IFooService"
/>
<service
serviceType="Foo"
component="
zope.app.component.tests.service.fooService"
permission="zope.Public"
/>
"""
serviceType="Foo"
component="zope.app.component.tests.service.fooService"
permission="zope.Public"
/>
'''
)))

service = getService("Foo")
Expand All @@ -164,30 +158,23 @@ def testProtectedServiceConfig(self):
self.assertRaises(ComponentLookupError, getService, "Foo")

xmlconfig(StringIO(template % (
"""
<directives namespace="http://namespaces.zope.org/zope">
<directive name="permission"
attributes="id title description"
handler="
zope.app.security.metaconfigure.definePermission" />
</directives>
'''
<include package="zope.app.security" file="meta.zcml" />
<permission id="zope.TestPermission" title="Test permission" />
<serviceType id="Foo"
interface="
zope.app.component.tests.service.IFooService"
/>
<serviceType
id="Foo"
interface="zope.app.component.tests.service.IFooService"
/>
<service
serviceType="Foo"
component="
zope.app.component.tests.service.fooService"
permission="zope.TestPermission"
/>
"""
serviceType="Foo"
component="zope.app.component.tests.service.fooService"
permission="zope.TestPermission"
/>
'''
)))


# Need to "log someone in" to turn on checks
from zope.security.management import newInteraction, endInteraction
endInteraction()
Expand Down

0 comments on commit cef7ec5

Please sign in to comment.