[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ZopePublication/tests - testZopePublication.py:1.1.2.23
Jim Fulton
jim@zope.com
Sun, 28 Apr 2002 13:17:15 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ZopePublication/tests
In directory cvs.zope.org:/tmp/cvs-serv17050/lib/python/Zope/App/ZopePublication/tests
Modified Files:
Tag: Zope-3x-branch
testZopePublication.py
Log Message:
HOTYB: Merged SecurityProxy-branch into main branch.
All tests pass and folders can be listed and added through the web.
It is likely that most other things don't work and will need to be
fixed. The reason is that many accesses that should have been checked
before are now being checked and additional checks and thinking about
permissions and security settings are needed.
I'm in the process of drafting a paper for the wiki that describes the
changes in more detail.
=== Zope3/lib/python/Zope/App/ZopePublication/tests/testZopePublication.py 1.1.2.22 => 1.1.2.23 ===
from Zope.Publisher.DefaultPublication import TestPublication
from Zope.Publisher.IPublication import IPublication
-from Zope.ContextWrapper import Wrapper, getobject, getcontext
+from Zope.Proxy.ContextWrapper import getWrapperContext
+from Zope.ContextWrapper import Wrapper
import ZODB
from ZODB.MappingStorage import MappingStorage
from Zope.Publisher.Exceptions import Retry
-from Zope.App.Security.SecurityManager import setSecurityPolicy
-from Zope.App.Security import SimpleSecurityPolicies
+from Zope.Security import SimpleSecurityPolicies
+from Zope.Security.SecurityManagement import setSecurityPolicy
from Zope.App.ZopePublication.Traversers import DefaultTraverser
from Interface import Interface
from Interface.Verify import verifyClass
@@ -40,6 +41,8 @@
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
from StringIO import StringIO
@@ -94,10 +97,6 @@
connection.close()
- def tearDown(self):
- setSecurityPolicy(self.policy)
- CleanUp.tearDown(self)
-
def testInterfacesVerify(self):
for interface in instancesOfObjectImplements(self.klass):
verifyClass(interface, TestPublication)
@@ -121,7 +120,6 @@
klass = BrowserPublication
def testBaseTagNoBase(self):
- # XXX WRONG!
self._testBaseTags('/somepath/view;view/', '')
def testBaseTag1(self):
@@ -151,16 +149,14 @@
pub = BrowserPublication(self.db)
provideView(I1, 'view', IBrowserPublisher, DummyView)
- #provideView(I1, '', IBrowserPublisher, DummyView)
setDefaultViewName(I1, IBrowserPublisher, 'view')
provideView(None, '_traverse', IBrowserPublisher, DefaultTraverser)
ob = O1()
## the following is for running the tests standalone
- principalRegistry.defineDefaultPrincipal('tim',
- 'timbot',
- 'ai at its best')
+ principalRegistry.defineDefaultPrincipal(
+ 'tim', 'timbot', 'ai at its best')
principalRoleManager.assignRoleToPrincipal('Manager', 'tim')
@@ -174,10 +170,12 @@
get_transaction().commit()
connection.close()
+ defineChecker(app.__class__, NamesChecker(somepath='xxx'))
+
req = self._createRequest(url, pub)
response = req.getResponse()
- publish(req)
+ publish(req, handle_errors=0)
self.assertEqual(response.getBase(), expected)
@@ -187,6 +185,19 @@
request.setPublication(publication)
return request
+
+
+class SimpleObject:
+ def __init__(self, v):
+ self.v = v
+
+class I1(Interface):
+ pass
+
+class mydict(dict):
+ __implements__ = I1
+
+
class BrowserPublicationTests(BasePublicationTests):
klass = BrowserPublication
@@ -199,13 +210,6 @@
self.failUnless(isinstance(ob2, Wrapper))
def testAdaptedTraverseNameWrapping(self):
- from Interface import Interface
- class I1(Interface):
- pass
-
- class mydict(dict):
- " "
- __implements__ = I1
class Adapter:
" "
@@ -221,21 +225,17 @@
from Zope.ComponentArchitecture import provideView
provideView(I1, '_traverse', IBrowserPublisher, Adapter)
ob = mydict()
- ob['bruce'] = 'bruce'
- ob['bruce2'] = 'bruce2'
+ ob['bruce'] = SimpleObject('bruce')
+ ob['bruce2'] = SimpleObject('bruce2')
pub = self.klass(self.db)
ob2 = pub.traverseName(self._createRequest('/bruce',pub), ob, 'bruce')
self.failUnless(isinstance(ob2, Wrapper))
- unw = getobject(ob2)
- self.assertEqual(unw, 'bruce')
+ unw = removeAllProxies(ob2)
+ self.assertEqual(unw.v, 'bruce')
def testAdaptedTraverseDefaultWrapping(self):
- from Interface import Interface
- class I1(Interface):
- pass
-
- class mydict(dict):
- __implements__ = I1
+ """Test default content and make sure that it's wrapped.
+ """
class Adapter:
__implements__ = IBrowserPublisher
@@ -247,14 +247,14 @@
provideView(I1, '_traverse', IBrowserPublisher, Adapter)
ob = mydict()
- ob['bruce'] = 'bruce'
- ob['bruce2'] = 'bruce2'
+ ob['bruce'] = SimpleObject('bruce')
+ ob['bruce2'] = SimpleObject('bruce2')
pub = self.klass(self.db)
- ob2,x = pub.getDefaultTraversal(self._createRequest('/bruce',pub), ob)
+ ob2, x = pub.getDefaultTraversal(self._createRequest('/bruce',pub), ob)
self.assertEqual(x, 'dummy')
self.failUnless(isinstance(ob2, Wrapper))
- unw = getobject(ob2)
- self.assertEqual(unw, 'bruce')
+ unw = removeAllProxies(ob2)
+ self.assertEqual(unw.v, 'bruce')
def testTraverseSkinExtraction(self):
@@ -279,13 +279,13 @@
def testTraverseName(self):
pub = self.klass(self.db)
class C:
- x=1
+ x = SimpleObject(1)
ob = C()
r = self._createRequest('/x',pub)
provideView(None, '_traverse', IBrowserPublisher, DefaultTraverser)
ob2 = pub.traverseName(r, ob, 'x')
- self.assertEqual(getobject(ob2), 1)
- self.assertEqual(getcontext(ob2), ob)
+ self.assertEqual(removeAllProxies(ob2).v, 1)
+ self.assertEqual(getWrapperContext(ob2), ob)
def testTraverseNameView(self):
pub = self.klass(self.db)
@@ -299,19 +299,19 @@
r = self._createRequest('/spam;view',pub)
provideView(I, 'spam', IBrowserPublisher, V)
ob2 = pub.traverseName(r, ob, 'spam;view')
- self.assertEqual(getobject(ob2).__class__, V)
- self.assertEqual(getcontext(ob2), ob)
+ self.assertEqual(removeAllProxies(ob2).__class__, V)
+ self.assertEqual(getWrapperContext(ob2), ob)
def testTraverseNameServices(self):
pub = self.klass(self.db)
class C:
def getServiceManager(self):
- return 1
+ return SimpleObject(1)
ob = C()
r = self._createRequest('/Services;etc',pub)
ob2 = pub.traverseName(r, ob, 'Services;etc')
- self.assertEqual(getobject(ob2), 1)
- self.assertEqual(getcontext(ob2), ob)
+ self.assertEqual(removeAllProxies(ob2).v, 1)
+ self.assertEqual(getWrapperContext(ob2), ob)
def testTraverseNameApplicationControl(self):
from Zope.App.OFS.ApplicationControl.ApplicationControl \