[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/XMLRPC/tests - TestViews.py:1.1.2.1 __init__.py:1.1.2.1 testAttributePublisher.py:1.1.2.1 testBrowserLanguages.py:1.1.2.1 testDirectives.py:1.1.2.1

Stephan Richter srichter@cbu.edu
Sun, 3 Mar 2002 23:36:14 -0500


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

Added Files:
      Tag: srichter-OFS_Formulator-branch
	TestViews.py __init__.py testAttributePublisher.py 
	testBrowserLanguages.py testDirectives.py 
Log Message:
Here are some of the changes made:

- Payload now keeps trakc of View Type

- Reimplementation of {set|get}ViewType in HTTPRequest, to overload the 
  standard BaseRequest one to look in the payload vor the View Type

- Implemented XMLRPCPayload

- Created IXMLRPCPublisher interface

- Implemenyed new Publisher interface in MethodPublisher

- Created xmlrpc ZCML namespace

- Move Payloads out of HTTP directory into Browser and XMLRPC


ToDo:

- Write and update tests. (nothing done yet)

- Update interfaces and create new ones

- Work on Authentication of XML-RPC

- Get rid of the 'Hacker' lines

- More refactoring needs to be done.



=== 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.2.1 2002/03/04 04:36:13 srichter Exp $
"""

from Interface import Interface
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher

class IC(Interface): pass

class V1:
    __implements__ = IBrowserPublisher

    def __init__(self,context): 
        self._context = context 

class VZMI(V1):
    pass

class R1:
    __implements__ = IBrowserPublisher

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/testAttributePublisher.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.Browser.AttributePublisher import AttributePublisher
from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher

from Interface import verify, instancesOfObjectImplements

class Presentation(AttributePublisher):
    index = 'index'
    action = 'action'
    foo = 'foo'

class TestAttributePublisher(unittest.TestCase):
    def setUp(self):
        self.pres = Presentation()

    def testImplementsIBrowserPublisher(self):
        self.failUnless(IBrowserPublisher.isImplementedBy(self.pres))

    def testInterfacesVerify(self):
        for interface in instancesOfObjectImplements(Presentation):
            verify(interface, Presentation)

    def testBrowserDefault(self):
        self.assertEquals(self.pres.browser_default(None),
            (self.pres, ('index.html',)))

    def testBrowserTraverseIndexHtml(self):
        self.assertEquals(self.pres.browser_traverse(None, 'index.html'),
            'index')

    def testBrowserTraverseIndex(self):
        self.assertEquals(self.pres.browser_traverse(None, 'index'),
            'index')

    def testBrowserTraverseActionHtml(self):
        self.assertEquals(self.pres.browser_traverse(None, 'action.html'),
            'action')

    def testBrowserTraverseAction(self):
        self.assertEquals(self.pres.browser_traverse(None, 'action'),
            'action')

    def testBrowserTraverseNotFound(self):
        self.failUnlessRaises(AttributeError, self.pres.browser_traverse, 
            None, 'bar')


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

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


=== Added File Zope3/lib/python/Zope/Publisher/XMLRPC/tests/testBrowserLanguages.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

class Test(unittest.TestCase):

    def test(self):
        request = {'HTTP_ACCEPT_LANGUAGE': 'da, en-gb;q=0.8, en;q=0.7'}

        from Zope.Publisher.Browser.BrowserLanguages import BrowserLanguages

        browser_languages = BrowserLanguages(request)

        self.assertEqual(list(browser_languages.getLanguages()),
                         ['da', 'en-gb', 'en'])

    # XXX Add support for quality statements


    

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/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.Browser.IBrowserPublisher import IBrowserPublisher
from Zope.Publisher.Browser.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:browser='http://namespaces.zope.org/browser'>
   %s
   </zopeConfigure>"""

class Ob:
    __implements__ = IC

class Test(CleanUp, unittest.TestCase):

    # XXX: tests for other directives needed

    def testView(self):

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

        xmlconfig(StringIO(template % (
            """
            <directive name="view"
                       attributes="component, name, for, layer"
               handler="Zope.Publisher.Browser.metaConfigure.view"
               namespace="http://namespaces.zope.org/browser" />
            <browser:view name="test"
                  factory="Zope.Publisher.Browser.tests.TestViews.V1"
                  for="Zope.Publisher.Browser.tests.TestViews.IC" /> 
            """
            ))) 
        
        self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
                                 ).__class__, V1)
         
    def testDefaultView(self):

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

        xmlconfig(StringIO(template % (
            """
            <directive name="defaultView"
                       attributes="component, name, for, layer"
               handler="Zope.Publisher.Browser.metaConfigure.defaultView"
               namespace="http://namespaces.zope.org/browser" />
            <browser:defaultView name="test"
                  factory="Zope.Publisher.Browser.tests.TestViews.V1"
                  for="Zope.Publisher.Browser.tests.TestViews.IC" /> 
            """
            ))) 
        
        self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
                                 ).__class__, V1)
        self.assertEqual(getDefaultViewName(ob, IBrowserPublisher
                                 ), 'test')
                                 
        
      
    def testSKinView(self):

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

        xmlconfig(StringIO(template % (
            """
            <directive name="view"
                       attributes="component, name, for, layer"
                handler="Zope.Publisher.Browser.metaConfigure.view"
                namespace="http://namespaces.zope.org/browser" />
            <directive name="skin" attributes="name, layers"
                handler="Zope.Publisher.Browser.metaConfigure.skin"
                namespace="http://namespaces.zope.org/browser" />
            <browser:skin name="zmi" layers="zmi," />
            <browser:view name="test"
                  factory="Zope.Publisher.Browser.tests.TestViews.VZMI"
                  layer="zmi" 
                  for="Zope.Publisher.Browser.tests.TestViews.IC" /> 
            <browser:view name="test"
                  factory="Zope.Publisher.Browser.tests.TestViews.V1"
                  for="Zope.Publisher.Browser.tests.TestViews.IC" />
            """
            ))) 
        
        self.assertEqual(getView(ob, 'test', IBrowserPublisher, None
                                 ).__class__, V1)
        self.assertEqual(getView(ob, 'test', IBrowserPublisher, None,
                                 skin='zmi').__class__,
                         VZMI)

    def testResource(self):

        ob = Ob()
        self.assertEqual(getResource(ob, 'test', IBrowserPublisher, None),
                         None)

        xmlconfig(StringIO(template % (
            """
            <directive name="resource"
                       attributes="component, name, layer"
               handler="Zope.Publisher.Browser.metaConfigure.resource"
               namespace="http://namespaces.zope.org/browser" />
            <browser:resource name="test"
                  component="Zope.Publisher.Browser.tests.TestViews.r1" /> 
            """
            ))) 
        
        self.assertEqual(
            getResource(ob, 'test', IBrowserPublisher, None).__class__,
            R1)
         
    def testSKinResource(self):

        ob = Ob()
        self.assertEqual(
            getResource(ob, 'test', IBrowserPublisher, None),
            None)

        xmlconfig(StringIO(template % (
            """
            <directive name="resource" attributes="component, name, layer"
                handler="Zope.Publisher.Browser.metaConfigure.resource"
                namespace="http://namespaces.zope.org/browser" />
            <directive name="skin" attributes="name, layers"
                handler="Zope.Publisher.Browser.metaConfigure.skin"
                namespace="http://namespaces.zope.org/browser" />
            <browser:skin name="zmi" layers="zmi," />
            <browser:resource name="test"
                  component="Zope.Publisher.Browser.tests.TestViews.rZMI"
                  layer="zmi" /> 
            <browser:resource name="test"
                  component="Zope.Publisher.Browser.tests.TestViews.r1" />
            """
            ))) 
        
        self.assertEqual(
            getResource(ob, 'test', IBrowserPublisher, None).__class__,
            R1)
        self.assertEqual(
            getResource(ob, 'test', IBrowserPublisher, None,
                        skin='zmi').__class__,
            RZMI)
    
def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

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