<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-908080082616606516</id><updated>2024-08-30T01:09:54.855+02:00</updated><category term="python"/><category term="testing"/><title type='text'>Michael Nelson - Something driven development</title><subtitle type='html'>Software development thoughts and musings around Python, Ruby and other tools.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://michael-a-nelson.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://michael-a-nelson.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Michael</name><uri>http://www.blogger.com/profile/13080395092257355476</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFrtHbvdEY8VxkrdGrW6RcxgIUqnjwvuSvGiwRJamV3KiXWgCpd07_mYMIO1B3Es507FET3odj2amGoqgmYykfkfOuQIK4yS1FmiSNBskvHCso4gQ87FD2RLgIADh1F8/s220/MikeSooksWedding.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-908080082616606516.post-1030793217322498671</id><published>2009-05-20T23:12:00.002+02:00</published><updated>2009-05-20T23:37:36.214+02:00</updated><title type='text'>Outside-in development on Ubuntu</title><content type='html'>For over 6 months now I&#39;ve been working on &lt;a href=&quot;http://launchpad.net/&quot;&gt;launchpad.net&lt;/a&gt; - collaborative development for open source software - using Python (Zope). It&#39;s been an unreal experience seeing various testing strategies on such a large code-base, but the two things I miss the most while developing on launchpad are:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The ability to do outside-in development properly - as is possible with ruby&#39;s &lt;a href=&quot;http://cukes.info/&quot;&gt;Cucumber&lt;/a&gt; project (although, this could be used, but it&#39;d be adding yet-another-technology to the stack - I haven&#39;t tried &lt;a href=&quot;http://github.com/cpennington/pycucumber/tree/master&quot;&gt;pyCucumber&lt;/a&gt;, but it doesn&#39;t look too active), and&lt;/li&gt;&lt;li&gt;Something similar to &lt;a href=&quot;http://rspactorapp.com/&quot;&gt;rspactor&lt;/a&gt; - allowing tests to be run automatically as I edit files, and reporting them via the OS&#39;s notification system.&lt;/li&gt;&lt;/ol&gt;But trying to communicate exactly what I mean by that to people who haven&#39;t used rspactor or Cucumber is kind-of tricky, so here&#39;s a video demo&#39;ing how I&#39;d love to do inside-out development on Ubuntu...&lt;br /&gt;&lt;br /&gt;&lt;object width=&quot;660&quot; height=&quot;525&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube-nocookie.com/v/bvUDYmllVrM&amp;amp;hl=en&amp;amp;fs=1&amp;amp;rel=0&amp;amp;hd=1&amp;amp;border=1&quot;&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;embed src=&quot;http://www.youtube-nocookie.com/v/bvUDYmllVrM&amp;amp;hl=en&amp;amp;fs=1&amp;amp;rel=0&amp;amp;hd=1&amp;amp;border=1&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;660&quot; height=&quot;525&quot;&gt;&lt;/embed&gt;&lt;/object&gt;</content><link rel='replies' type='application/atom+xml' href='http://michael-a-nelson.blogspot.com/feeds/1030793217322498671/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/908080082616606516/1030793217322498671' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default/1030793217322498671'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default/1030793217322498671'/><link rel='alternate' type='text/html' href='http://michael-a-nelson.blogspot.com/2009/05/outside-in-development-on-ubuntu.html' title='Outside-in development on Ubuntu'/><author><name>Michael</name><uri>http://www.blogger.com/profile/13080395092257355476</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFrtHbvdEY8VxkrdGrW6RcxgIUqnjwvuSvGiwRJamV3KiXWgCpd07_mYMIO1B3Es507FET3odj2amGoqgmYykfkfOuQIK4yS1FmiSNBskvHCso4gQ87FD2RLgIADh1F8/s220/MikeSooksWedding.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-908080082616606516.post-2986572290392200891</id><published>2008-10-14T06:31:00.000+02:00</published><updated>2008-10-14T06:45:13.743+02:00</updated><title type='text'>Mocking in Python just got easier</title><content type='html'>Voidspace just released &lt;a href=&quot;http://www.voidspace.org.uk/python/weblog/arch_d7_2008_10_11.shtml&quot;&gt;Mock 0.4.0&lt;/a&gt; - an update to the excellent Mock library which brings a few conveniences and easier patching of module and class-level attributes.&lt;br /&gt;&lt;br /&gt;This makes tests using mocks easier to read, for example inside a test case:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;self.assertEquals(my_mock.my_method.call_args, &lt;br /&gt;    ((&#39;goodbye&#39;,),{&#39;hello&#39;: False}))&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Can now be written as:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;my_mock.my_method.assert_called_with(&#39;goodbye&#39;, hello=False)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Check it out!</content><link rel='replies' type='application/atom+xml' href='http://michael-a-nelson.blogspot.com/feeds/2986572290392200891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/908080082616606516/2986572290392200891' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default/2986572290392200891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default/2986572290392200891'/><link rel='alternate' type='text/html' href='http://michael-a-nelson.blogspot.com/2008/10/mocking-in-python-just-got-easier.html' title='Mocking in Python just got easier'/><author><name>Michael</name><uri>http://www.blogger.com/profile/13080395092257355476</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFrtHbvdEY8VxkrdGrW6RcxgIUqnjwvuSvGiwRJamV3KiXWgCpd07_mYMIO1B3Es507FET3odj2amGoqgmYykfkfOuQIK4yS1FmiSNBskvHCso4gQ87FD2RLgIADh1F8/s220/MikeSooksWedding.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-908080082616606516.post-1169768136746142869</id><published>2008-09-27T20:07:00.000+02:00</published><updated>2008-10-07T08:45:22.772+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="testing"/><title type='text'>Mocking with Django and Google AppEngine</title><content type='html'>Since working with &lt;a href=&quot;http://rspec.info/&quot;&gt;RSpec&lt;/a&gt; over the past 6 months - a Behaviour-Driven Development framework for ruby - I&#39;ve been wondering if there&#39;s anything comparable in Python (my preferred tool for development!). One of the things I love about RSpec is the ease with which &lt;a href=&quot;http://www.mockobjects.com/&quot;&gt;Mock objects&lt;/a&gt; can be used to keep tests focused.&lt;br /&gt;&lt;br /&gt;While there are a number of mock libraries around for Python most don&#39;t result in particularly readable test code. But I was pleasantly suprised to discover Michael Foord&#39;s &lt;a href=&quot;http://www.voidspace.org.uk/python/mock.html&quot;&gt;Mocking and Testing utilities&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;A simple example: I&#39;ve got a Django application hosted on Google AppEngine and say I want to write a simple test to verify that my view does require the user to be logged in with their Google account and if not, redirects appropriately - but I don&#39;t want to have to manually log a user in, or even use the Google api as part of my test. Here&#39;s a snippet showing how easy this is with Mock:&lt;br /&gt;&lt;code&gt;&lt;pre&gt;&lt;br /&gt;from mock import Mock&lt;br /&gt;from google.appengine.api import users&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;class MySpecialView(TestCase):&lt;br /&gt;&lt;br /&gt;    def setUp():&lt;br /&gt;        &quot;&quot;&quot; Create the required mocks for the view tests &quot;&quot;&quot;&lt;br /&gt;        # Mock the get_current_user method of the google users api&lt;br /&gt;        users.get_current_user = Mock()&lt;br /&gt;&lt;br /&gt;        # Create a mock user that we&#39;ll pretend is logged in&lt;br /&gt;        mock_user = Mock()&lt;br /&gt;&lt;br /&gt;        # Just for readability, save the special app-engine login url as &lt;br /&gt;        # an instance variable&lt;br /&gt;        self.url = reverse(&#39;my-special-view-name&#39;)&lt;br /&gt;        self.login_url = &quot;http://testserver/_ah/login?continue=http%%3A//testserver%s&quot; % self.url&lt;br /&gt;&lt;br /&gt;    def test_logged_in_user_can_access_page(self):&lt;br /&gt;        &quot;&quot;&quot;A logged in user should not be redirected to the login page&quot;&quot;&quot;&lt;br /&gt;        # Set the return value for the mocked &lt;br /&gt;        # get_current_user method:&lt;br /&gt;        users.get_current_user.return_value = mock_user&lt;br /&gt;&lt;br /&gt;        response = do_request()&lt;br /&gt;&lt;br /&gt;        # Make sure the mock method was called&lt;br /&gt;        self.assertTrue(users.get_current_user.called)&lt;br /&gt;&lt;br /&gt;        # And the redirect did not take place, but the &lt;br /&gt;        # normal template was rendered...&lt;br /&gt;        self.assertTemplateUsed(response, &#39;myapp/overview.html&#39;)&lt;br /&gt;       &lt;br /&gt;    def test_anonymous_user_is_redirected_to_login(self):&lt;br /&gt;        &quot;&quot;&quot; An anonymous user should be redirected to the login page&quot;&quot;&quot;&lt;br /&gt;        # Set the google api&#39;s get_current_user method to return None&lt;br /&gt;        users.get_current_user.return_value = None&lt;br /&gt;&lt;br /&gt;        response = self.do_request()&lt;br /&gt;&lt;br /&gt;        # Make sure the mock method was called&lt;br /&gt;        self.assertTrue(users.get_current_user.called)&lt;br /&gt;&lt;br /&gt;        # And that the redirect took place... note we can&#39;t use&lt;br /&gt;        # the normal assertRedirects due to the app-engine specific&lt;br /&gt;        # login url.&lt;br /&gt;        self.assertEquals(response.status_code, 302)&lt;br /&gt;        self.assertEquals(&lt;br /&gt;            response[&#39;location&#39;],&lt;br /&gt;            &quot;http://testserver/_ah/login?continue=http%%3A//testserver%s&quot; % self.url&lt;br /&gt;        )&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;Easy! Thanks &lt;a href=&quot;http://www.voidspace.org.uk/python/weblog/index.shtml&quot;&gt;Michael&lt;/a&gt;. The Mock object has lots of other goodies of course (such as auto-setting all the mock-methods from the real object, testing for call parameters etc.).</content><link rel='replies' type='application/atom+xml' href='http://michael-a-nelson.blogspot.com/feeds/1169768136746142869/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/908080082616606516/1169768136746142869' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default/1169768136746142869'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/908080082616606516/posts/default/1169768136746142869'/><link rel='alternate' type='text/html' href='http://michael-a-nelson.blogspot.com/2008/09/mocking-with-django-and-google-app.html' title='Mocking with Django and Google AppEngine'/><author><name>Michael</name><uri>http://www.blogger.com/profile/13080395092257355476</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFrtHbvdEY8VxkrdGrW6RcxgIUqnjwvuSvGiwRJamV3KiXWgCpd07_mYMIO1B3Es507FET3odj2amGoqgmYykfkfOuQIK4yS1FmiSNBskvHCso4gQ87FD2RLgIADh1F8/s220/MikeSooksWedding.gif'/></author><thr:total>0</thr:total></entry></feed>