Simple patching of `requests` calls
Project description
patch-requests
Simple patching of requests
calls.
Example from tests.py:
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('http://example.com')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {1: 1})
s = requests.Session()
response = s.post('http://www.example.com')
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/>')
s.close()
response = requests.patch('')
self.assertEqual(response.status_code, 500)
self.assertEqual(response.content, b'\\')
self.assertEqual(
p.mocks['get'].call_args_list[0][0], ('http://example.com',))
self.assertEqual(
p.mocks['post'].call_args_list[0][0], ('http://www.example.com',))
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for patch_requests-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe536d9a6ab9473484edf3961f9539e502cb7c5f2aa0708060a24c707d93e610 |
|
MD5 | 8eb6c976433a9647bb3f6e125b81cd84 |
|
BLAKE2b-256 | 4b4b1f173e02d5f1309c2a432a944ad05afcbf7797b828e1759afbad52d0cf10 |