Latest Version: 0.9.6.2

TestResponse


Attributes

a disabled

True

a form

Returns a single Form instance; it is an error if there are multiple forms on the page.

a forms

A list of <form>s found on the page (instances of Form)

a normal_body

Return the whitespace-normalized body

Methods

f __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.

f __init__(self, test_app, status, headers, body, errors, total_time) ...

f all_headers(self, name) ...

Gets all headers by the name, returns as a list

f click(self, description=None, linkid=None, href=None, anchor=None, index=None, verbose=False) ...

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.
  • anchor is a pattern that matches the entire anchor, with its contents.

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.

f clickbutton(self, description=None, buttonid=None, href=None, button=None, index=None, verbose=False) ...

Like .click(), except looks for link-like buttons. This kind of button should look like <button onclick="...location.href='url'...">.

f follow(self, **kw) ...

If this request is a redirect, follow that redirect. It is an error if this is not a redirect response. Returns another response object.

f form__get(self) ...

f forms__get(self) ...

Returns a dictionary of Form objects. Indexes are both in order (from zero) and by form id (if the form is given an id).

f 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 app.get() or app.post() methods.

All hostnames and schemes will be ignored.

f header(self, name, default=<class 'paste.fixture.NoDefault'>) ...

Returns the named header; an error if there is not exactly one matching header (unless you give a default -- always an error if there is more than one header)

f mustcontain(self, *strings, **kw) ...

Assert that the response contains all of the strings passed in as arguments.

Equivalent to:

assert string in res

f showbrowser(self) ...

Show this response in a browser window (for debugging purposes, when it's hard to read the HTML).

See the source for more information.

Top