Public Member Functions | |
def | __contains__ |
def | __repr__ |
def | __str__ |
def | __unicode__ |
def | click |
def | clickbutton |
def | follow |
def | form |
def | forms |
def | goto |
def | html |
def | json |
def | lxml |
def | maybe_follow |
def | mustcontain |
def | normal_body |
def | pyquery |
def | showbrowser |
def | testbody |
def | unicode_normal_body |
def | xml |
Public Attributes | |
content_type | |
FIXME: would be nice to set xml:base, in some fashion. | |
Static Public Attributes | |
string | parser_features = 'html.parser' |
request = None | |
Private Member Functions | |
def | _find_element |
def | _follow |
def | _parse_forms |
Private Attributes | |
_normal_body | |
_unicode_normal_body | |
Static Private Attributes | |
_forms_indexed = None | |
tuple | _normal_body_regex = re.compile(to_bytes(r'[ \n\r\t]+')) |
tuple | _tag_re = re.compile(r'<(/?)([:a-z0-9_\-]*)(.*?)>', re.S | re.I) |
tuple | _unicode_normal_body_regex = re.compile('[ \\n\\r\\t]+') |
Instances of this class are returned by :class:`~webtest.app.TestApp` methods.
Definition at line 23 of file response.py.
def webtest.response.TestResponse.__contains__ | ( | self, | |
s | |||
) |
A response 'contains' a string if it is present in the body of the response. Whitespace is normalized when searching for a string.
Definition at line 323 of file response.py.
def webtest.response.TestResponse.__repr__ | ( | self | ) |
Definition at line 392 of file response.py.
def webtest.response.TestResponse.__str__ | ( | self | ) |
Definition at line 371 of file response.py.
def webtest.response.TestResponse.__unicode__ | ( | self | ) |
Definition at line 386 of file response.py.
def webtest.response.TestResponse._find_element | ( | self, | |
tag, | |||
href_attr, | |||
href_extract, | |||
content, | |||
id, | |||
href_pattern, | |||
index, | |||
verbose | |||
) | [private] |
Definition at line 183 of file response.py.
def webtest.response.TestResponse._follow | ( | self, | |
kw | |||
) | [private] |
Definition at line 84 of file response.py.
def webtest.response.TestResponse._parse_forms | ( | self | ) | [private] |
Definition at line 75 of file response.py.
def webtest.response.TestResponse.click | ( | self, | |
description = None , |
|||
linkid = None , |
|||
href = None , |
|||
index = None , |
|||
verbose = False , |
|||
extra_environ = None |
|||
) |
Click the link as described. Each of ``description``, ``linkid``, and ``url`` are *patterns*, meaning that they are either strings (regular expressions), compiled regular expressions (objects with a ``search`` method), or callables returning true or false. All the given patterns are ANDed together: * ``description`` is a pattern that matches the contents of the anchor (HTML and all -- everything between ``<a...>`` and ``</a>``) * ``linkid`` is a pattern that matches the ``id`` attribute of the anchor. It will receive the empty string if no id is given. * ``href`` is a pattern that matches the ``href`` of the anchor; the literal content of that attribute, not the fully qualified attribute. If more than one link matches, then the ``index`` link is followed. If ``index`` is not given and more than one link matches, or if no link matches, then ``IndexError`` will be raised. If you give ``verbose`` then messages will be printed about each link, and why it does or doesn't match. If you use ``app.click(verbose=True)`` you'll see a list of all the links. You can use multiple criteria to essentially assert multiple aspects about the link, e.g., where the link's destination is.
Definition at line 120 of file response.py.
def webtest.response.TestResponse.clickbutton | ( | self, | |
description = None , |
|||
buttonid = None , |
|||
href = None , |
|||
index = None , |
|||
verbose = False |
|||
) |
Like :meth:`~webtest.response.TestResponse.click`, except looks for link-like buttons. This kind of button should look like ``<button onclick="...location.href='url'...">``.
Definition at line 166 of file response.py.
def webtest.response.TestResponse.follow | ( | self, | |
kw | |||
) |
If this response is a redirect, follow that redirect. It is an error if it is not a redirect response. Any keyword arguments are passed to :class:`webtest.app.TestApp.get`. Returns another :class:`TestResponse` object.
Definition at line 92 of file response.py.
def webtest.response.TestResponse.form | ( | self | ) |
If there is only one form on the page, return it as a :class:`~webtest.forms.Form` object; raise a TypeError is there are no form or multiple forms.
Definition at line 47 of file response.py.
def webtest.response.TestResponse.forms | ( | self | ) |
Returns a dictionary containing all the forms in the pages as :class:`~webtest.forms.Form` objects. Indexes are both in order (from zero) and by form id (if the form is given an id). See :doc:`forms` for more info on form objects.
Definition at line 34 of file response.py.
def webtest.response.TestResponse.goto | ( | self, | |
href, | |||
method = 'get' , |
|||
args | |||
) |
Go to the (potentially relative) link ``href``, using the given method (``'get'`` or ``'post'``) and any extra arguments you want to pass to the :meth:`webtest.app.TestApp.get` or :meth:`webtest.app.TestApp.post` methods. All hostnames and schemes will be ignored.
Definition at line 251 of file response.py.
def webtest.response.TestResponse.html | ( | self | ) |
Returns the response as a `BeautifulSoup <http://www.crummy.com/software/BeautifulSoup/documentation.html>`_ object. Only works with HTML responses; other content-types raise AttributeError.
Definition at line 413 of file response.py.
def webtest.response.TestResponse.json | ( | self | ) |
Return the response as a JSON response. You must have `simplejson <http://goo.gl/B9g6s>`_ installed to use this, or be using a Python version with the json module. The content type must be one of json type to use this.
Definition at line 491 of file response.py.
def webtest.response.TestResponse.lxml | ( | self | ) |
Returns the response as an `lxml object <http://codespeak.net/lxml/>`_. You must have lxml installed to use this. If this is an HTML response and you have lxml 2.x installed, then an ``lxml.html.HTML`` object will be returned; if you have an earlier version of lxml then a ``lxml.HTML`` object will be returned.
Definition at line 459 of file response.py.
def webtest.response.TestResponse.maybe_follow | ( | self, | |
kw | |||
) |
Follow all redirects. If this response is not a redirect, do nothing. Any keyword arguments are passed to :class:`webtest.app.TestApp.get`. Returns another :class:`TestResponse` object.
Definition at line 104 of file response.py.
def webtest.response.TestResponse.mustcontain | ( | self, | |
strings, | |||
kw | |||
) |
mustcontain(*strings, no=[]) Assert that the response contains all of the strings passed in as arguments. Equivalent to:: assert string in res Can take a `no` keyword argument that can be a string or a list of strings which must not be present in the response.
Definition at line 335 of file response.py.
def webtest.response.TestResponse.normal_body | ( | self | ) |
Return the whitespace-normalized body
Definition at line 299 of file response.py.
def webtest.response.TestResponse.pyquery | ( | self | ) |
Returns the response as a `PyQuery <http://pyquery.org/>`_ object. Only works with HTML and XML responses; other content-types raise AttributeError.
Definition at line 506 of file response.py.
def webtest.response.TestResponse.showbrowser | ( | self | ) |
Show this response in a browser window (for debugging purposes, when it's hard to read the HTML).
Definition at line 525 of file response.py.
def webtest.response.TestResponse.testbody | ( | self | ) |
Definition at line 64 of file response.py.
Return the whitespace-normalized body, as unicode
Definition at line 310 of file response.py.
def webtest.response.TestResponse.xml | ( | self | ) |
Returns the response as an `ElementTree <http://python.org/doc/current/lib/module-xml.etree.ElementTree.html>`_ object. Only works with XML responses; other content-types raise AttributeError
Definition at line 430 of file response.py.
webtest::response.TestResponse::_forms_indexed = None [static, private] |
Definition at line 30 of file response.py.
Definition at line 301 of file response.py.
tuple webtest::response.TestResponse::_normal_body_regex = re.compile(to_bytes(r'[ \n\r\t]+')) [static, private] |
Definition at line 296 of file response.py.
tuple webtest::response.TestResponse::_tag_re = re.compile(r'<(/?)([:a-z0-9_\-]*)(.*?)>', re.S | re.I) [static, private] |
Definition at line 73 of file response.py.
Definition at line 312 of file response.py.
tuple webtest::response.TestResponse::_unicode_normal_body_regex = re.compile('[ \\n\\r\\t]+') [static, private] |
Definition at line 307 of file response.py.
FIXME: would be nice to set xml:base, in some fashion.
Definition at line 469 of file response.py.
string webtest::response.TestResponse::parser_features = 'html.parser' [static] |
Definition at line 31 of file response.py.
webtest::response.TestResponse::request = None [static] |
Definition at line 29 of file response.py.