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

Jim Fulton jim@zope.com
Sat, 25 Jan 2003 08:10:00 -0500


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

Modified Files:
	test_interfacewidget.py 
Log Message:

Added code to get the interface widget to only show interfaces that
satisfy the field constraint.

Added notation that multi-interface widgets should be used with
multi-interface fields, which we don't have yet.

Changed some string literal formatting to avoid confusing emacs Python
mode.




=== Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py:1.15	Fri Jan 17 11:31:33 2003
+++ Zope3/src/zope/app/browser/component/tests/test_interfacewidget.py	Sat Jan 25 08:09:57 2003
@@ -183,7 +183,43 @@
         )
         self.assertEqual(widget(), out)
 
-    def testInterfaceWidgetNone(self):
+    def testInterfaceWidget_w_constraint(self):
+        request = self.request
+        field = InterfaceField(
+            __name__='TestName',
+            title=u"This is a test",
+            required=False,
+            constraint=lambda i: not (i.__name__.endswith("2")),
+            )
+
+        widget = InterfaceWidget(field, request)
+
+        self.assertEqual(widget.getData(), None)
+        self.failIf(widget.haveData())
+
+        out = (
+        '<input type="text" name="field.TestName.search" value="">'
+        '<select name="field.TestName">'
+        '<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.I3'
+        '">'
+        'zope.app.browser.component.tests.test_interfacewidget.I3'
+        '</option>'
+
+        '</select>'
+        )
+
+        self.assertEqual(widget(), out)
+
+    def testInterfaceWidget_allow_None_as_well_as_interfaces(self):
         request = self.request
         field = InterfaceField(__name__='TestName',
                                title=u"This is a test",
@@ -347,6 +383,9 @@
         )
         self.assertEqual(widget.hidden(), out)
 
+
+# XXX Note that MultiInterface widgets should be for multi-interface fields
+
 class TestMultiInterfaceWidget(BaseInterfaceWidgetTest):
 
     def testMultiInterfaceWidget(self):
@@ -812,7 +851,7 @@
         search_string = 'foo"blee'
         select_name = 'selectname'
         out = (
-        '''<input type="text" name="searchname" value='foo"blee'>'''
+        '''<input type="text" name="searchname" value=\'foo"blee\'>'''
         '''<select name="selectname">'''
         '''<option value="">---select interface---</option>'''
         '''<option value="foo">foo</option>'''