Skip to main content

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

Project description

https://badge.fury.io/py/webtest-plus.png https://travis-ci.org/sloria/webtest-plus.png?branch=master

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

Install

$ pip install -U webtest-plus

Usage

import unittest
from myapp import app
from webtest_plus import TestApp

class TestMyApp(unittest.TestCase):

    def setUp(self):
        self.app = TestApp(app)

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

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

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

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

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

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

Features

  • Basic HTTP authentication

  • JSON Web Token authentication

  • Auto-follow redirects

  • Framework-agnostic

Requirements

  • Python >= 2.6 or >= 3.3

License

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

Changelog

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 TestResponse.click 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.

Source Distribution

webtest-plus-0.3.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

webtest_plus-0.3.1-py2.py3-none-any.whl (9.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file webtest-plus-0.3.1.tar.gz.

File metadata

File hashes

Hashes for webtest-plus-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3af1115decd012323af71a6c33e03df75de2f889e51f85f429e9772a003d205d
MD5 14d5d889abbf1f771d67a5bfc12deaa9
BLAKE2b-256 9e0b38ebab025a72451032caff266e79e538a4e629491234180af7cfe5881258

See more details on using hashes here.

File details

Details for the file webtest_plus-0.3.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for webtest_plus-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f751a9dbfb98d686489b2cb08f41fb8c28c1f2d4bad7f1cb9e23112ab0e897f9
MD5 fefdf12730706bd1d5b72ca035d3f1da
BLAKE2b-256 3452599eda64dd7e416192a34217aeeca6ef273085add300dcb4d2d4462d85e9

See more details on using hashes here.

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