2014-06-15 12:08:57 +10:00
2014-06-15 00:15:32 +10:00
2014-06-15 11:12:21 +10:00
2014-06-15 12:08:57 +10:00
2014-06-15 11:12:21 +10:00
2014-04-10 13:13:07 +10:00
2014-04-10 13:13:07 +10:00
2014-06-15 11:12:21 +10:00
2014-06-14 20:36:04 +10:00
2014-06-15 11:12:21 +10:00

requests-mock

image

image

image

image

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
RETIRED, continues at github.com:jamielennox/requests-mock
Readme 664 KiB