[Zope3-checkins] CVS: Zope3/src/zope/app/browser/component/tests - __init__.py:1.1.2.1 test_interfacewidget.py:1.1.2.1

Jim Fulton jim@zope.com
Mon, 23 Dec 2002 14:31:03 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/component/tests
In directory cvs.zope.org:/tmp/cvs-serv19908/zope/app/browser/component/tests

Added Files:
      Tag: NameGeddon-branch
	__init__.py test_interfacewidget.py 
Log Message:
Initial renaming before debugging

=== Added File Zope3/src/zope/app/browser/component/tests/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py ===
##############################################################################
#
# Copyright (c) 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.
# 
##############################################################################
"""Interface field widget tests

$Id: test_interfacewidget.py,v 1.1.2.1 2002/12/23 19:31:02 jim Exp $
"""

__metaclass__ = type

from zope.interface import Interface
from unittest import TestCase, TestSuite, main, makeSuite
from zope.testing.cleanup import CleanUp
from zope.app.component.globalinterfaceservice import InterfaceService
from zope.app.component.globalinterfaceservice import IInterfaceService
from zope.app.component.interfacefield \
     import InterfaceField
from zope.app.browser.component.interfacewidget \
     import SingleInterfaceWidget
from zope.publisher.browser import TestRequest
from zope.component.service \
     import serviceManager, defineService


class I(Interface):
    """bah blah
    """
    
class I2(Interface):
    """eek
    """
    
class I3(Interface):
    """
    """
    def one():
        """method one"""

    def two():
        """method two"""
        
class Test(CleanUp, TestCase):
    """Test Interface for InterfaceService Instance.
    """

    def testInterfaceWidget(self):
        service = InterfaceService()
        defineService('Interfaces', IInterfaceService)
        serviceManager.provideService('Interfaces', service)
        service.provideInterface(I.__module__+'.'+I.__name__, I)
        service.provideInterface(I2.__module__+'.'+I2.__name__, I2)
        service.provideInterface(I3.__module__+'.'+I3.__name__, I3)

        request = TestRequest()
        
        interfaceField = InterfaceField(__name__ = 'TestName',
                                        title = u"This is a test",
                                        required=False)
        
        widget = SingleInterfaceWidget(interfaceField, request)
        
        self.assertEqual(widget.getData(), None)
       
        out = (
        '<input type="text" name="field.TestName.search" value="">' 
        '<select name="field.TestName">' 
        '<option value="">---select interface---</option>'

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I'
        '</option>' 

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        '</option>' 

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '</option>' 

        '</select>'
        )
        
        self.assertEqual(widget(), out)
        
        out = (
        '<input type="text" name="field.TestName.search" value="">'
        '<select name="field.TestName">'
        '<option value="">---select interface---</option>'

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I'
        '" selected>'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I'
        '</option>'

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        '</option>'

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '</option>'

        '</select>'
        )
        
        self.assertEqual(widget.render(I), out)

        self.assertEqual(widget.getData(), None)

        widget = SingleInterfaceWidget(interfaceField, request)
        
        request.form["field.TestName"] = (
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        )
        self.assertEqual(widget.getData(), I2)

        out = (
        '<input type="text" name="field.TestName.search" value="">' 
        '<select name="field.TestName">' 

        '<option value="">---select interface---</option>'
        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I'
        '</option>' 

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        '" selected>'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I2'
        '</option>' 

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '</option>' 

        '</select>'
        )
        self.assertEqual(widget(), out)
                
        request.form["field.TestName.search"] = 'two'
        out = (
        '<input type="text" name="field.TestName.search" value="two">' 
        '<select name="field.TestName">' 
        '<option value="">---select interface---</option>'

        '<option value="'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '">'
        'Zope.App.ComponentArchitecture.Browser.tests.testInterfaceWidget.I3'
        '</option>' 

        '</select>'
        )
        self.assertEqual(widget(), out)

       
def test_suite():
    return TestSuite((makeSuite(Test),))