Provides an adapter for mocking HTTP requests for unit test purposes.
Project description
Currently a very basic module that provides an adapter for requests that mocks network activity for unit test purposes.
How to use
This code assumes your HTTP client is written in a way that enables passing a custom Session object. When that’s the case, all you have to do is to mount the adapter to answer for a specific prefix:
>>> import requests >>> from requests_testadapter import TestAdapter >>> s = requests.Session() >>> s.mount('http://', TestAdapter(b'Mock!', status=404)) >>> r = s.get('http://mocked.com') >>> r.status_code 404 >>> r.text 'Mock!'
You can also specify a headers dictionary as a keyword argument to TestAdapter.
How do I run the tests?
The easiest way would be to extract the source tarball and run:
$ python test/test_testadapter.py
Change Log
0.1.0
initial published version
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
Close
Hashes for requests-testadapter-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e3296863e3ab13cf786cd7c92840c08762bf8608740b86dac049989deb61efc |
|
MD5 | f4120c871a63204e172c5f1c504b1d0d |
|
BLAKE2b-256 | 47fbe6b487974a71f5026c16d87fc38474372ac37b14b1ad2c0e00ba70002949 |