[Zope3-checkins] SVN: Zope3/trunk/ allow the getForm() method to be called without arguments when

Fred L. Drake, Jr. fdrake at gmail.com
Thu Sep 21 17:52:05 EDT 2006


Log message for revision 70312:
  allow the getForm() method to be called without arguments when
  there is only one form (no disambiguation needed)
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/testbrowser/README.txt
  U   Zope3/trunk/src/zope/testbrowser/browser.py
  A   Zope3/trunk/src/zope/testbrowser/ftests/oneform.html

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2006-09-21 21:12:31 UTC (rev 70311)
+++ Zope3/trunk/doc/CHANGES.txt	2006-09-21 21:52:04 UTC (rev 70312)
@@ -10,6 +10,10 @@
 
     New features
 
+      - The getForm() method on testbrowser instances no longer needs
+        arguments to disambiguate among forms if there's only one form
+        in the input.
+
       - The security setting values from zope.app.security.settings are now
         exported by zope.app.securitypolicy.interfaces, since they are
         exposed by the APIs defined there, and are not used in the

Modified: Zope3/trunk/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/README.txt	2006-09-21 21:12:31 UTC (rev 70311)
+++ Zope3/trunk/src/zope/testbrowser/README.txt	2006-09-21 21:52:04 UTC (rev 70312)
@@ -1083,7 +1083,21 @@
     Traceback (most recent call last):
     LookupError
 
+If the HTML page contains only one form, no arguments to `getForm` are
+needed:
 
+    >>> oneform = Browser()
+    >>> oneform.open('http://localhost/@@/testbrowser/oneform.html')
+    >>> form = oneform.getForm()
+
+If the HTML page contains more than one form, `index` is needed to
+disambiguate if no other arguments are provided:
+
+    >>> browser.getForm()
+    Traceback (most recent call last):
+    ValueError: if no other arguments are given, index is required.
+
+
 Performance Testing
 -------------------
 

Modified: Zope3/trunk/src/zope/testbrowser/browser.py
===================================================================
--- Zope3/trunk/src/zope/testbrowser/browser.py	2006-09-21 21:12:31 UTC (rev 70311)
+++ Zope3/trunk/src/zope/testbrowser/browser.py	2006-09-21 21:52:04 UTC (rev 70312)
@@ -345,9 +345,6 @@
 
     def getForm(self, id=None, name=None, action=None, index=None):
         zeroOrOne([id, name, action], '"id", "name", and "action"')
-        if index is None and not any([id, name, action]):
-            raise ValueError(
-                'if no other arguments are given, index is required.')
 
         matching_forms = []
         for form in self.mech_browser.forms():
@@ -357,6 +354,13 @@
             or id == name == action == None):
                 matching_forms.append(form)
 
+        if index is None and not any([id, name, action]):
+            if len(matching_forms) == 1:
+                index = 0
+            else:
+                raise ValueError(
+                    'if no other arguments are given, index is required.')
+
         form = disambiguate(matching_forms, '', index)
         self.mech_browser.form = form
         return Form(self, form)

Added: Zope3/trunk/src/zope/testbrowser/ftests/oneform.html
===================================================================
--- Zope3/trunk/src/zope/testbrowser/ftests/oneform.html	2006-09-21 21:12:31 UTC (rev 70311)
+++ Zope3/trunk/src/zope/testbrowser/ftests/oneform.html	2006-09-21 21:52:04 UTC (rev 70312)
@@ -0,0 +1,14 @@
+<html>
+  <body>
+
+    <h1>Single Form Tests</h1>
+
+    <form id="1" name="one" action="forms.html"
+          enctype="multipart/form-data" method="post">
+      <input type="text" name="text-value" value="First Text" />
+      <input type="image" name="image-1" src="zope3logo.gif" />
+      <input type="submit" name="submit-1" value="Submit" />
+    </form>
+
+  </body>
+</html>



More information about the Zope3-Checkins mailing list