Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Test an API wrapper using requests.
import unittest
from mock import patch
import mymodule
class APITest(unittest.TestCase):
def test_wrapped_example(self, MockRequests):
mock_request = MockRequests()
# Set your status code you want to test against
mock_request.status_code = 200
# Set the response content you want to test against
mock_request.text = "{'Your expected response': 'Stuff'}"
# Make your request
response = mymodule.method()
# Test the result.
self.assertTrue(response.status_code == 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.