Package googleapiclient :: Module http :: Class HttpMockSequence
[hide private]
[frames] | no frames]

Class HttpMockSequence

source code


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.

  http = HttpMockSequence([
    ({'status': '401'}, ''),
    ({'status': '200'}, '{"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.

'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

Instance Methods [hide private]
 
__init__(self, iterable)
Args:...
source code
 
request(self, uri, method='GET', body=None, headers=None, redirections=1, connection_type=None) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, iterable)
(Constructor)

source code 

Args:
  iterable: iterable, a sequence of pairs of (headers, body)

Overrides: object.__init__