An extension of WebTest with useful extras, including requests-style authentication.
Project description
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.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
Built Distribution
File details
Details for the file webtest-plus-0.3.0.tar.gz
.
File metadata
- Download URL: webtest-plus-0.3.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95fa3776fbe7103d58285105325817034b7b5ed5d3d68efe8e2d3e3b596d00b1 |
|
MD5 | 0744d47a2bfe3c15805726ed2e9f5861 |
|
BLAKE2b-256 | c57fa01a55c9757c3b5d6a4bd9447c04a62c91c0232113918619f083d33abc9d |
File details
Details for the file webtest_plus-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: webtest_plus-0.3.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a40f4b039556b8f5d0d0d0b3408d4c06885949942abdcfe43dfcc01bb2e8ea67 |
|
MD5 | 993ebd3afaf2762aea693f14dce16c09 |
|
BLAKE2b-256 | d666cdffe04b12cf46c035f1d9c4e8fb3ad65b31b40426d5f4fed9d1e9aea347 |