API

class flask.ext.testing.TestCase(methodName='runTest')

assert200(response)

Checks if response status code is 200

Parameters: response – Flask response

assert400(response)

Checks if response status code is 400

Versionadded: 0.2.5

Parameters: response – Flask response

assert401(response)

Checks if response status code is 401

Versionadded: 0.2.1

Parameters: response – Flask response

assert403(response)

Checks if response status code is 403

Versionadded: 0.2

Parameters: response – Flask response

assert404(response)

Checks if response status code is 404

Parameters: response – Flask response

assert405(response)

Checks if response status code is 405

Versionadded: 0.2

Parameters: response – Flask response

assert500(response)

Checks if response status code is 500

Versionadded: 0.4.1

Parameters: response – Flask response

assertContext(name, value)

Checks if given name exists in the template context and equals the given value.

Versionadded:

0.2

Parameters:

  • name – name of context variable
  • value – value to check against

assertRedirects(response, location)

Checks if response is an HTTP redirect to the given location.

Parameters:

  • response – Flask response
  • location – relative URL (i.e. without http://localhost)

assertStatus(response, status_code)

Helper method to check matching response status.

Parameters:

  • response – Flask response
  • status_code – response status code (e.g. 200)

assertTemplateUsed(name, tmpl_name_attribute='name')

Checks if a given template is used in the request. Only works if your version of Flask has signals support (0.6+) and blinker is installed. If the template engine used is not Jinja2, provide tmpl_name_attribute with a value of its Template class attribute name which contains the provided name value.

Versionadded:

0.2

Parameters:

  • name – template name
  • tmpl_name_attribute – template engine specific attribute name

assert_200(response)

Checks if response status code is 200

Parameters: response – Flask response

assert_400(response)

Checks if response status code is 400

Versionadded: 0.2.5

Parameters: response – Flask response

assert_401(response)

Checks if response status code is 401

Versionadded: 0.2.1

Parameters: response – Flask response

assert_403(response)

Checks if response status code is 403

Versionadded: 0.2

Parameters: response – Flask response

assert_404(response)

Checks if response status code is 404

Parameters: response – Flask response

assert_405(response)

Checks if response status code is 405

Versionadded: 0.2

Parameters: response – Flask response

assert_500(response)

Checks if response status code is 500

Versionadded: 0.4.1 Parameters: response – Flask response

assert_context(name, value)

Checks if given name exists in the template context and equals the given value.

Versionadded:

0.2

Parameters:

  • name – name of context variable
  • value – value to check against

assert_redirects(response, location)

Checks if response is an HTTP redirect to the given location.

Parameters:

  • response – Flask response
  • location – relative URL (i.e. without http://localhost)

assert_status(response, status_code)

Helper method to check matching response status.

Parameters:

  • response – Flask response
  • status_code – response status code (e.g. 200)

assert_template_used(name, tmpl_name_attribute='name')

Checks if a given template is used in the request. Only works if your version of Flask has signals support (0.6+) and blinker is installed. If the template engine used is not Jinja2, provide tmpl_name_attribute with a value of its Template class attribute name which contains the provided name value.

Versionadded:

0.2

Parameters:

  • name – template name
  • tmpl_name_attribute – template engine specific attribute name

create_app()

Create your Flask app here, with any configuration you need.

get_context_variable(name)

Returns a variable from the context passed to the template. Only works if your version of Flask has signals support (0.6+) and blinker is installed.

Raises a ContextVariableDoesNotExist exception if does not exist in context.

Versionadded: 0.2

Parameters: name – name of variable

class flask.ext.testing.Twill(app, host='127.0.0.1', port=5000, scheme='http')

Versionadded: 0.3

Twill wrapper utility class.

Creates a Twill browser instance and handles WSGI intercept.

Usage:

  1. t = Twill(self.app)
  2. with t:
  3. t.browser.go("/")
  4. t.url("/")

url(url)

Makes complete URL based on host, port and scheme Twill settings.

Parameters: url – relative URL

class flask.ext.testing.TwillTestCase(methodName='runTest')

Deprecated: use Twill helper class instead.

Creates a Twill browser instance and handles WSGI intercept.

make_twill_url(url)

Makes complete URL based on host, port and scheme Twill settings.

Parameters: url – relative URL