Skip to main content

The library to help test your HTTP requests using unittests

Project description


CircleCI Coverage Status PyPI version PyPI - License PyPI - Python Version PyPI - Status

The decorator and context manager to mock and verify HTTP requests made by requests library for unittest.

How to install

pip install requests-asserts

How to use

Make a list of RequestMock elements that contain all information about the expected request and response. Use RequestMock.assert_requests(request_mocks) with the list as a decorator or context manager.


import requests
from unittests import TestCase 

def get_likes_on_post(username, password, post_id):
    access_token =
        json={'username': username, 'password': password}

    likes = requests.get(
            'Accept': 'application/json', 
            'Authorization': f'Bearer {access_token}'

    return likes

class TestGetLikesOnPost(TestCase):
            request_json={'username': 'the name', 'password': 'the password'},
            response_json={"access_token": 'the-token'}
            request_headers_contains={'Authorization': 'Bearer the-token'},
            response_json={'name': 'The cool story', 'likes': 42}
    def test_get_likes_on_post(self):
        self.assertEqual(42, get_likes_on_post('the name', 'the password', 3))

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-asserts-0.1.3.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

requests_asserts-0.1.3-py3-none-any.whl (4.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page