Skip to main content

Provides an adapter for mocking HTTP requests for unit test purposes.

Project description

https://secure.travis-ci.org/ambv/requests-testadapter.png

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

Authors

Glued together by Łukasz Langa.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for requests-testadapter, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size requests-testadapter-0.1.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page