[Zope3-checkins] CVS: Zope3/src/zope/app/browser/component/tests - test_interfacewidget.py:1.3
Steve Alexander
steve@cat-box.net
Sun, 5 Jan 2003 13:57:23 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/component/tests
In directory cvs.zope.org:/tmp/cvs-serv19046/src/zope/app/browser/component/tests
Modified Files:
test_interfacewidget.py
Log Message:
Added a widget for choosing a tuple of interfaces, and displaying them.
=== Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py:1.2 Wed Dec 25 09:12:29 2002
+++ Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py Sun Jan 5 13:56:50 2003
@@ -23,13 +23,11 @@
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.app.component.interfacefield import InterfaceField, InterfacesField
+from zope.app.browser.component.interfacewidget import InterfaceWidget
+from zope.app.browser.component.interfacewidget import MultiInterfaceWidget
from zope.publisher.browser import TestRequest
-from zope.component.service \
- import serviceManager, defineService
+from zope.component.service import serviceManager, defineService
class I(Interface):
@@ -49,11 +47,9 @@
def two():
"""method two"""
-class Test(CleanUp, TestCase):
- """Test Interface for InterfaceService Instance.
- """
+class BaseInterfaceWidgetTest(CleanUp, TestCase):
- def testInterfaceWidget(self):
+ def setUp(self):
service = InterfaceService()
defineService('Interfaces', IInterfaceService)
serviceManager.provideService('Interfaces', service)
@@ -63,11 +59,187 @@
request = TestRequest()
- interfaceField = InterfaceField(__name__ = 'TestName',
- title = u"This is a test",
+ self.request = request
+
+class TestMultiInterfaceWidget(BaseInterfaceWidgetTest):
+
+ def testMultiInterfaceWidget(self):
+ request = self.request
+ field = InterfacesField(__name__='TestName',
+ title=u'This is a test',
+ required=False)
+ widget = MultiInterfaceWidget(field, request)
+
+ self.assertEqual(widget.getData(), ())
+
+ out = (
+ 'Use refresh to enter more interfaces'
+ '<br>'
+
+ '<input type="text" name="field.TestName.search.i0" value="">'
+
+ '<select name="field.TestName.i0">'
+
+ '<option value="">---select interface---</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '</option>'
+
+ '</select>'
+
+ '<br>'
+
+ '<input type="text" name="field.TestName.search.i1" value="">'
+
+ '<select name="field.TestName.i1">'
+
+ '<option value="">---select interface---</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '</option>'
+
+ '</select>'
+ )
+ self.assertEqual(widget(), out)
+
+ widget = MultiInterfaceWidget(field, request)
+
+ request.form["field.TestName.i1"] = (
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ )
+ self.assertEqual(widget.getData(), (I2,))
+ out = (
+ 'Use refresh to enter more interfaces'
+ '<br>'
+
+ '<input type="text" name="field.TestName.search.i0" value="">'
+
+ '<select name="field.TestName.i0">'
+
+ '<option value="">---select interface---</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '</option>'
+
+ '</select>'
+
+ '<br>'
+ '<input type="text" name="field.TestName.search.i1" value="">'
+
+ '<select name="field.TestName.i1">'
+ '<option value="">---select interface---</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '" selected>'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '</option>'
+
+ '</select>'
+ )
+ self.assertEqual(widget(), out)
+
+ # There is no selected option because the option that would be
+ # selected has been filtered out by the search.
+ request.form["field.TestName.search.i1"] = 'two'
+ out = (
+ 'Use refresh to enter more interfaces'
+ '<br>'
+
+ '<input type="text" name="field.TestName.search.i0" value="">'
+
+ '<select name="field.TestName.i0">'
+
+ '<option value="">---select interface---</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I2'
+ '</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '</option>'
+
+ '</select>'
+
+ '<br>'
+
+ '<input type="text" name="field.TestName.search.i1" value="two">'
+
+ '<select name="field.TestName.i1">'
+ '<option value="">---select interface---</option>'
+ '<option value="'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '">'
+ 'zope.app.browser.component.tests.test_interfacewidget.I3'
+ '</option>'
+
+ '</select>'
+ )
+ self.assertEqual(widget(), out)
+
+
+class TestInterfaceWidget(BaseInterfaceWidgetTest):
+
+ def testInterfaceWidget(self):
+ request = self.request
+ field = InterfaceField(__name__='TestName',
+ title=u"This is a test",
required=False)
- widget = SingleInterfaceWidget(interfaceField, request)
+ widget = InterfaceWidget(field, request)
self.assertEqual(widget.getData(), None)
@@ -129,7 +301,7 @@
self.assertEqual(widget.getData(), None)
- widget = SingleInterfaceWidget(interfaceField, request)
+ widget = InterfaceWidget(field, request)
request.form["field.TestName"] = (
'zope.app.browser.component.tests.test_interfacewidget.I2'
@@ -181,4 +353,6 @@
def test_suite():
- return TestSuite((makeSuite(Test),))
+ return TestSuite((makeSuite(TestInterfaceWidget),
+ makeSuite(TestMultiInterfaceWidget)
+ ))