/usr/share/pyshared/zope/app/publication/tests/test_xmlrpcpublication.py is in python-zope.app.publication 3.13.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation 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
"""
import unittest
from zope.app.publication.tests.test_zopepublication import \
BasePublicationTests
from zope.app.publication.traversers import TestTraverser
from zope.app.publication.traversers import SimpleComponentTraverser
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.publisher.interfaces.xmlrpc import IXMLRPCView
from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
from zope.publisher.interfaces.xmlrpc import IXMLRPCPublisher
from zope.publisher.xmlrpc import TestRequest
from zope.app.publication.tests import support
from zope import component
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.klass(self.db)
class C(object):
x = SimpleObject(1)
ob = C()
r = self._createRequest('/x', pub)
component.provideAdapter(TestTraverser, (None, IXMLRPCRequest),
IXMLRPCPublisher)
ob2 = pub.traverseName(r, ob, 'x')
self.assertEqual(removeAllProxies(ob2).v, 1)
def testDenyDirectMethodAccess(self):
pub = self.klass(self.db)
class I(Interface):
pass
class C(object):
implements(I)
def foo(self):
return 'bar'
class V(object):
def __init__(self, context, request):
pass
implements(IXMLRPCView)
ob = C()
r = self._createRequest('/foo', pub)
component.provideAdapter(V, (I, IXMLRPCView), Interface,
name='view')
support.setDefaultViewName(I, 'view', type=IXMLRPCView)
self.assertRaises(NotFound, pub.traverseName, r, ob, 'foo')
def testTraverseNameView(self):
pub = self.klass(self.db)
class I(Interface):
pass
class C(object):
implements(I)
ob = C()
class V(object):
def __init__(self, context, request):
pass
implements(IXMLRPCView)
# Register the simple traverser so we can traverse without @@
component.provideAdapter(SimpleComponentTraverser,
(Interface, IXMLRPCRequest),
IXMLRPCPublisher)
r = self._createRequest('/@@spam', pub)
component.provideAdapter(V, (I, IXMLRPCRequest), Interface,
name='spam')
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.klass(self.db)
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()
|