Skip to main content

Simple patching of `requests` calls

Project description


Simple patching of requests calls.

Example from

import unittest
import requests
from patch_requests import patch_requests

class TestPatcher(unittest.TestCase):
    def test_multiple_requests(self):
        with patch_requests([
                ('get', (200, {1: 1})),
                ('post', (201, {2: 2})),
                ('GET', (404, '<html><p><br/>')),
                ('patch', (500, b'\\')),
                ]) as p:
            response = requests.get('')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.json(), {1: 1})

            s = requests.Session()

            response ='')
            self.assertEqual(response.status_code, 201)
            self.assertEqual(response.json(), {2: 2})

            response = s.get('http://')
            self.assertEqual(response.status_code, 404)
            self.assertEqual(response.text, '<html><p><br/>')


            response = requests.patch('')
            self.assertEqual(response.status_code, 500)
            self.assertEqual(response.content, b'\\')

            p.mocks['get'].call_args_list[0][0], ('',))
            p.mocks['post'].call_args_list[0][0], ('',))

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

patch-requests-0.2.0.tar.gz (2.5 kB view hashes)

Uploaded source

Built Distribution

patch_requests-0.2.0-py3-none-any.whl (3.5 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