[Zope3-checkins] SVN: Zope3/trunk/src/zope/testbrowser/ - reorder interfaces.py to be more reader friendly

Benji York benji at zope.com
Sat Nov 12 12:22:54 EST 2005


Log message for revision 40065:
   - reorder interfaces.py to be more reader friendly
   - address non testing uses of zope.testbrowser briefly in README.txt
  

Changed:
  U   Zope3/trunk/src/zope/testbrowser/README.txt
  U   Zope3/trunk/src/zope/testbrowser/interfaces.py

-=-
Modified: Zope3/trunk/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/README.txt	2005-11-12 17:21:19 UTC (rev 40064)
+++ Zope3/trunk/src/zope/testbrowser/README.txt	2005-11-12 17:22:54 UTC (rev 40065)
@@ -2,17 +2,28 @@
 The Test Browser
 ================
 
-The ``zope.testbrowser`` module exposes a ``Browser`` class that
+The ``zope.testbrowser.browser`` module exposes a ``Browser`` class that
 simulates a web browser similar to Mozilla Firefox or IE.
 
+    >>> from zope.testbrowser.browser import Browser
+    >>> browser = Browser()
+
+This version of the browser object can be used to access any web site just as
+you would do using a normal web browser.
+
+There is also a special version of the ``Browser`` class used to do functional
+testing of Zope 3 applications, it can be imported from
+``zope.testbrowser.testing`` or just ``zope.testbrowser`` directly::
+
     >>> from zope.testbrowser import Browser
     >>> browser = Browser()
-    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
 
-It can send arbitrary headers; this is helpful for setting the language value,
-so that your tests format values the way you expect in your tests, if you rely
-on zope.i18n locale-based formatting or a similar approach.
+The browser can send arbitrary headers; this is helpful for setting the
+"Authorization" header or a language value, so that your tests format values
+the way you expect in your tests, if you rely on zope.i18n locale-based
+formatting or a similar approach.
 
+    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     >>> browser.addHeader('Accept-Language', 'en-US')
 
 The browser can `open` web pages:
@@ -25,7 +36,8 @@
 testbrowser doctests suggests using 'click' to navigate further (as discussed
 below), except in unusual circumstances.
 
-The test browser complies with the IBrowser interface.
+The test browser complies with the IBrowser interface; see
+``zope.testbrowser.interfaces`` for full interface details.
 
     >>> from zope.testbrowser import interfaces
     >>> from zope.interface.verify import verifyObject

Modified: Zope3/trunk/src/zope/testbrowser/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/testbrowser/interfaces.py	2005-11-12 17:21:19 UTC (rev 40064)
+++ Zope3/trunk/src/zope/testbrowser/interfaces.py	2005-11-12 17:22:54 UTC (rev 40065)
@@ -30,9 +30,130 @@
     from dummymodules import schema
 
 
+class IBrowser(interface.Interface):
+    """A Programmatic Web Browser."""
+
+    url = schema.URI(
+        title=u"URL",
+        description=u"The URL the browser is currently showing.",
+        required=True)
+
+    headers = schema.Field(
+        title=u"Headers",
+        description=u"Heards of the HTTP response; a ``httplib.HTTPMessage``.",
+        required=True)
+
+    contents = schema.Text(
+        title=u"Contents",
+        description=u"The complete response body of the HTTP request.",
+        required=True)
+
+    isHtml = schema.Bool(
+        title=u"Is HTML",
+        description=u"Tells whether the output is HTML or not.",
+        required=True)
+
+    title = schema.TextLine(
+        title=u"Title",
+        description=u"Title of the displayed page",
+        required=False)
+
+    handleErrors = schema.Bool(
+        title=u"Handle Errors",
+        description=(u"Describes whether server-side errors will be handled "
+                     u"by the publisher. If set to ``False``, the error will "
+                     u"progress all the way to the test, which is good for "
+                     u"debugging."),
+        default=True,
+        required=True)
+
+    def addHeader(key, value):
+        """Adds a header to each HTTP request.
+
+        Adding additional headers can be useful in many ways, from setting the
+        credentials token to specifying the browser identification string.
+        """
+
+    def open(url, data=None):
+        """Open a URL in the browser.
+
+        The URL must be fully qualified. However, note that the server name
+        and port is arbitrary for Zope 3 functional tests, since the request
+        is sent to the publisher directly.
+
+        The ``data`` argument describes the data that will be sent as the body
+        of the request.
+        """
+
+    def reload():
+        """Reload the current page.
+
+        Like a browser reload, if the past request included a form submission,
+        the form data will be resubmitted."""
+
+    def goBack(count=1):
+        """Go back in history by a certain amount of visisted pages.
+
+        The ``count`` argument specifies how far to go back. It is set to 1 by
+        default.
+        """
+
+    def getLink(text=None, url=None, id=None):
+        """Return an ILink from the page.
+
+        The link is found by the arguments of the method.  One or more may be
+        used together.
+
+          o ``text`` -- A regular expression trying to match the link's text,
+            in other words everything between <a> and </a> or the value of the
+            submit button.
+
+          o ``url`` -- The URL the link is going to. This is either the
+            ``href`` attribute of an anchor tag or the action of a form.
+
+          o ``id`` -- The id attribute of the anchor tag submit button.
+        """
+
+    def getControl(label=None, name=None, index=None):
+        """Get a control from the page.
+
+        Only one of ``label`` and ``name`` may be provided.  ``label``
+        searches form labels (including submit button values, per the HTML 4.0
+        spec), and ``name`` searches form field names.
+
+        Label value is searched as case-sensitive whole words within
+        the labels for each control--that is, a search for 'Add' will match
+        'Add a contact' but not 'Address'.  A word is defined as one or more
+        alphanumeric characters or the underline.
+
+        If no values are found, the code raises a LookupError.
+
+        If ``index`` is None (the default) and more than one field matches the
+        search, the code raises an AmbiguityError.  If an index is provided,
+        it is used to choose the index from the ambiguous choices.  If the
+        index does not exist, the code raises a LookupError.
+        """
+
+    def getForm(id=None, name=None, action=None, index=None):
+        """Get a form from the page.
+
+        Zero or one of ``id``, ``name``, and ``action`` may be provided.  If
+        none are provided the index alone is used to determine the return
+        value.
+
+        If no values are found, the code raises a LookupError.
+
+        If ``index`` is None (the default) and more than one form matches the
+        search, the code raises an AmbiguityError.  If an index is provided,
+        it is used to choose the index from the ambiguous choices.  If the
+        index does not exist, the code raises a LookupError.
+        """
+
+
 class ExpiredError(Exception):
     """The browser page to which this was attached is no longer active"""
 
+
 class IControl(interface.Interface):
     """A control (input field) of a page."""
 
@@ -69,6 +190,7 @@
     def clear():
         """Clear the value of the control."""
 
+
 class IListControl(IControl):
     """A radio button, checkbox, or select control"""
 
@@ -103,16 +225,19 @@
         """a list of subcontrols for the control.  mutating list has no effect
         on control (although subcontrols may be changed as usual).""")
 
+
 class ISubmitControl(IControl):
 
     def click():
         "click the submit button"
 
+
 class IImageSubmitControl(ISubmitControl):
 
     def click(coord=(1,1,)):
         "click the submit button with optional coordinates"
 
+
 class IItemControl(interface.Interface):
     """a radio button or checkbox within a larger multiple-choice control"""
 
@@ -140,6 +265,7 @@
         default=None,
         required=False)
 
+
 class ILink(interface.Interface):
 
     def click():
@@ -234,121 +360,3 @@
         """
 
 
-class IBrowser(interface.Interface):
-    """A Test Web Browser."""
-
-    url = schema.URI(
-        title=u"URL",
-        description=u"The URL the browser is currently showing.",
-        required=True)
-
-    headers = schema.Field(
-        title=u"Headers",
-        description=u"Heards of the HTTP response; a ``httplib.HTTPMessage``.",
-        required=True)
-
-    contents = schema.Text(
-        title=u"Contents",
-        description=u"The complete response body of the HTTP request.",
-        required=True)
-
-    isHtml = schema.Bool(
-        title=u"Is HTML",
-        description=u"Tells whether the output is HTML or not.",
-        required=True)
-
-    title = schema.TextLine(
-        title=u"Title",
-        description=u"Title of the displayed page",
-        required=False)
-
-    handleErrors = schema.Bool(
-        title=u"Handle Errors",
-        description=(u"Describes whether server-side errors will be handled "
-                     u"by the publisher. If set to ``False``, the error will "
-                     u"progress all the way to the test, which is good for "
-                     u"debugging."),
-        default=True,
-        required=True)
-
-    def addHeader(key, value):
-        """Adds a header to each HTTP request.
-
-        Adding additional headers can be useful in many ways, from setting the
-        credentials token to specifying the browser identification string.
-        """
-
-    def open(url, data=None):
-        """Open a URL in the browser.
-
-        The URL must be fully qualified. However, note that the server name
-        and port is arbitrary for Zope 3 functional tests, since the request
-        is sent to the publisher directly.
-
-        The ``data`` argument describes the data that will be sent as the body
-        of the request.
-        """
-
-    def reload():
-        """Reload the current page.
-
-        Like a browser reload, if the past request included a form submission,
-        the form data will be resubmitted."""
-
-    def goBack(count=1):
-        """Go back in history by a certain amount of visisted pages.
-
-        The ``count`` argument specifies how far to go back. It is set to 1 by
-        default.
-        """
-
-    def getLink(text=None, url=None, id=None):
-        """Return an ILink from the page.
-
-        The link is found by the arguments of the method.  One or more may be
-        used together.
-
-          o ``text`` -- A regular expression trying to match the link's text,
-            in other words everything between <a> and </a> or the value of the
-            submit button.
-
-          o ``url`` -- The URL the link is going to. This is either the
-            ``href`` attribute of an anchor tag or the action of a form.
-
-          o ``id`` -- The id attribute of the anchor tag submit button.
-        """
-
-    def getControl(label=None, name=None, index=None):
-        """Get a control from the page.
-
-        Only one of ``label`` and ``name`` may be provided.  ``label``
-        searches form labels (including submit button values, per the HTML 4.0
-        spec), and ``name`` searches form field names.
-
-        Label value is searched as case-sensitive whole words within
-        the labels for each control--that is, a search for 'Add' will match
-        'Add a contact' but not 'Address'.  A word is defined as one or more
-        alphanumeric characters or the underline.
-
-        If no values are found, the code raises a LookupError.
-
-        If ``index`` is None (the default) and more than one field matches the
-        search, the code raises an AmbiguityError.  If an index is provided,
-        it is used to choose the index from the ambiguous choices.  If the
-        index does not exist, the code raises a LookupError.
-        """
-
-    def getForm(id=None, name=None, action=None, index=None):
-        """Get a form from the page.
-
-        Zero or one of ``id``, ``name``, and ``action`` may be provided.  If
-        none are provided the index alone is used to determine the return
-        value.
-
-        If no values are found, the code raises a LookupError.
-
-        If ``index`` is None (the default) and more than one form matches the
-        search, the code raises an AmbiguityError.  If an index is provided,
-        it is used to choose the index from the ambiguous choices.  If the
-        index does not exist, the code raises a LookupError.
-        """



More information about the Zope3-Checkins mailing list