[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication/tests - testDefaultTraverser.py:1.1.2.12 testZopePublication.py:1.1.2.24
Gary Poster
garyposter@earthlink.net
Mon, 29 Apr 2002 19:20:41 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication/tests
In directory cvs.zope.org:/tmp/cvs-serv1556/App/ZopePublication/tests
Modified Files:
Tag: Zope-3x-branch
testDefaultTraverser.py testZopePublication.py
Log Message:
ComponentArchitecture reorganization; addition of for_container; addition of IWriteContainer.isAddable.
good news: all tests pass; bad news: after the new security system, my changes have some problems. I had to punt on the default contents view of all folders for instance--hasServiceManager is causing a problem for some reason I couldn't divine, even with Shane's Checker tool. I commented out the offending code on the contents.pt just to keep things up.
I tagged before committing: gary_CA-reorganization
changes more in depth (as I understand it, all or most approved :-) ):
(in ComponentArchitecture:)
* changing implementation names to Global* (i.e., AdapterService becomes
GlobalAdapterService) and giving each its own file (many are clumped together
in hooks.py)
* removing hooks.py in ComponentArchitecture, putting all functions in appropriate module above (i.e. getAdapter will be in the adapter module)
* largely removing indirection (_hook) except for getService and
getNextService
* changing IServiceService.py to IServiceManager
* changing Service.py to GlobalServiceManager.py (and class name too)
* removing "provide*" functions (i.e., provideAdapter, provideUtility, etc.)
and "defineService" from the __init__.py imports
* change all global services to classes with appropriate methods as per
interfaces
* update all tests
* remove all of the "provide*" functions from the interfaces
* renamed IComponentArchitecture to IPlacefulComponentArchitecture (hereafter IPCA), after long discussion with SteveA
* list Resources as one of core CA services in IPlacefulComponentArchitecture
* build actual IPCA interface, not just import of service interfaces (because we want IPCA to be placeful, but the service interfaces do not need to be)
* place functions implementing ICA actually in __init__
* explicitly setting up services in zcml
* created Global service interfaces, and placed the "provides" and "set" and "define" functions there: however, to keep the main interfaces clean and clear, I placed these global interfaces in the same file as the global implementations, hoping to clarify that these are not reusable interfaces but descriptive, one-time interfaces
* built PlacefulSetup in Zope.ComponentArchitecture.tests for more specific CleanUp (a subclass). PlacefulSetup is in the tests folder of the local ServiceManager. AddableSetup also is available, in the AddableService tests.
(elsewhere in Zope3)
* built for_container in addables
* built isAddable for containers (after discussion with Jim, we decided an addable "contains" attribute in the zcml might not be the way to go. I chose the isAddable approach for a number of reasons)
* addableservice does some more checks in getting the addable list, pertinent to the above and to whether it can find the appropriate factories
* a few more tests: a start of one in the local event service, and some more here and there
I'm sorry to add to the confusion of the big security changes, but I needed to either trash these changes or commit them: I'm a bit out of time for the moment. If all else fails, again, I did tag the previous version.
=== Zope3/lib/python/Zope/App/ZopePublication/tests/testDefaultTraverser.py 1.1.2.11 => 1.1.2.12 ===
import unittest, sys
from Zope.ComponentArchitecture.tests.Request import Request
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-from Zope.ComponentArchitecture import provideView
+from Zope.ComponentArchitecture import getService
from Zope.App.ZopePublication.Traversers import DefaultTraverser
from Interface import Interface
from Zope.Exceptions import NotFoundError
-
+from Zope.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
class I(Interface): pass
@@ -54,7 +53,7 @@
-class Test(CleanUp, unittest.TestCase):
+class Test(PlacelessSetup, unittest.TestCase):
def testAttr(self):
""" test container traver """
@@ -78,7 +77,7 @@
req = Request( I, '')
T = DefaultTraverser(c)
- provideView(None , 'foo', I, View)
+ getService(None,"Views").provideView(None , 'foo', I, View)
self.failUnless(T.publishTraverse(req,'foo;view').__class__ is View )
self.failUnless(T.publishTraverse(req,'foo') is foo)
=== Zope3/lib/python/Zope/App/ZopePublication/tests/testZopePublication.py 1.1.2.23 => 1.1.2.24 ===
from Interface.Implements import instancesOfObjectImplements
-from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
-from Zope.ComponentArchitecture import provideView, setDefaultViewName
+from Zope.ComponentArchitecture.tests.PlacelessSetup\
+ import PlacelessSetup
+from Zope.ComponentArchitecture import getService, getServiceManager
from Zope.App.Security.PrincipalRegistry import principalRegistry
from Zope.App.Security.PrincipalRoleManager import principalRoleManager
-from Zope.ComponentArchitecture import provideView
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from Zope.Security.Checker import defineChecker, NamesChecker
@@ -73,10 +73,11 @@
return self._context
-class BasePublicationTests(CleanUp, unittest.TestCase):
+class BasePublicationTests(PlacelessSetup, unittest.TestCase):
klass = ZopePublication
def setUp(self):
+ PlacelessSetup.setUp(self)
self.policy = setSecurityPolicy(
SimpleSecurityPolicies.PermissiveSecurityPolicy()
)
@@ -89,13 +90,17 @@
if app is None:
from Zope.App.OFS.Folder.RootFolder import RootFolder
from Transaction import get_transaction
-
+
app = RootFolder()
root[ZopePublication.root_name] = app
get_transaction().commit()
-
+
connection.close()
+
+ def tearDown(self):
+ setSecurityPolicy(self.policy) # XXX still needed?
+ PlacelessSetup.tearDown(self)
def testInterfacesVerify(self):
for interface in instancesOfObjectImplements(self.klass):
@@ -148,9 +153,12 @@
pub = BrowserPublication(self.db)
- provideView(I1, 'view', IBrowserPublisher, DummyView)
- setDefaultViewName(I1, IBrowserPublisher, 'view')
- provideView(None, '_traverse', IBrowserPublisher, DefaultTraverser)
+ getService(None,'Views').provideView(I1, 'view',
+ IBrowserPublisher, DummyView)
+ getService(None,'Views').setDefaultViewName(I1,
+ IBrowserPublisher, 'view')
+ getService(None, 'Views').provideView(None,
+ '_traverse', IBrowserPublisher, DefaultTraverser)
ob = O1()
@@ -222,7 +230,7 @@
self.counter+=1
return self.context[name]
- from Zope.ComponentArchitecture import provideView
+ provideView=getService(None, "Views").provideView
provideView(I1, '_traverse', IBrowserPublisher, Adapter)
ob = mydict()
ob['bruce'] = SimpleObject('bruce')
@@ -245,6 +253,7 @@
def browserDefault(self, request):
return (self.context['bruce'], 'dummy')
+ provideView=getService(None, "Views").provideView
provideView(I1, '_traverse', IBrowserPublisher, Adapter)
ob = mydict()
ob['bruce'] = SimpleObject('bruce')
@@ -264,6 +273,7 @@
pub = self.klass(self.db)
ob = C()
+ provideView=getService(None, "Views").provideView
provideView(I1, 'edit', IBrowserPublisher, BobView)
r = self._createRequest('/edit;skin=zmi;view',pub)
@@ -282,6 +292,7 @@
x = SimpleObject(1)
ob = C()
r = self._createRequest('/x',pub)
+ provideView=getService(None, "Views").provideView
provideView(None, '_traverse', IBrowserPublisher, DefaultTraverser)
ob2 = pub.traverseName(r, ob, 'x')
self.assertEqual(removeAllProxies(ob2).v, 1)
@@ -297,6 +308,7 @@
def __init__(self, context): pass
__implements__ = IBrowserPublisher
r = self._createRequest('/spam;view',pub)
+ provideView=getService(None, "Views").provideView
provideView(I, 'spam', IBrowserPublisher, V)
ob2 = pub.traverseName(r, ob, 'spam;view')
self.assertEqual(removeAllProxies(ob2).__class__, V)