/usr/share/doc/python-betamax-doc/html/cassettes.html is in python-betamax-doc 0.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What is a cassette? — Betamax 0.8.0 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.8.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="Betamax 0.8.0 documentation" href="index.html" />
<link rel="next" title="Implementation Details" href="implementation_details.html" />
<link rel="prev" title="API" href="api.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="what-is-a-cassette">
<h1>What is a cassette?<a class="headerlink" href="#what-is-a-cassette" title="Permalink to this headline">¶</a></h1>
<p>A cassette is a set of recorded interactions serialized to a specific format.
Currently the only supported format is <a class="reference external" href="http://json.org">JSON</a>. A cassette has a list (or array)
of interactions and information about the library that recorded it. This means
that the cassette’s structure (using JSON) is</p>
<div class="code javascript highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"http_interactions"</span><span class="p">:</span> <span class="p">[</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">],</span>
<span class="s2">"recorded_with"</span><span class="p">:</span> <span class="s2">"betamax"</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Each interaction is the object representing the request and response as well
as the date it was recorded. The structure of an interaction is</p>
<div class="code javascript highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"request"</span><span class="p">:</span> <span class="p">{</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">},</span>
<span class="s2">"response"</span><span class="p">:</span> <span class="p">{</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">},</span>
<span class="s2">"recorded_at"</span><span class="p">:</span> <span class="s2">"2013-09-28T01:25:38"</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Each request has the body, method, uri, and an object representing the
headers. A serialized request looks like:</p>
<div class="code javascript highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"body"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"string"</span><span class="p">:</span> <span class="s2">"..."</span><span class="p">,</span>
<span class="s2">"encoding"</span><span class="p">:</span> <span class="s2">"utf-8"</span>
<span class="p">},</span>
<span class="s2">"method"</span><span class="p">:</span> <span class="s2">"GET"</span><span class="p">,</span>
<span class="s2">"uri"</span><span class="p">:</span> <span class="s2">"http://example.com"</span><span class="p">,</span>
<span class="s2">"headers"</span><span class="p">:</span> <span class="p">{</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>A serialized response has the status_code, url, and objects
representing the headers and the body. A serialized response looks like:</p>
<div class="code javascript highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"body"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"encoding"</span><span class="p">:</span> <span class="s2">"utf-8"</span><span class="p">,</span>
<span class="s2">"string"</span><span class="p">:</span> <span class="s2">"..."</span>
<span class="p">},</span>
<span class="s2">"url"</span><span class="p">:</span> <span class="s2">"http://example.com"</span><span class="p">,</span>
<span class="s2">"status"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"code"</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
<span class="s2">"message"</span><span class="p">:</span> <span class="s2">"OK"</span>
<span class="p">},</span>
<span class="s2">"headers"</span><span class="p">:</span> <span class="p">{</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
<p>If you put everything together, you get:</p>
<div class="code javascript highlight-default" id="cassette-dict"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">"http_interactions"</span><span class="p">:</span> <span class="p">[</span>
<span class="p">{</span>
<span class="s2">"request"</span><span class="p">:</span> <span class="p">{</span>
<span class="p">{</span>
<span class="s2">"body"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"string"</span><span class="p">:</span> <span class="s2">"..."</span><span class="p">,</span>
<span class="s2">"encoding"</span><span class="p">:</span> <span class="s2">"utf-8"</span>
<span class="p">},</span>
<span class="s2">"method"</span><span class="p">:</span> <span class="s2">"GET"</span><span class="p">,</span>
<span class="s2">"uri"</span><span class="p">:</span> <span class="s2">"http://example.com"</span><span class="p">,</span>
<span class="s2">"headers"</span><span class="p">:</span> <span class="p">{</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">},</span>
<span class="s2">"response"</span><span class="p">:</span> <span class="p">{</span>
<span class="p">{</span>
<span class="s2">"body"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"encoding"</span><span class="p">:</span> <span class="s2">"utf-8"</span><span class="p">,</span>
<span class="s2">"string"</span><span class="p">:</span> <span class="s2">"..."</span>
<span class="p">},</span>
<span class="s2">"url"</span><span class="p">:</span> <span class="s2">"http://example.com"</span><span class="p">,</span>
<span class="s2">"status"</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">"code"</span><span class="p">:</span> <span class="mi">200</span><span class="p">,</span>
<span class="s2">"message"</span><span class="p">:</span> <span class="s2">"OK"</span>
<span class="p">},</span>
<span class="s2">"headers"</span><span class="p">:</span> <span class="p">{</span>
<span class="o">//</span> <span class="o">...</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">},</span>
<span class="s2">"recorded_at"</span><span class="p">:</span> <span class="s2">"2013-09-28T01:25:38"</span>
<span class="p">}</span>
<span class="p">],</span>
<span class="s2">"recorded_with"</span><span class="p">:</span> <span class="s2">"betamax"</span>
<span class="p">}</span>
</pre></div>
</div>
<p>If you were to pretty-print a cassette, this is vaguely what you would see.
Keep in mind that since Python does not keep dictionaries ordered, the items
may not be in the same order as this example.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last"><strong>Pro-tip</strong> You can pretty print a cassette like so:
<code class="docutils literal"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">json.tool</span> <span class="pre">cassette.json</span></code>.</p>
</div>
</div>
<div class="section" id="what-is-a-cassette-library">
<h1>What is a cassette library?<a class="headerlink" href="#what-is-a-cassette-library" title="Permalink to this headline">¶</a></h1>
<p>When configuring Betamax, you can choose your own cassette library directory.
This is the directory available from the current directory in which you want
to store your cassettes.</p>
<p>For example, let’s say that you set your cassette library to be
<code class="docutils literal"><span class="pre">tests/cassettes/</span></code>. In that case, when you record a cassette, it will be
saved there. To continue the example, let’s say you use the following code:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">requests</span> <span class="k">import</span> <span class="n">Session</span>
<span class="kn">from</span> <span class="nn">betamax</span> <span class="k">import</span> <span class="n">Betamax</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">Session</span><span class="p">()</span>
<span class="k">with</span> <span class="n">Betamax</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">cassette_library_dir</span><span class="o">=</span><span class="s1">'tests/cassettes'</span><span class="p">)</span><span class="o">.</span><span class="n">use_cassette</span><span class="p">(</span><span class="s1">'example'</span><span class="p">):</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'https://httpbin.org/get'</span><span class="p">)</span>
</pre></div>
</div>
<p>You would then have the following directory structure:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span>.
`-- tests
`-- cassettes
`-- example.json
</pre></div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">What is a cassette?</a></li>
<li><a class="reference internal" href="#what-is-a-cassette-library">What is a cassette library?</a></li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="api.html" title="previous chapter">API</a></li>
<li>Next: <a href="implementation_details.html" title="next chapter">Implementation Details</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/cassettes.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
©2013-2016 - Ian Cordasco.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.4.8</a>
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.8</a>
|
<a href="_sources/cassettes.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>
|