Doc fixups

Add some of the recent request object attributes into the docs.

Change-Id: If699bf83379032e77ca08a91e0def70fb6b57202
This commit is contained in:
Jamie Lennox 2016-05-09 14:19:11 +10:00
parent 780eb4b4fe
commit 63fe479d22
2 changed files with 24 additions and 4 deletions

View File

@ -267,7 +267,8 @@ texinfo_documents = [
requests_uri = 'http://docs.python-requests.org/en/latest/'
urllib3_uri = 'http://urllib3.readthedocs.org/en/latest'
python_uri = 'http://docs.python.org/3.3'
python_uri = 'http://docs.python.org/3'
intersphinx_mapping = {'requests': (requests_uri, None),
'urllib': (python_uri, None),
'urllib3': (urllib3_uri, None),
'python': (python_uri, None)}

View File

@ -7,7 +7,7 @@ The object returned from creating a mock or registering a URI in an adapter is c
Called
======
The easiest way to test if a request hit the adapter is to simply check the called property.
The easiest way to test if a request hit the adapter is to simply check the called property or the call_count property.
.. doctest::
@ -38,10 +38,29 @@ The history of objects that passed through the `mocker`/`adapter` can also be re
>>> history[0].url
'http://test.com/'
This request history object is a wrapper around a standard :py:class:`requests.Request` object with some additional information that make the interface more workable (as the :py:class:`~requests.Request` object is generally not dealt with by users.
The alias `last_request` is also available for the last request to go through the mocker.
This request object is a wrapper around a standard :py:class:`requests.Request` object with some additional information that make the interface more workable (as the :py:class:`~requests.Request` object is generally not dealt with by users.
These additions include:
:text: The data of the request converted into a unicode string.
:json: The data of the request loaded from json into python objects.
:qs: The query string of the request. See :py:meth:`urllib.parse.parse_qs` for information on the return format.
:qs: The query string of the request. See :py:func:`urllib.parse.parse_qs` for information on the return format.
.. doctest::
>>> m.last_request.qs.scheme
'http'
>>> m.last_request.qs.netloc
'test.com'
The following parameters of the :py:func:`requests.request` call are also exposed via the request object:
:timeout: How long to wait for the server to send data before giving up.
:allow_redirects: Set to True if POST/PUT/DELETE redirect following is allowed.
:proxies: Dictionary mapping protocol to the URL of the proxy.
:verify: whether the SSL cert will be verified.
:cert: The client certificate or cert/key tuple for this request.
Note: That the default value of these attributes are the values that are passed to the adapter and not what is passed to the request method. This means that the default for allow_redirects is None (even though that is interpretted as True) if unset, whereas the defautl for verify is True, and the default for proxies the empty dict.