[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/XMLRPC/tests - TestViews.py:1.1.4.1 __init__.py:1.1.4.1 testDirectives.py:1.1.4.1 testMethodPublisher.py:1.1.4.1 testXMLRPCRequest.py:1.1.2.1
Stephan Richter
srichter@cbu.edu
Wed, 27 Mar 2002 09:49:33 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/XMLRPC/tests
In directory cvs.zope.org:/tmp/cvs-serv16355/XMLRPC/tests
Added Files:
Tag: Zope-3x-branch
TestViews.py __init__.py testDirectives.py
testMethodPublisher.py testXMLRPCRequest.py
Log Message:
- Added XML-RPC support
- tweaked refactoring a little tp better support other HTTP sub-protocols
- Worked on security
=== Added File Zope3/lib/python/Zope/Publisher/XMLRPC/tests/TestViews.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
Revision information: $Id: TestViews.py,v 1.1.4.1 2002/03/27 14:49:32 srichter Exp $
"""
from Interface import Interface
from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
class IC(Interface): pass
class V1:
__implements__ = IXMLRPCPublisher
def __init__(self,context):
self._context = context
class VZMI(V1):
pass
class R1:
__implements__ = IXMLRPCPublisher
r1 = R1()
class RZMI(R1):
pass
rZMI = RZMI()
=== Added File Zope3/lib/python/Zope/Publisher/XMLRPC/tests/__init__.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.
=== Added File Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testDirectives.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
import unittest
from Zope.Configuration.xmlconfig import xmlconfig
from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
from Zope.Publisher.XMLRPC.tests.TestViews import IC, V1, VZMI, R1, RZMI
from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
from Zope.ComponentArchitecture import getView
from cStringIO import StringIO
template = """<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:xmlrpc='http://namespaces.zope.org/xmlrpc'>
%s
</zopeConfigure>"""
class Ob:
__implements__ = IC
class Test(CleanUp, unittest.TestCase):
def testView(self):
ob = Ob()
self.assertEqual(getView(ob, 'test', IXMLRPCPublisher, None), None)
xmlconfig(StringIO(template % (
'''
<directive name="view"
attributes="component, name, for, layer"
handler="Zope.Publisher.XMLRPC.metaConfigure.view"
namespace="http://namespaces.zope.org/xmlrpc" />
<xmlrpc:view name="test"
factory="Zope.Publisher.XMLRPC.tests.TestViews.V1"
for="Zope.Publisher.XMLRPC.tests.TestViews.IC" />
'''
)))
self.assertEqual(getView(ob, 'test', IXMLRPCPublisher, None
).__class__, V1)
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(Test)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testMethodPublisher.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.
import unittest, sys
from Zope.Publisher.XMLRPC.MethodPublisher import MethodPublisher
from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
from Interface.Verify import verifyClass
from Interface.Implements import instancesOfObjectImplements
class Presentation(MethodPublisher):
index = 'index'
action = 'action'
foo = 'foo'
class TestMethodPublisher(unittest.TestCase):
def setUp(self):
self.pres = Presentation()
def testImplementsIXMLRPCPublisher(self):
self.failUnless(IXMLRPCPublisher.isImplementedBy(self.pres))
def testInterfacesVerify(self):
for interface in instancesOfObjectImplements(Presentation):
verifyClass(interface, Presentation)
def testXMLRPCTraverseIndex(self):
self.assertEquals(self.pres.publishTraverse(None, 'index'),
'index')
def testXMLRPCTraverseAction(self):
self.assertEquals(self.pres.publishTraverse(None, 'action'),
'action')
def testXMLRPCTraverseNotFound(self):
self.failUnlessRaises(AttributeError, self.pres.publishTraverse,
None, 'bar')
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(TestMethodPublisher)
if __name__ == '__main__':
unittest.TextTestRunner().run(test_suite())
=== Added File Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testXMLRPCRequest.py ===
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.
import unittest
from Zope.Publisher.XMLRPC.XMLRPCRequest import XMLRPCRequest
from Zope.Publisher.XMLRPC.XMLRPCResponse import XMLRPCResponse
from Zope.Publisher.Publish import publish
from Zope.Publisher.DefaultPublication import DefaultPublication
from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
from cStringIO import StringIO
from Zope.Publisher.HTTP.tests.testHTTP import HTTPTests
class Publication(DefaultPublication):
require_docstrings = 0
def getDefaultTraversal(self, request, ob):
if hasattr(ob, 'browserDefault'):
return ob.browserDefault(request)
return ob, ()
xmlrpc_call = '''<?xml version='1.0'?>
<methodCall>
<methodName>action</methodName>
<params>
<param>
<value><int>1</int></value>
</param>
</params>
</methodCall>
'''
class XMLRPCTests(unittest.TestCase):
"""The only thing different to HTTP is the input processing; so there
is no need to redo all the HTTP tests again.
"""
_testEnv = {
'PATH_INFO': '/folder/item2/view/',
'QUERY_STRING': '',
'SERVER_URL': 'http://foobar.com',
'HTTP_HOST': 'foobar.com',
'CONTENT_LENGTH': '0',
'REQUEST_METHOD': 'POST',
'HTTP_AUTHORIZATION': 'Should be in accessible',
'GATEWAY_INTERFACE': 'TestFooInterface/1.0',
'HTTP_OFF_THE_WALL': "Spam 'n eggs",
}
def setUp(self):
class AppRoot:
" "
class Folder:
" "
class Item:
def __call__(self, a, b):
return "%s, %s" % (`a`, `b`)
def doit(self, a, b):
return 'do something %s %s' % (a, b)
class View:
def action(self, a):
return "Parameter[type: %s; value: %s" %(
type(a).__name__, `a`)
class Item2:
view = View()
self.app = AppRoot()
self.app.folder = Folder()
self.app.folder.item = Item()
self.app.folder.item2 = Item2()
def _createRequest(self, extra_env={}, body="", outstream=None):
env = self._testEnv.copy()
env.update(extra_env)
if len(body):
env['CONTENT_LENGTH'] = str(len(body))
publication = Publication(self.app)
if outstream is None:
outstream = StringIO()
instream = StringIO(body)
request = XMLRPCRequest(instream, outstream, env)
request.setPublication(publication)
return request
def testIViewRequest(self):
''' test the IView request'''
r = self._createRequest()
self.failUnless( r.getViewType() is IXMLRPCPublisher)
def testProcessInput(self):
req = self._createRequest({}, xmlrpc_call)
req.processInputs()
self.failUnlessEqual(req._args, (1,))
self.failUnlessEqual(tuple(req._path_suffix), ('action',))
def testTraversal(self):
req = self._createRequest({}, xmlrpc_call)
req.processInputs()
action = req.traverse(self.app)
self.failUnlessEqual(action(*req._args),
"Parameter[type: int; value: 1")
def test_suite():
loader = unittest.TestLoader()
return loader.loadTestsFromTestCase(XMLRPCTests)
if __name__=='__main__':
unittest.TextTestRunner().run( test_suite() )