A static HTTP mock interface for requests
Project description
requests-staticmock
A static HTTP mock interface for requests
Free software: Apache 2 License
Documentation: https://requests-staticmock.readthedocs.org.
Usage
As a context manager for requests Session instances
The requests_staticmock
import requests
import requests_staticmock
session = requests.Session()
with requests_staticmock.mock_session_with_fixtures(session, 'tests/fixtures', 'http://test_context.com'):
# will return a response object with the contents of tests/fixtures/test.json
response = new_session.request('get', 'http://test_context.com/test.json')
As an adapter
You can inject the requests_staticmock adapter into an existing (or new) requests session to mock out a particular URL or domain, e.g.
import requests
from requests_staticmock import Adapter
session = requests.Session()
special_adapter = Adapter('fixtures')
session.mount('http://specialwebsite.com', special_adapter)
session.request('http://normal.com/api/example') # works as normal
session.request('http://specialwebsite.com') # returns static mocks
Features
Allow mocking of HTTP responses via a directory of static fixtures
Support for sub-directories matching URL paths
Credits
This project takes inspiration and ideas from the requests_mock package, maintained by the OpenStack foundation.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.0 (2017-01-01)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
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
Hashes for requests-staticmock-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e340c1280f4c9888c3e8635eb8fea9011edf01875f4ec20c8c5eb5a4247a573 |
|
MD5 | b951b9d2364b5d7b853d81884e04daae |
|
BLAKE2b-256 | 6c88d281ebaffaa01d54087144fc0e3792f40370002d1889def1a7edb9c786c3 |
Hashes for requests_staticmock-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed9064a410bb15a7fb846af13ed8a8ba5150c8dbf55e2b5d3e42ed8e91078a9 |
|
MD5 | 42bbe3ceb29eb0512bfccc527684fbfd |
|
BLAKE2b-256 | 77fbe167fc8e069f6cdfbd3d346e6fbf45de56447f66735a0e7cd6cd11366771 |