Adjust examples and docs.

This commit is contained in:
Aldo Cortesi 2012-08-23 12:37:02 +12:00
parent d758409b76
commit b78a3817cd
3 changed files with 44 additions and 36 deletions

View File

@ -1,23 +1,22 @@
import requests import requests
from libpathod import test from libpathod import test
class Test: def test_simple():
""" """
Testing the requests module with Testing the requests module with
a pathod context manager. a pathod context manager.
""" """
def test_simple(self): # Start pathod in a separate thread
# Start pathod in a separate thread with test.Daemon() as d:
with test.Daemon() as d: # Get a URL for a pathod spec
# Get a URL for a pathod spec url = d.p("200:b@100")
url = d.p("200:b@100") # ... and request it
# ... and request it r = requests.put(url)
r = requests.put(url)
# Check the returned data # Check the returned data
assert r.status_code == 200 assert r.status_code == 200
assert len(r.content) == 100 assert len(r.content) == 100
# Check pathod's internal log # Check pathod's internal log
log = d.last_log()["request"] log = d.last_log()["request"]
assert log["method"] == "PUT" assert log["method"] == "PUT"

View File

@ -4,22 +4,32 @@
<section> <section>
<div class="page-header"> <div class="page-header">
<h1> <h1>
where how
<small>to get the code.</small> <small>to get it.</small>
</h1> </h1>
</div> </div>
<h3>git clone git://github.com/cortesi/pathod.git</h3> <p>The easiest way to install pathod is to use pip:</p>
<pre>pip install pathod</pre>
<p> You can find the project source on GitHub: </p>
<div style="margin-top: 20px; margin-bottom: 20px">
<a class="btn btn-primary btn-large" href="https://github.com/cortesi/pathod">github.com/cortesi/pathod</a>
</div>
<p>Please also use the <a
href="https://github.com/cortesi/pathod/issues">github issue tracker</a> to
report bugs. </p>
<p>Please use the <a href="http://github.com/cortesi/pathod/issues">github
issue tracker</a> to report bugs. </p>
</section> </section>
<section> <section>
<div class="page-header"> <div class="page-header">
<h1> <h1>
why why
<small>this was written.</small> <small>this it written.</small>
</h1> </h1>
</div> </div>

View File

@ -1,24 +1,23 @@
<div class="highlight"><pre><span class="kn">import</span> <span class="nn">requests</span> <div class="highlight"><pre><span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">from</span> <span class="nn">libpathod</span> <span class="kn">import</span> <span class="n">test</span> <span class="kn">from</span> <span class="nn">libpathod</span> <span class="kn">import</span> <span class="n">test</span>
<span class="k">class</span> <span class="nc">Test</span><span class="p">:</span> <span class="k">def</span> <span class="nf">test_simple</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span> <span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Testing the requests module with </span> <span class="sd"> Testing the requests module with</span>
<span class="sd"> a pathod context manager.</span> <span class="sd"> a pathod context manager.</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">test_simple</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c"># Start pathod in a separate thread</span>
<span class="c"># Start pathod in a separate thread</span> <span class="k">with</span> <span class="n">test</span><span class="o">.</span><span class="n">Daemon</span><span class="p">()</span> <span class="k">as</span> <span class="n">d</span><span class="p">:</span>
<span class="k">with</span> <span class="n">test</span><span class="o">.</span><span class="n">Daemon</span><span class="p">()</span> <span class="k">as</span> <span class="n">d</span><span class="p">:</span> <span class="c"># Get a URL for a pathod spec</span>
<span class="c"># Get a URL for a pathod spec</span> <span class="n">url</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">p</span><span class="p">(</span><span class="s">&quot;200:b@100&quot;</span><span class="p">)</span>
<span class="n">url</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">p</span><span class="p">(</span><span class="s">&quot;200:b@100&quot;</span><span class="p">)</span> <span class="c"># ... and request it</span>
<span class="c"># ... and request it</span> <span class="n">r</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
<span class="c"># Check the returned data</span> <span class="c"># Check the returned data</span>
<span class="k">assert</span> <span class="n">r</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">200</span> <span class="k">assert</span> <span class="n">r</span><span class="o">.</span><span class="n">status_code</span> <span class="o">==</span> <span class="mi">200</span>
<span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">content</span><span class="p">)</span> <span class="o">==</span> <span class="mi">100</span> <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">content</span><span class="p">)</span> <span class="o">==</span> <span class="mi">100</span>
<span class="c"># Check pathod&#39;s internal log</span> <span class="c"># Check pathod&#39;s internal log</span>
<span class="n">log</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">last_log</span><span class="p">()[</span><span class="s">&quot;request&quot;</span><span class="p">]</span> <span class="n">log</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">last_log</span><span class="p">()[</span><span class="s">&quot;request&quot;</span><span class="p">]</span>
<span class="k">assert</span> <span class="n">log</span><span class="p">[</span><span class="s">&quot;method&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;PUT&quot;</span> <span class="k">assert</span> <span class="n">log</span><span class="p">[</span><span class="s">&quot;method&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;PUT&quot;</span>
</pre></div> </pre></div>