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.

Source Distribution

requests-testadapter-0.1.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page