Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Static Private Attributes
webtest.forms.Form Class Reference

List of all members.

Public Member Functions

def __getitem__
def __init__
def __repr__
def __setitem__
def get
def lint
def select
def select_multiple
def set
def submit
def submit_fields
def upload_fields

Public Attributes

 action
 enctype
 field_order
 fields
 html
 id
 method
 response
 text

Static Public Attributes

 FieldClass = Field

Private Member Functions

def _parse_fields

Static Private Attributes

tuple _label_re
tuple _tag_re = re.compile(r'<(/?)([a-z0-9_\-]*)([^>]*?)>', re.I)

Detailed Description

This object represents a form that has been found in a page.

:param response: `webob.response.TestResponse` instance
:param text: Unparsed html of the form

.. attribute:: text

    the full HTML of the form.

.. attribute:: action

    the relative URI of the action.

.. attribute:: method

    the HTTP method (e.g., ``'GET'``).

.. attribute:: id

    the id, or None if not given.

.. attribute:: enctype

    encoding of the form submission

.. attribute:: fields

    a dictionary of fields, each value is a list of fields by
    that name.  ``<input type=\"radio\">`` and ``<select>`` are
    both represented as single fields with multiple options.

.. attribute:: field_order

    Ordered list of field names as found in the html.

Definition at line 358 of file forms.py.


Constructor & Destructor Documentation

def webtest.forms.Form.__init__ (   self,
  response,
  text,
  parser_features = 'html.parser' 
)

Definition at line 405 of file forms.py.


Member Function Documentation

def webtest.forms.Form.__getitem__ (   self,
  name 
)
Get the named field object (ambiguity is an error).

Definition at line 517 of file forms.py.

Definition at line 669 of file forms.py.

def webtest.forms.Form.__setitem__ (   self,
  name,
  value 
)
Set the value of the named field. If there is 0 or multiple fields
by that name, it is an error.

Multiple checkboxes of the same name are special-cased; a list may be
assigned to them to check the checkboxes whose value is present in the
list (and uncheck all others).

Setting the value of a ``<select>`` selects the given option (and
confirms it is an option). Setting radio fields does the same.
Checkboxes get boolean values. You cannot set hidden fields or buttons.

Use ``.set()`` if there is any ambiguity and you must provide an index.

Definition at line 488 of file forms.py.

def webtest.forms.Form._parse_fields (   self) [private]

Definition at line 419 of file forms.py.

def webtest.forms.Form.get (   self,
  name,
  index = None,
  default = utils.NoDefault 
)
Get the named/indexed field object, or ``default`` if no field is
found. Throws an AssertionError if no field is found and no ``default``
was given.

Definition at line 556 of file forms.py.

def webtest.forms.Form.lint (   self)
Check that the html is valid:

- each field must have an id
- each field must have a label

Definition at line 527 of file forms.py.

def webtest.forms.Form.select (   self,
  name,
  value = None,
  text = None,
  index = None 
)
Like ``.set()``, except also confirms the target is a ``<select>``
and allows selecting options by text.

Definition at line 573 of file forms.py.

def webtest.forms.Form.select_multiple (   self,
  name,
  value = None,
  texts = None,
  index = None 
)
Like ``.set()``, except also confirms the target is a
``<select multiple>`` and allows selecting options by text.

Definition at line 582 of file forms.py.

def webtest.forms.Form.set (   self,
  name,
  value,
  index = None 
)
Set the given name, using ``index`` to disambiguate.

Definition at line 545 of file forms.py.

def webtest.forms.Form.submit (   self,
  name = None,
  index = None,
  value = None,
  args 
)
Submits the form.  If ``name`` is given, then also select that
button (using ``index`` or ``value`` to disambiguate)``.

Any extra keyword arguments are passed to the
:meth:`webtest.TestResponse.get` or
:meth:`webtest.TestResponse.post` method.

Returns a :class:`webtest.TestResponse` object.

Definition at line 591 of file forms.py.

def webtest.forms.Form.submit_fields (   self,
  name = None,
  index = None,
  submit_value = None 
)
Return a list of ``[(name, value), ...]`` for the current state of
the form.

:param name: Same as for :meth:`submit`
:param index: Same as for :meth:`submit`

Definition at line 625 of file forms.py.

Return a list of file field tuples of the form::

    (field name, file name)

or::

    (field name, file name, file contents).

Definition at line 608 of file forms.py.


Member Data Documentation

tuple webtest::forms.Form::_label_re [static, private]
Initial value:
re.compile(
        '''<label\s+(?:[^>]*)for=(?:"|')([a-z0-9_\-]+)(?:"|')(?:[^>]*)>''',
        re.I)

Definition at line 399 of file forms.py.

tuple webtest::forms.Form::_tag_re = re.compile(r'<(/?)([a-z0-9_\-]*)([^>]*?)>', re.I) [static, private]

Definition at line 398 of file forms.py.

Definition at line 405 of file forms.py.

Definition at line 405 of file forms.py.

Definition at line 419 of file forms.py.

Definition at line 403 of file forms.py.

Definition at line 419 of file forms.py.

Definition at line 405 of file forms.py.

Definition at line 405 of file forms.py.

Definition at line 405 of file forms.py.

Definition at line 405 of file forms.py.

Definition at line 405 of file forms.py.


The documentation for this class was generated from the following file:


webtest
Author(s): AlexV
autogenerated on Sat Jun 8 2019 20:32:08