TestApp
The TestApp class is accessible via the webtest module.
Attributes
Methods
f __init__(self, app, extra_environ=None, relative_to=None) ...
Wraps a WSGI application in a more convenient interface for testing.
app may be an application, or a Paste Deploy app URI, like 'config:filename.ini#test'.
extra_environ is a dictionary of values that should go into the environment for each request. These can provide a communication channel with the application.
relative_to is a directory, and filenames used for file uploads are calculated relative to this. Also config: URIs that aren't absolute.
f get(self, url, params=None, headers=None, extra_environ=None, status=None, expect_errors=False) ...
Get the given url (well, actually a path like '/page.html').
- params:
- A query string, or a dictionary that will be encoded into a query string. You may also include a query string on the url.
- headers:
- A dictionary of extra headers to send.
- extra_environ:
- A dictionary of environmental variables that should be added to the request.
- status:
- The integer status code you expect (if not 200 or 3xx). If you expect a 404 response, for instance, you must give status=404 or it will be an error. You can also give a wildcard, like '3*' or '*'.
- expect_errors:
- If this is not true, then if anything is written to wsgi.errors it will be an error. If it is true, then non-200/3xx responses are also okay.
Returns a webob.Response object.
f post(self, url, params='', headers=None, extra_environ=None, status=None, upload_files=None, expect_errors=False) ...
Do a POST request. Very like the .get() method. params are put in the body of the request.
upload_files is for file uploads. It should be a list of [(fieldname, filename, file_content)]. You can also use just [(fieldname, filename)] and the file content will be read from disk.
Returns a webob.Response object.
f put(self, url, params='', headers=None, extra_environ=None, status=None, upload_files=None, expect_errors=False) ...
Do a PUT request. Very like the .get() method. params are put in the body of the request.
upload_files is for file uploads. It should be a list of [(fieldname, filename, file_content)]. You can also use just [(fieldname, filename)] and the file content will be read from disk.
Returns a webob.Response object.
f delete(self, url, headers=None, extra_environ=None, status=None, expect_errors=False) ...
Do a DELETE request. Very like the .get() method. params are put in the body of the request.
Returns a webob.Response object.
f encode_multipart(self, params, files) ...
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).
f do_request(self, req, status, expect_errors) ...
Executes the given request (req), with the expected status. Generally .get() and .post() are used instead.
See the source for more information.