<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PyRuby blog &#187; testing</title>
	<atom:link href="http://www.pyruby.com/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pyruby.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 12 Dec 2011 11:03:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Stubserver 0.1 released</title>
		<link>http://www.pyruby.com/2010/02/23/stubserver-0-1-released/</link>
		<comments>http://www.pyruby.com/2010/02/23/stubserver-0-1-released/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 04:03:41 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=63</guid>
		<description><![CDATA[<p>I&#8217;ve released a python stub webserver, described in an earlier blog post, on pypi.  The features include support for any method (i.e. PUT, POST, DELETE, GET, RHUBARB &#8230;), handles chunked encoding, and supports capturing data passed for later assertions.  </p>
<p>Because it&#8217;s on pypi, you can install using:-</p>
<p>pip install stubserver</p>
<p>or</p>
<p>easy_install stubserver</p>
<p>The verification model is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released a python stub webserver, described in an earlier <a href="http://www.pyruby.com/2009/11/22/testing-against-a-stub-web-server/">blog post</a>, on <a href="http://pypi.python.org/pypi/stubserver">pypi</a>.  The features include support for any method (i.e. PUT, POST, DELETE, GET, RHUBARB &#8230;), handles chunked encoding, and supports capturing data passed for later assertions.  </p>
<p>Because it&#8217;s on pypi, you can install using:-</p>
<p><code>pip install stubserver</code></p>
<p>or</p>
<p><code>easy_install stubserver</code></p>
<p>The verification model is very simplistic, each registered expectation is only expected to occur once.  To get more details, please refer to the <a href="http://www.pyruby.com/pythonstubserver/">documentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2010/02/23/stubserver-0-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stubbing a REST api in Python</title>
		<link>http://www.pyruby.com/2009/10/06/stubbing-a-rest-api-in-python/</link>
		<comments>http://www.pyruby.com/2009/10/06/stubbing-a-rest-api-in-python/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 04:58:19 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=15</guid>
		<description><![CDATA[<p>For the last few jobs I&#8217;ve had, Service Oriented Architecture has been a strong theme.  Having services presenting REST apis that consume and produce XML has been the regular approach.  When it comes to testing consumers of those services, I have found Python to be an extremely useful and convenient tool.  It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>For the last few jobs I&#8217;ve had, <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service Oriented Architecture</a> has been a strong theme.  Having services presenting REST apis that consume and produce XML has been the regular approach.  When it comes to testing consumers of those services, I have found Python to be an extremely useful and convenient tool.  It&#8217;s quick and easy to <a href="http://docs.python.org/library/basehttpserver.html">throw an HTTP server up</a> in Python, and hard code the values that it returns.  The problem is though, that I have ended up just adding code to the do_GET / do_POST methods as I add tests that handle different expectations.  This ends up separating the expectations and return values from the test, and making maintaining the stub code harder than it should be.  </p>
<p>To resolve this, I&#8217;d like to add expectations of the stub http server in the same way as with defining mocks.  The syntax would look something like this</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"> &nbsp; &nbsp;server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;GET&quot;</span>, url=<span class="st0">&quot;/address/<span class="es0">\d</span>+$&quot;</span><span class="br0">&#41;</span>.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>mime=<span class="st0">&quot;text/xml&quot;</span>, file_content=<span class="st0">&quot;path/to/response.xml&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; capture = <span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;PUT&quot;</span>, url=<span class="st0">&quot;/address/<span class="es0">\d</span>+$&quot;</span>, data_capture=capture<span class="br0">&#41;</span>.</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>reply_code=<span class="nu0">201</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;POST&quot;</span>, url=<span class="st0">&quot;address/<span class="es0">\d</span>+/inhabitant&quot;</span>, data=<span class="st0">&#8216;&lt;inhabitant name=&quot;Chris&quot;/&gt;&#8217;</span><span class="br0">&#41;</span>.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>reply_code=<span class="nu0">204</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;GET&quot;</span>, url=<span class="st0">&quot;/monitor/server_status$&quot;</span><span class="br0">&#41;</span>.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>content=<span class="st0">&quot;&lt;html&gt;&lt;body&gt;Server is up&lt;/body&gt;&lt;/html&gt;&quot;</span>, mime_type=<span class="st0">&quot;text/html&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1"># execute system under test</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">assertEquals</span><span class="br0">&#40;</span><span class="st0">&quot;&lt;expected&gt;&lt;xml/&gt;&lt;/expected&gt;&quot;</span>, capture<span class="br0">&#91;</span><span class="st0">&quot;body&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>So, over the next couple of weeks I&#8217;ll be putting this together, which should among other things allow me to improve the end to end testing story for <a href="http://djangorestmodel.sourceforge.net">djangoRESTModel</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/10/06/stubbing-a-rest-api-in-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

