[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/SOAP/tests - TestViews.py:1.1.2.1 __init__.py:1.1.2.1 testDirectives.py:1.1.2.1 testMethodPublisher.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Wed, 13 Mar 2002 05:57:36 -0500


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

Added Files:
      Tag: srichter-OFS_Formulator-branch
	TestViews.py __init__.py testDirectives.py 
	testMethodPublisher.py 
Log Message:
- Added some more tests. Won;t do more, since Publisher is being redesigned
  later this week. I will wait until then.

- Added preliminary SOAP support, so we can test Mozilla's SOAP 
  capabilities. Unfortunately, soaplib is very old; I will look into using 
  SOAPpy instead. It seems fairly complete.


=== Added File Zope3/lib/python/Zope/Publisher/SOAP/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.2.1 2002/03/13 10:57:35 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/SOAP/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/SOAP/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, sys
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, getResource
from Zope.ComponentArchitecture import getDefaultViewName
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 testDefaultView(self):

        ob = Ob()
        self.assertEqual(getView(ob, 'test', IXMLRPCPublisher, None), None)

        xmlconfig(StringIO(template % (
            """
            <directive name="defaultView"
                       attributes="component, name, for, layer"
               handler="Zope.Publisher.XMLRPC.metaConfigure.defaultView"
               namespace="http://namespaces.zope.org/xmlrpc" />
            <xmlrpc:defaultView 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)
        self.assertEqual(getDefaultViewName(ob, IXMLRPCPublisher
                                 ), 'test')
                                 
              
    
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/SOAP/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 import verify, 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):
            verify(interface, Presentation)


    def testXMLRPCDefault(self):
        self.assertEquals(self.pres.xmlrpc_default(None),
            (self.pres, ('info',)))


    def testXMLRPCTraverseIndex(self):
        self.assertEquals(self.pres.xmlrpc_traverse(None, 'index'),
            'index')


    def testXMLRPCTraverseAction(self):
        self.assertEquals(self.pres.xmlrpc_traverse(None, 'action'),
            'action')


    def testXMLRPCTraverseNotFound(self):
        self.failUnlessRaises(AttributeError, self.pres.xmlrpc_traverse, 
            None, 'bar')



def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(TestMethodPublisher)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())