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.2.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file Flask-WebTest-0.0.2.tar.gz.

File metadata

File hashes

Hashes for Flask-WebTest-0.0.2.tar.gz
Algorithm Hash digest
SHA256 797a593af566c0589d1bfc8676e67b5b2d177a0821a3cbd43c85cd6634c166c0
MD5 2c0230411d8c94e94d35180b2dcb7685
BLAKE2b-256 bceb98ff1182c42ffc3785d2a002f0086ecb5af21eecbcf357421e7fb7dfa021

See more details on using hashes here.

Provenance

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