Skip to main content

An extension of WebTest with useful extras, including requests-style authentication.

Project description

An extension of WebTest with useful extras, including requests-style authentication.


$ pip install -U webtest-plus


import unittest
from myapp import app
from webtest_plus import TestApp

class TestMyApp(unittest.TestCase):

    def setUp(self): = TestApp(app)

    def test_protected_endpoint(self):
        response ="/secret/", expect_errors=True)
        assert response.status_code == 401
        # Requests-style authentication
        response ="/secret/", auth=("admin", "passw0rd"))
        assert response.status_code == 200

    def test_more_secrets(self):
        # Another way to authenticate"admin", password="passw0rd")
        assert"/secret/").status_code == 200
        assert"/secret/", expect_errors=True).status_code == 401

    def test_posting_json(self):
        # Testing json requests and responses
        response ="/postsecret/", {"secret": "myprecious"},
                                        auth=("admin", "passw0rd"))
        assert response.request.content_type == "application/json"

    def test_clicking(self):
        response ="/")
        response ="Protected link", auth=("admin", "passw0rd"))
        assert response.status_code == 200

    def test_token_auth(self):
        response ='/secret-requires-token/', expect_errors=True)
        assert response.status_code == 401

        # Authenticate with JWT
        response ='/secret-requires-token',
            auth='yourlongtokenhere', auth_type='jwt')
        assert response.status_code == 200


  • Basic HTTP authentication
  • JSON Web Token authentication
  • Auto-follow redirects
  • Framework-agnostic


  • Python >= 2.6 or >= 3.3


MIT licensed. See the bundled LICENSE file for more details.


1.0.0 (2017-05-17)

  • Fix handling of utf-encoded values when using auth (#3). Thanks @biern for the catch and patch.
  • Drop support for Python 2.6.
  • Test against Python 3.6.

0.3.3 (2015-03-17)

  • Implement TestApp.head.

0.3.2 (2014-06-04)

  • Bug fix that caused an UnboundLocalError.

0.3.1 (2014-05-31)

  • Fix string encoding bug on Python 2.

0.3.0 (2014-05-31)

  • Add support for JSON web token authentication.

0.2.1 (2013-11-24)

  • Add authentication to and TestResponse.clickbutton.

0.2.0 (2013-10-15)

  • Add support for JSON methods (e.g. app.post_json, etc.)

0.1.0 (2013-10-06)

  • First release.
  • HTTP Basic Authentication working.

Project details

Download files

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

Files for webtest-plus, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size webtest_plus-1.0.0-py2.py3-none-any.whl (9.8 kB) File type Wheel Python version 3.5 Upload date Hashes View
Filename, size webtest-plus-1.0.0.tar.gz (8.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page