Skip to main content

Utilities for testing Flask applications with WebTest.

Project description

Flask-WebTest provides a set of utilities to ease testing Flask applications with WebTest.

flask.ext.webtest.TestApp extends webtest.TestApp by adding few useful fields to response:

  • response.templates ― dictionary containing information about what templates were used to build the response and what their contexts were. The keys are template names and the values are template contexts. If only one template was used, it’s name and context can be accessed through response.template and response.context.

  • response.flashes ― list of tuples (category, message) containing messages that were flashed during request.

    Note: Fully supported only starting with Flask 0.10 (which is not released at the time of writing). If you use previous version, response.flashes will contain only those messages that was consumed by get_flashed_messages() template calls.

  • response.session ― dictionary containing session data.

Installation

pip install flask-webtest

Usage

from unittest import TestCase
from flask.ext.webtest import TestApp
from main import app


class ExampleTest(TestCase):
    def setUp(self):
        self.app = app
        self.w = TestApp(self.app)  # Or self.app.wsgi_app

    def test(self):
        r = self.w.get('/')
        self.assertFalse(r.flashes)
        self.assertEqual(r.context['text'], 'Hello!')
        self.assertEqual(r.template, 'template.html')
        self.assertFalse(r.flashes)
        self.assertNotIn('user_id', r.session)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-WebTest-0.0.1.tar.gz (2.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page