requests-mock
Intro
requests-mock provides a simple way to stub out the HTTP portions or your testing code.
Usage
The only means of using requests-mock at the moment is in conjunction with the fixtures library.
import requests
import requests_mock
import testtools
class MyTestCase(testtools.TestCase):
def setUp(self):
super(MyTestCase, self).setUp()
self.requests_mock = self.useFixture(requests_mock.Mock())
def test_case(self):
self.requests_mock.register_uri('GET', 'http://www.google.com',
body='Success')
resp = requests.get('http://www.google.com')
self.assertEqual('Success', resp.text)
TODO
- Fixtures shouldn't be the only way of stubbing, should allow a context manager and a decorator.
- Should allow stubbing an individual session object rather than the entire library.
Description