Skip to content

Commit

Permalink
Remove the dependency of the publication tests on ZODB (Now we only i…
Browse files Browse the repository at this point in the history
…mport ZODB.POSException). Move and add some tests to zope.app.zodb.
  • Loading branch information
Brian Sutherland committed Apr 8, 2007
1 parent f9358c9 commit 5b9b0d3
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 80 deletions.
37 changes: 10 additions & 27 deletions tests/test_browserpublication.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _testBaseTags(self, url, expected):
# so that the classes can be pickled.
import transaction

pub = BrowserPublication(self.db)
pub = self.publication

ztapi.browserView(I1, 'view', DummyView)
ztapi.setDefaultViewName(I1, 'view')
Expand All @@ -131,13 +131,9 @@ def _testBaseTags(self, url, expected):

# now place our object inside the application

connection = self.db.open()
app = connection.root()['Application']
app.somepath = ob
transaction.commit()
connection.close()
self.app.somepath = ob

defineChecker(app.__class__, NamesChecker(somepath='xxx'))
defineChecker(self.app.__class__, NamesChecker(somepath='xxx'))

req = self._createRequest(url, pub)
response = req.response
Expand Down Expand Up @@ -174,7 +170,7 @@ def publishTraverse(self, request, name):
ob = mydict()
ob['bruce'] = SimpleObject('bruce')
ob['bruce2'] = SimpleObject('bruce2')
pub = self.klass(self.db)
pub = self.publication
ob2 = pub.traverseName(self._createRequest('/bruce', pub), ob, 'bruce')
self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')
Expand All @@ -193,14 +189,14 @@ def browserDefault(self, request):
ob = mydict()
ob['bruce'] = SimpleObject('bruce')
ob['bruce2'] = SimpleObject('bruce2')
pub = self.klass(self.db)
pub = self.publication
ob2, x = pub.getDefaultTraversal(self._createRequest('/bruce',pub), ob)
self.assertEqual(x, 'dummy')
self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')

def testTraverseName(self):
pub = self.klass(self.db)
pub = self.publication
class C(object):
x = SimpleObject(1)
ob = C()
Expand All @@ -211,7 +207,7 @@ class C(object):
self.assertEqual(removeSecurityProxy(ob2).v, 1)

def testTraverseNameView(self):
pub = self.klass(self.db)
pub = self.publication
class I(Interface): pass
class C(object):
implements(I)
Expand All @@ -224,7 +220,7 @@ def __init__(self, context, request): pass
self.assertEqual(ob2.__class__, V)

def testTraverseNameSiteManager(self):
pub = self.klass(self.db)
pub = self.publication
class C(object):
def getSiteManager(self):
return SimpleObject(1)
Expand All @@ -234,21 +230,8 @@ def getSiteManager(self):
self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
self.assertEqual(removeSecurityProxy(ob2).v, 1)

def testTraverseNameApplicationControl(self):
from zope.app.applicationcontrol.applicationcontrol \
import applicationController, applicationControllerRoot
pub = self.klass(self.db)
r = self._createRequest('/++etc++process',pub)
ac = pub.traverseName(r,
applicationControllerRoot,
'++etc++process')
self.assertEqual(ac, applicationController)
r = self._createRequest('/++etc++process',pub)
app = r.publication.getApplication(r)
self.assertEqual(app, applicationControllerRoot)

def testHEADFuxup(self):
pub = self.klass(self.db)
pub = self.publication

class User(object):
id = 'bob'
Expand Down Expand Up @@ -303,7 +286,7 @@ def setUp(self):
factoryRegistry.register('HEAD', '*', 'BROWSER', 10, BrowserFactory())

def testGetBackSamePublication(self):
factory = HTTPPublicationRequestFactory(db=self.db)
factory = HTTPPublicationRequestFactory(db=self.resource_factory)
args = (StringIO(''), {})
self.assert_(id(factory(*args).publication) ==
id(factory(*args).publication))
Expand Down
133 changes: 133 additions & 0 deletions tests/test_xmlrpcpublication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""XML-RPC Publication Tests
$Id$
"""
import unittest

from zope.app.publication.tests.test_zopepublication import \
BasePublicationTests
from zope.app.publication.traversers import TestTraverser
from zope.app.publication.xmlrpc import XMLRPCPublication
from zope.interface import Interface, implements
from zope.proxy import removeAllProxies
from zope.publisher.interfaces import NotFound
from zope.app.publisher.interfaces.xmlrpc import IXMLRPCPresentation
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.xmlrpc import TestRequest
from zope.app.testing import ztapi


class SimpleObject(object):
def __init__(self, v):
self.v = v


class XMLRPCPublicationTests(BasePublicationTests):

klass = XMLRPCPublication

def _createRequest(self, path, publication, **kw):
request = TestRequest(PATH_INFO=path, **kw)
request.setPublication(publication)
return request

def testTraverseName(self):
pub = self.publication
class C(object):
x = SimpleObject(1)
ob = C()
r = self._createRequest('/x', pub)
ztapi.provideView(None, IXMLRPCRequest, IXMLRPCPublisher,
'', TestTraverser)
ob2 = pub.traverseName(r, ob, 'x')
self.assertEqual(removeAllProxies(ob2).v, 1)

def testDenyDirectMethodAccess(self):
pub = self.publication
class I(Interface):
pass

class C(object):
implements(I)

def foo(self):
return 'bar'

class V(object):
def __init__(self, context, request):
pass
implements(IXMLRPCPresentation)

ob = C()
r = self._createRequest('/foo', pub)

ztapi.provideView(I, IXMLRPCPresentation, Interface, 'view', V)
ztapi.setDefaultViewName(I, 'view', type=IXMLRPCPresentation)
self.assertRaises(NotFound, pub.traverseName, r, ob, 'foo')


def testTraverseNameView(self):
pub = self.publication

class I(Interface):
pass

class C(object):
implements(I)

ob = C()

class V(object):
def __init__(self, context, request):
pass
implements(IXMLRPCPresentation)


# Register the simple traverser so we can traverse without @@
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
from zope.app.publication.traversers import SimpleComponentTraverser
ztapi.provideView(Interface, IXMLRPCRequest, IXMLRPCPublisher, '',
SimpleComponentTraverser)

r = self._createRequest('/@@spam', pub)
ztapi.provideView(I, IXMLRPCRequest, Interface, 'spam', V)
ob2 = pub.traverseName(r, ob, '@@spam')
self.assertEqual(removeAllProxies(ob2).__class__, V)

ob2 = pub.traverseName(r, ob, 'spam')
self.assertEqual(removeAllProxies(ob2).__class__, V)


def testTraverseNameSiteManager(self):
pub = self.publication
class C(object):
def getSiteManager(self):
return SimpleObject(1)
ob = C()
r = self._createRequest('/++etc++site',pub)
ob2 = pub.traverseName(r, ob, '++etc++site')
self.assertEqual(removeAllProxies(ob2).v, 1)


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(XMLRPCPublicationTests),
))

if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 5b9b0d3

Please sign in to comment.