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
methodParameters: - 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
andtornado.httpclient.HTTPResponse
objects into a vcr output utilizing an underlying writerParameters: - 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
- writer (object) – writer object that supports
-
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 writerParameters: - writer (object) – writer object that will recieve yaml string. Must support
write(str)
- yaml (yaml) – yaml encoder, must support pyyaml-like interface
- writer (object) – writer object that will recieve yaml string. Must support
-
recorder.
run
(port, target, no_headers=False, skip_methods=None)[source]¶ Starts a vcr proxy on a given
port
usingtarget
as a request destinationParameters: - 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