requests_mock package¶
Subpackages¶
requests_mock.adapter module¶
- class requests_mock.adapter.Adapter[source]¶
Bases: requests.adapters.BaseAdapter, requests_mock.adapter._RequestHistoryTracker
A fake adapter than can return predefined responses.
- add_matcher(matcher)[source]¶
Register a custom matcher.
A matcher is a callable that takes a requests.Request and returns a requests.Response if it matches or None if not.
Parameters: matcher (callable) – The matcher to execute.
requests_mock.exceptions module¶
- exception requests_mock.exceptions.InvalidRequest[source]¶
Bases: requests_mock.exceptions.MockException
This call cannot be made under a mocked environment
- exception requests_mock.exceptions.MockException[source]¶
Bases: exceptions.Exception
Base Exception for library
- exception requests_mock.exceptions.NoMockAddress(request)[source]¶
Bases: requests_mock.exceptions.MockException
The requested URL was not mocked
requests_mock.fixture module¶
Module contents¶
- class requests_mock.Adapter¶
Bases: requests.adapters.BaseAdapter, requests_mock.adapter._RequestHistoryTracker
A fake adapter than can return predefined responses.
- add_matcher(matcher)¶
Register a custom matcher.
A matcher is a callable that takes a requests.Request and returns a requests.Response if it matches or None if not.
Parameters: matcher (callable) – The matcher to execute.
- close()¶
- register_uri(method, url, response_list=None, **kwargs)¶
Register a new URI match and fake response.
Parameters:
- send(request, **kwargs)¶
- requests_mock.create_response(request, **kwargs)¶
Parameters: - status_code (int) – The status code to return upon a successful match. Defaults to 200.
- raw (HTTPResponse) – A HTTPResponse object to return upon a successful match.
- body (io.IOBase) – An IO object with a read() method that can return a body on successful match.
- content (bytes) – A byte string to return upon a successful match.
- text (unicode) – A text string to return upon a successful match.
- json (object) – A python object to be converted to a JSON string and returned upon a successful match.
- headers (dict) – A dictionary object containing headers that are returned upon a successful match.
- class requests_mock.Mocker(**kwargs)¶
Bases: requests_mock.mocker.MockerCore
The standard entry point for mock Adapter loading.
- TEST_PREFIX = 'test'¶
- copy()¶
Returns an exact copy of current mock
- class requests_mock.MockerCore(**kwargs)¶
Bases: object
A wrapper around common mocking functions.
Automate the process of mocking the requests library. This will keep the same general options available and prevent repeating code.
- delete(*args, **kwargs)¶
- get(*args, **kwargs)¶
- head(*args, **kwargs)¶
- options(*args, **kwargs)¶
- patch(*args, **kwargs)¶
- post(*args, **kwargs)¶
- put(*args, **kwargs)¶
- request(*args, **kwargs)¶
- start()¶
Start mocking requests.
Install the adapter and the wrappers required to intercept requests.
- stop()¶
Stop mocking requests.
This should have no impact if mocking has not been started.
- exception requests_mock.MockException¶
Bases: exceptions.Exception
Base Exception for library
- exception requests_mock.NoMockAddress(request)¶
Bases: requests_mock.exceptions.MockException
The requested URL was not mocked