Latest Version: 0.9.6.2

TestApp


Attributes

a disabled

True

Methods

f __init__(self, app, namespace=None, relative_to=None, extra_environ=None, pre_request_hook=None, post_request_hook=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'.

namespace is a dictionary that will be written to (if provided). This can be used with doctest or some other system, and the variable res will be assigned everytime you make a request (instead of returning the request).

relative_to is a directory, and filenames used for file uploads are calculated relative to this. Also config: URIs that aren't absolute.

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.

pre_request_hook is a function to be called prior to making requests (such as post or get). This function must take one argument (the instance of the TestApp).

post_request_hook is a function, similar to pre_request_hook, to be called after requests are made.

f delete(self, url, params='', 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 response object

f do_request(self, req, status) ...

Executes the given request (req), with the expected status. Generally .get() and .post() are used instead.

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 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 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 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 response object

f reset(self) ...

Resets the state of the application; currently just clears saved cookies.

See the source for more information.

Top