Docstring pass after pep8ify in tests/
This commit is contained in:
@@ -24,11 +24,12 @@ class HttpMock(object):
|
||||
"""Mock of httplib2.Http"""
|
||||
|
||||
def __init__(self, filename=None, headers=None):
|
||||
"""HttpMock constructor.
|
||||
|
||||
Args:
|
||||
filename: string, absolute filename to read response from
|
||||
headers: dict, header to return with response
|
||||
"""
|
||||
Args:
|
||||
filename: string, absolute filename to read response from
|
||||
headers: dict, header to return with response
|
||||
"""
|
||||
if headers is None:
|
||||
headers = {'status': '200 OK'}
|
||||
if filename:
|
||||
@@ -60,32 +61,34 @@ class HttpMock(object):
|
||||
class HttpMockSequence(object):
|
||||
"""Mock of httplib2.Http
|
||||
|
||||
Mocks a sequence of calls to request returning different responses for each
|
||||
call. Create an instance initialized with the desired response headers
|
||||
and content and then use as if an httplib2.Http instance.
|
||||
Mocks a sequence of calls to request returning different responses for each
|
||||
call. Create an instance initialized with the desired response headers
|
||||
and content and then use as if an httplib2.Http instance::
|
||||
|
||||
http = HttpMockSequence([
|
||||
({'status': '401'}, b''),
|
||||
({'status': '200'}, b'{"access_token":"1/3w","expires_in":3600}'),
|
||||
({'status': '200'}, 'echo_request_headers'),
|
||||
])
|
||||
resp, content = http.request("http://examples.com")
|
||||
http = HttpMockSequence([
|
||||
({'status': '401'}, b''),
|
||||
({'status': '200'}, b'{"access_token":"1/3w","expires_in":3600}'),
|
||||
({'status': '200'}, 'echo_request_headers'),
|
||||
])
|
||||
resp, content = http.request("http://examples.com")
|
||||
|
||||
There are special values you can pass in for content to trigger
|
||||
behavours that are helpful in testing.
|
||||
There are special values you can pass in for content to trigger
|
||||
behavours that are helpful in testing.
|
||||
|
||||
'echo_request_headers' means return the request headers in the response body
|
||||
'echo_request_headers_as_json' means return the request headers in
|
||||
the response body
|
||||
'echo_request_body' means return the request body in the response body
|
||||
'echo_request_uri' means return the request uri in the response body
|
||||
"""
|
||||
* 'echo_request_headers' means return the request headers in the response
|
||||
body
|
||||
* 'echo_request_headers_as_json' means return the request headers in
|
||||
the response body
|
||||
* 'echo_request_body' means return the request body in the response body
|
||||
* 'echo_request_uri' means return the request uri in the response body
|
||||
"""
|
||||
|
||||
def __init__(self, iterable):
|
||||
"""HttpMockSequence constructor.
|
||||
|
||||
Args:
|
||||
iterable: iterable, a sequence of pairs of (headers, body)
|
||||
"""
|
||||
Args:
|
||||
iterable: iterable, a sequence of pairs of (headers, body)
|
||||
"""
|
||||
self._iterable = iterable
|
||||
self.follow_redirects = True
|
||||
self.requests = []
|
||||
|
||||
@@ -677,16 +677,16 @@ class BasicCredentialsTests(unittest.TestCase):
|
||||
self.assertEqual(token_response, self.credentials.token_response)
|
||||
|
||||
def test_recursive_authorize(self):
|
||||
"""Tests that OAuth2Credentials does not introduce new method constraints.
|
||||
"""Tests that OAuth2Credentials doesn't intro. new method constraints.
|
||||
|
||||
Formerly, OAuth2Credentials.authorize monkeypatched the request method of
|
||||
its httplib2.Http argument with a wrapper annotated with
|
||||
@util.positional(1). Since the original method has no such annotation, that
|
||||
meant that the wrapper was violating the contract of the original method by
|
||||
adding a new requirement to it. And in fact the wrapper itself doesn't
|
||||
even respect that requirement. So before the removal of the annotation, this
|
||||
test would fail.
|
||||
"""
|
||||
Formerly, OAuth2Credentials.authorize monkeypatched the request method
|
||||
of its httplib2.Http argument with a wrapper annotated with
|
||||
@util.positional(1). Since the original method has no such annotation,
|
||||
that meant that the wrapper was violating the contract of the original
|
||||
method by adding a new requirement to it. And in fact the wrapper
|
||||
itself doesn't even respect that requirement. So before the removal of
|
||||
the annotation, this test would fail.
|
||||
"""
|
||||
token_response = {'access_token': '1/3w', 'expires_in': 3600}
|
||||
encoded_response = json.dumps(token_response).encode('utf-8')
|
||||
http = HttpMockSequence([
|
||||
|
||||
Reference in New Issue
Block a user