Routines for testing WSGI applications.
Wraps a WSGI application in a more convenient interface for testing. It uses extended version of webob.BaseRequest and webob.Response.
Parameters: |
|
---|
A convenient shortcut for a dict of all cookies in cookiejar.
alias of TestRequest
Do a DELETE request. Similar to get().
Returns: | webtest.TestResponse instance. |
---|
Do a DELETE request. Very like the delete method.
params are dumped to json and put in the body of the request. Content-Type is set to application/json.
Returns a webtest.TestResponse object.
Executes the given webob Request (req), with the expected status. Generally get() and post() are used instead.
To use this:
req = webtest.TestRequest.blank('url', ...args...)
resp = app.do_request(req)
Note
You can pass any keyword arguments to TestRequest.blank(), which will be set on the request. These can be arguments like content_type, accept, etc.
Encodes a set of parameters (typically a name/value list) and a set of files (a list of (name, filename, file_body)) into a typical POST body, returning the (content_type, body).
Do a GET request given the url path.
Parameters: |
|
---|---|
Returns: | webtest.TestResponse instance. |
Do a HEAD request. Similar to get().
Returns: | webtest.TestResponse instance. |
---|
Do a OPTIONS request. Similar to get().
Returns: | webtest.TestResponse instance. |
---|
Do a PATCH request. Similar to post().
Returns: | webtest.TestResponse instance. |
---|
Do a PATCH request. Very like the patch method.
params are dumped to json and put in the body of the request. Content-Type is set to application/json.
Returns a webtest.TestResponse object.
Do a POST request. Similar to get().
Parameters: |
|
---|---|
Returns: | webtest.TestResponse instance. |
Do a POST request. Very like the post method.
params are dumped to json and put in the body of the request. Content-Type is set to application/json.
Returns a webtest.TestResponse object.
Do a PUT request. Similar to post().
Returns: | webtest.TestResponse instance. |
---|
Do a PUT request. Very like the put method.
params are dumped to json and put in the body of the request. Content-Type is set to application/json.
Returns a webtest.TestResponse object.
Creates and executes a request. You may either pass in an instantiated TestRequest object, or you may pass in a URL and keyword arguments to be passed to TestRequest.blank().
You can use this to run a request without the intermediary functioning of TestApp.get() etc. For instance, to test a WebDAV method:
resp = app.request('/new-col', method='MKCOL')
Note that the request won’t have a body unless you specify it, like:
resp = app.request('/test.txt', method='PUT', body='test')
You can use webtest.TestRequest:
req = webtest.TestRequest.blank('/url/', method='GET')
resp = app.do_request(req)
Bases: webob.request.BaseRequest
A subclass of webob.Requset
alias of TestResponse
Bases: webob.response.Response
Instances of this class are returned by TestApp methods.
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:
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.
Like click(), except looks for link-like buttons. This kind of button should look like <button onclick="...location.href='url'...">.
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 webtest.app.TestApp.get. Returns another TestResponse object.
If there is only one form on the page, return it as a Form object; raise a TypeError is there are no form or multiple forms.
Returns a dictionary containing all the forms in the pages as Form objects. Indexes are both in order (from zero) and by form id (if the form is given an id).
See Form handling for more info on form objects.
Go to the (potentially relative) link href, using the given method ('get' or 'post') and any extra arguments you want to pass to the webtest.app.TestApp.get() or webtest.app.TestApp.post() methods.
All hostnames and schemes will be ignored.
Returns the response as a BeautifulSoup object.
Only works with HTML responses; other content-types raise AttributeError.
Return the response as a JSON response. You must have simplejson installed to use this, or be using a Python version with the json module.
The content type must be application/json to use this.
Returns the response as an lxml object. 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.
Follow all redirects. If this response is not a redirect, do nothing. Any keyword arguments are passed to webtest.app.TestApp.get. Returns another TestResponse object.
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.
Returns the response as a PyQuery object.
Only works with HTML and XML responses; other content-types raise AttributeError.
Show this response in a browser window (for debugging purposes, when it’s hard to read the HTML).
Returns the response as an ElementTree object.
Only works with XML responses; other content-types raise AttributeError
Helpers to fill and submit forms.
Bases: webtest.forms.Field
Field representing <input type="checkbox">
Returns True if checkbox is checked.
Like setting a value, except forces it (even for, say, hidden fields).
Bases: object
Base class for all Field objects.
Dictionary of field types (select, radio, etc)
Set/get value of the field.
Bases: webtest.forms.Field
Field representing <input type="file">
Like setting a value, except forces it (even for, say, hidden fields).
Bases: object
This object represents a form that has been found in a page.
Parameters: |
|
---|
the full HTML of the form.
the relative URI of the action.
the HTTP method (e.g., 'GET').
the id, or None if not given.
encoding of the form submission
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.
Ordered list of field names as found in the html.
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.
Check that the html is valid:
Like .set(), except also confirms the target is a <select>.
Submits the form. If name is given, then also select that button (using index to disambiguate)``.
Any extra keyword arguments are passed to the webtest.TestResponse.get() or webtest.TestResponse.post() method.
Returns a webtest.TestResponse object.
Bases: webtest.forms.Text
Field representing <input type="hidden">
Like setting a value, except forces it (even for, say, hidden fields).
Bases: webtest.forms.Field
Field representing <select multiple="multiple">
Bases: webtest.forms.Select
Field representing <input type="radio">
Like setting a value, except forces it (even for, say, hidden fields).
Bases: webtest.forms.Field
Field representing <select /> form element.
Bases: webtest.forms.Field
Field representing <input type="submit"> and <button>
Like setting a value, except forces it (even for, say, hidden fields).
Bases: webtest.forms.Field
Field representing <input type="text">
Like setting a value, except forces it (even for, say, hidden fields).
Bases: webtest.forms.Text
Field representing <textarea>
Like setting a value, except forces it (even for, say, hidden fields).
This module contains some helpers to deal with the real http world.
Bases: waitress.server.WSGIServer
StopableWSGIServer is a WSGIServer which run in a separated thread. This allow to use tools like casperjs or selenium.
Server instance have an application_url attribute formated with the server host and port.
Middleware to check for obedience to the WSGI specification.
Some of the things this checks:
When applied between a WSGI server and a WSGI application, this middleware will check for WSGI compliancy on a number of levels. This middleware does not modify the request or response in any way, but will throw an AssertionError if anything seems off (except for a failure to close the application iterator, which will be printed to stderr – there’s no way to throw an exception at that point).