[Zope3-checkins] CVS: Zope3/src/zope/app/form/browser/tests - test_directives.py:1.4

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Apr 25 12:19:19 EDT 2004


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

Modified Files:
	test_directives.py 
Log Message:


Added tests for brwoser:widget subdirective.



Added simple test for browser:addform.




=== Zope3/src/zope/app/form/browser/tests/test_directives.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/form/browser/tests/test_directives.py:1.3	Tue Mar 23 17:08:07 2004
+++ Zope3/src/zope/app/form/browser/tests/test_directives.py	Sun Apr 25 12:19:18 2004
@@ -18,22 +18,23 @@
 import os
 import unittest
 from cStringIO import StringIO
+from zope.component.exceptions import ComponentLookupError
+from zope.exceptions import NotFoundError
+from zope.interface import Interface, implements
+from zope.publisher.browser import TestRequest
 
 from zope.app import zapi
-from zope.interface import Interface, implements
+import zope.app.component
+import zope.app.form.browser
+import zope.app.publisher.browser
 
 from zope.configuration.xmlconfig import xmlconfig, XMLConfig
 from zope.component import getDefaultViewName, getResource
 from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.security.proxy import ProxyFactory
 
-from zope.component.exceptions import ComponentLookupError
-
-from zope.publisher.browser import TestRequest
-
-import zope.app.publisher.browser
-
-from zope.schema import TextLine
+from zope.schema import TextLine, Int
+from zope.app.form.browser import TextWidget
 
 tests_path = os.path.join(
     os.path.split(zope.app.publisher.browser.__file__)[0],
@@ -63,6 +64,15 @@
 
 ob = Ob()
 
+class ISomeWidget(Interface):
+    displayWidth = Int(
+        title=u"Display Width",
+        default=20,
+        required=True)
+
+class SomeWidget(TextWidget):
+    implements(ISomeWidget)
+
 
 class Test(PlacelessSetup, unittest.TestCase):
 
@@ -80,6 +90,31 @@
 
         ps =  zapi.getService(None, zapi.servicenames.Presentation)
         
+    def testAddForm(self):
+        self.assertEqual(zapi.queryView(ob, 'test', request),
+                         None)
+        xmlconfig(StringIO(template % ("""
+          <view
+              type="zope.publisher.interfaces.browser.IBrowserRequest"
+              for="zope.schema.interfaces.ITextLine"
+              provides="zope.app.form.interfaces.IInputWidget"
+              factory="zope.app.form.browser.TextWidget"
+              permission="zope.Public"
+              />
+
+          <browser:addform
+              for="zope.app.form.browser.tests.test_directives.IC"
+              schema="zope.app.form.browser.tests.test_directives.Schema"
+              name="add.html"
+              label="Add a ZPT page"
+              fields="text"
+              permission="zope.Public" />
+            """)))
+
+        v = zapi.queryView(ob, 'add.html', request)
+        # expect component lookup as standard macros are not configured
+        self.assertRaises(NotFoundError, v)
+
     def testEditForm(self):
         self.assertEqual(zapi.queryView(ob, 'test', request),
                          None)
@@ -109,7 +144,7 @@
     def testEditFormWithMenu(self):
         self.assertEqual(zapi.queryView(ob, 'test', request),
                          None)
-        xmlconfig(StringIO(template % ("""
+        xmlconfig(StringIO(template % ('''
           <browser:menu id="test_menu" title="Test menu"/>
           <view
               type="zope.publisher.interfaces.browser.IBrowserRequest"
@@ -128,14 +163,86 @@
               menu="test_menu"
               title="Test View"
               />
-            """)))
+            ''')))
 
         v = zapi.queryView(ob, 'edit.html', request)
         # expect component lookup as standard macros are not configured
         self.assertRaises(ComponentLookupError, v)
 
 
-# XXX Tests for AddFormDirective are missing
+    def testAddFormWithWidget(self):
+        self.assertEqual(zapi.queryView(ob, 'test', request),
+                         None)
+        xmlconfig(StringIO(template % ('''
+          <view
+              type="zope.publisher.interfaces.browser.IBrowserRequest"
+              for="zope.schema.interfaces.ITextLine"
+              provides="zope.app.form.interfaces.IInputWidget"
+              factory="zope.app.form.browser.TextWidget"
+              permission="zope.Public"
+              />
+
+          <browser:addform
+              for="zope.app.form.browser.tests.test_directives.IC"
+              schema="zope.app.form.browser.tests.test_directives.Schema"
+              name="add.html"
+              label="Add a ZPT page"
+              fields="text"
+              permission="zope.Public">
+
+            <widget
+                field="text"
+                class="zope.app.form.browser.tests.test_directives.SomeWidget"
+                displayWidth="30"
+                extra="foo"
+                />
+
+          </browser:addform>
+            ''')), )
+
+        view = zapi.queryView(ob, 'add.html', request)
+        self.assert_(hasattr(view, 'text_widget'))
+        self.assert_(isinstance(view.text_widget, SomeWidget))
+        self.assertEqual(view.text_widget.extra, u'foo')
+        self.assertEqual(view.text_widget.displayWidth, 30)
+
+
+    def testEditFormWithWidget(self):
+        self.assertEqual(zapi.queryView(ob, 'test', request),
+                         None)
+        xmlconfig(StringIO(template % ('''
+          <view
+              type="zope.publisher.interfaces.browser.IBrowserRequest"
+              for="zope.schema.interfaces.ITextLine"
+              provides="zope.app.form.interfaces.IInputWidget"
+              factory="zope.app.form.browser.TextWidget"
+              permission="zope.Public"
+              />
+
+          <browser:editform
+              for="zope.app.form.browser.tests.test_directives.IC"
+              schema="zope.app.form.browser.tests.test_directives.Schema"
+              name="edit.html"
+              label="Edit a ZPT page"
+              fields="text"
+              permission="zope.Public">
+
+            <widget
+                field="text"
+                class="zope.app.form.browser.tests.test_directives.SomeWidget"
+                displayWidth="30"
+                extra="foo"
+                />
+
+          </browser:editform>
+            ''')), )
+
+        view = zapi.queryView(ob, 'edit.html', request)
+        self.assert_(hasattr(view, 'text_widget'))
+        self.assert_(isinstance(view.text_widget, SomeWidget))
+        self.assertEqual(view.text_widget.extra, u'foo')
+        self.assertEqual(view.text_widget.displayWidth, 30)
+
 
 def test_suite():
     loader=unittest.TestLoader()




More information about the Zope3-Checkins mailing list