pnuckowski / aioresponses

Aioresponses is a helper for mock/fake web requests in python aiohttp package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aioresponses

image

image

Code Health

Updates

image

Documentation Status

Aioresponses is a helper to mock/fake web requests in python aiohttp package.

For requests module there are a lot of packages that help us with testing (eg. httpretty, responses, requests-mock).

When it comes to testing asynchronous HTTP requests it is a bit harder (at least at the beginning). The purpose of this package is to provide an easy way to test asynchronous HTTP requests.

Installing

Supported versions

  • Python 3.7+
  • aiohttp>=3.3.0,<4.0.0

Usage

To mock out HTTP request use aioresponses as a method decorator or as a context manager.

Response status code, body, payload (for json response) and headers can be mocked.

Supported HTTP methods: GET, POST, PUT, PATCH, DELETE and OPTIONS.

for convenience use payload argument to mock out json response. Example below.

as a context manager

aioresponses allows to mock out any HTTP headers

allows to register different responses for the same url

Repeat response for the same url

E.g. for cases you want to test retrying mechanisms

match URLs with regular expressions

allows to make redirects responses

allows to passthrough to a specified list of servers

aioresponses allows to throw an exception

aioresponses allows to use callbacks to provide dynamic responses

aioresponses can be used in a pytest fixture

Features

  • Easy to mock out HTTP requests made by aiohttp.ClientSession

License

  • Free software: MIT license

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

Aioresponses is a helper for mock/fake web requests in python aiohttp package.

License:MIT License


Languages

Language:Python 95.7%Language:Makefile 4.3%