Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sloria/webtest-plus
An extension of WebTest with useful extras, including requests-style authentication
https://github.com/sloria/webtest-plus
Last synced: 17 days ago
JSON representation
An extension of WebTest with useful extras, including requests-style authentication
- Host: GitHub
- URL: https://github.com/sloria/webtest-plus
- Owner: sloria
- License: mit
- Created: 2013-10-06T14:12:41.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-05-12T02:31:10.000Z (over 7 years ago)
- Last Synced: 2024-10-04T13:38:38.763Z (about 1 month ago)
- Language: Python
- Size: 31.3 KB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE
Awesome Lists containing this project
README
============
webtest-plus
============.. image:: https://badge.fury.io/py/webtest-plus.png
:target: http://badge.fury.io/py/webtest-plus.. image:: https://travis-ci.org/sloria/webtest-plus.png?branch=master
:target: https://travis-ci.org/sloria/webtest-plusAn extension of `WebTest `_ with useful extras, including `requests `_-style authentication.
Install
-------
.. code-block:: bash$ pip install -U webtest-plus
Usage
-----.. code-block:: python
import unittest
from myapp import app
from webtest_plus import TestAppclass 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 == 200def 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 == 401def 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 == 200def 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 == 200Features
--------* Basic HTTP authentication
* `JSON Web Token `_ authentication
* Auto-follow redirects
* Framework-agnosticRequirements
------------- Python >= 2.6 or >= 3.3
License
-------MIT licensed. See the bundled `LICENSE `_ file for more details.