Skip to main content

A static HTTP mock interface for requests

Project description

requests-staticmock

https://img.shields.io/pypi/v/requests-staticmock.svg https://img.shields.io/travis/tonybaloney/requests-staticmock.svg Documentation Status https://coveralls.io/repos/github/tonybaloney/requests-staticmock/badge.svg?branch=master

A static HTTP mock interface for requests

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


Download files

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

Source Distribution

requests-staticmock-0.2.0.tar.gz (16.7 kB view hashes)

Uploaded Source

Built Distribution

requests_staticmock-0.2.0-py2.py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 2 Python 3

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