[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/XMLRPC/tests - TestViews.py:1.2 __init__.py:1.2 testDirectives.py:1.2 testMethodPublisher.py:1.2 testXMLRPCRequest.py:1.2

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:30:04 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/XMLRPC/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Publisher/XMLRPC/tests

Added Files:
	TestViews.py __init__.py testDirectives.py 
	testMethodPublisher.py testXMLRPCRequest.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.

=== Zope3/lib/python/Zope/Publisher/XMLRPC/tests/TestViews.py 1.1 => 1.2 ===
+#
+# 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.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$
+"""
+
+from Interface import Interface
+from Zope.Publisher.XMLRPC.IXMLRPCPublisher import IXMLRPCPublisher
+
+class IC(Interface): pass
+
+class V1:
+    __implements__ = IXMLRPCPublisher
+
+    def __init__(self, context, request): 
+        self.context = context
+        self.request = request
+
+class VZMI(V1):
+    pass
+
+class R1:
+    def __init__(self, request): 
+        self.request = request
+    
+    __implements__ = IXMLRPCPublisher
+
+class RZMI(R1):
+    pass


=== Zope3/lib/python/Zope/Publisher/XMLRPC/tests/__init__.py 1.1 => 1.2 ===
+#
+# 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.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.
+# 
+##############################################################################


=== Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testDirectives.py 1.1 => 1.2 ===
+#
+# 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.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.ComponentArchitecture.tests.PlacelessSetup import PlacelessSetup
+from Zope.ComponentArchitecture import queryView
+from cStringIO import StringIO
+
+from Zope.ComponentArchitecture.tests.Request import Request
+
+template = """<zopeConfigure
+   xmlns='http://namespaces.zope.org/zope'
+   xmlns:xmlrpc='http://namespaces.zope.org/xmlrpc'>
+   %s
+   </zopeConfigure>"""
+
+class Ob:
+    __implements__ = IC
+
+class Test(PlacelessSetup, unittest.TestCase):
+
+    def testView(self):
+
+        ob = Ob()
+        self.assertEqual(queryView(ob, 'test', Request(IXMLRPCPublisher)),
+                         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(queryView(ob, 'test', Request(IXMLRPCPublisher), None
+                                 ).__class__, V1)
+
+
+    
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase(Test)
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testMethodPublisher.py 1.1 => 1.2 ===
+#
+# 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.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, 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())


=== Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testXMLRPCRequest.py 1.1 => 1.2 ===
+#
+# 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.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.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 testIPresentationRequest(self):
+        ''' test the IView request'''
+    
+        r = self._createRequest()
+        self.failUnless( r.getPresentationType() 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() )
+
+
+