Recorder

VCR recorder for httpsrv API mocking library. Works as a proxy recording real API calls to yaml “vcr tape” that can further be used as httpsrv fixture

class recorder.ProxyHandler(application, request, **kwargs)[source]

Implementation of a tornado.web.RequestHandler that proxies any recieved request to a target URL and recorders everything that passes through into a given writer

initialize(httpclient, target, writer)[source]

Initializes a handler, overrides standard tornado.web.RequestHandler method

Parameters:
  • httpclient (tornado.httpclient.AsyncHTTPClient) – httpclient that will be used to make requests to target URL
  • target (str) – target API URL to proxy requests to
  • writer (VcrWriter) – vcr writer that will be used to output recorded requests
class recorder.VcrWriter(writer, json, no_headers=False, skip_methods=None)[source]

Converts tornado.httputil.HTTPServerRequest and tornado.httpclient.HTTPResponse objects into a vcr output utilizing an underlying writer

Parameters:
  • writer (object) – writer object that supports write(data) interface
  • json (json) – json module from standard library
  • no_headers (bool) – if True then no headers will be recorded for request or resposne
write(request, response)[source]

Writes a vcr output in a form of a dict from given tornado.httputil.HTTPServerRequest and tornado.httpclient.HTTPResponse

Parameters:
  • request (tornado.httputil.HTTPServerRequest) – server request
  • response (tornado.httpclient.HTTPResponse) – client response
class recorder.YamlWriter(writer, yaml)[source]

Acts as a decorator for the wrapped writer object. Any data given to YamlWriter.write() will be converted to yaml string and passde to the underlying writer

Parameters:
  • writer (object) – writer object that will recieve yaml string. Must support write(str)
  • yaml (yaml) – yaml encoder, must support pyyaml-like interface
write(data)[source]

Writes given data as a yaml string to an underlying stream

Parameters:data (any) – object that will be conveted to yaml string
recorder.run(port, target, no_headers=False, skip_methods=None)[source]

Starts a vcr proxy on a given port using target as a request destination

Parameters:
  • port (int) – port the proxy will bind to
  • target (str) – URL to proxy requests to, must be passed with protocol, e.g. http://some-url.com
  • no_headers (bool) – if True then no headers will be recorded for request or resposne
  • skip_methods (list) – recorder will not write any requests with provided methods to output
recorder.stop()[source]

Stops currently running vcr proxy