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
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 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.
Metadata
Release files for webtest-plus 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| webtest-plus-1.0.0.tar.gz | 8.9 kB | Without provenance | Details for webtest-plus-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| webtest_plus-1.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for webtest_plus-1.0.0-py2.py3-none-any.whl |
Total release size: 18.7 kB
Release files / webtest-plus-1.0.0.tar.gz
| Download URL | webtest-plus-1.0.0.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bebad7ac36c895daffa09def88d27c0cd9683e142a84a518b82b264a3a06872
|
|
BLAKE2b-256 checksum How to use checksums |
d39fa05220d4c2dca02c1a0db58246aa2639f22665800b8366bd0306069e26a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / webtest_plus-1.0.0-py2.py3-none-any.whl
| Download URL | webtest_plus-1.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
70c1eb5092863d2d769984c5aee56d577817a189bee149e622e4ecb68caf3270
|
|
BLAKE2b-256 checksum How to use checksums |
7d777c2bd17a367266f2a74f844917107fd2e5d876b219c96557df4ee4dde511
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for webtest-plus 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.