<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Dave Dash</title>
 <link href="http://davedash.com/tag/djangocon/atom.xml" rel="self"/>
 <link href="http://davedash.com/tag/djangocon"/>
 <updated>2012-01-17T21:54:19-08:00</updated>
 <id>http://davedash.com/</id>
 <author>
   <name>Dave Dash</name>
   <email>dd+atom1@davedash.com</email>
 </author>

 
 <entry>
   <title>DjangoCon Testing Tutorial</title>
   <link href="http://davedash.com/2011/08/10/djangocon-testing-tutorial/"/>
   <updated>2011-08-10T00:00:00-07:00</updated>
   <id>http://davedash.com/2011/08/10/djangocon-testing-tutorial</id>
   <content type="html">&lt;div class=&quot;side&quot;&gt;
   &lt;img src=&quot;/static/images/2011/08/10/djangocon.png&quot;
        width=&quot;287&quot; height=&quot;184&quot;
        alt=&quot;DjangoCon 2011&quot; /&gt;
&lt;/div&gt;


&lt;p&gt;If you want to learn all you can about testing anything in your Django App, see
&lt;a href=&quot;http://djangocon.us/schedule/presentations/30/&quot;&gt;my tutorial&lt;/a&gt; at &lt;a href=&quot;http://djangocon.us/&quot;&gt;DjangoCon&lt;/a&gt;.
It's on September 5th, it'll be 3 hours
long and so far with seven sign ups it will be very hands-on.&lt;/p&gt;

&lt;p&gt;Here's what I think I will cover, but I may change this depending on what the
audience wants:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Testing issues

&lt;ul&gt;
&lt;li&gt;ask people to fill out etherpad with issues they've run into&lt;/li&gt;
&lt;li&gt;ask someone to rank them in order of complexity&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;List an outline of topics

&lt;ul&gt;
&lt;li&gt;post them on etherpad&lt;/li&gt;
&lt;li&gt;have people + them if they are interested&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Testing overview

&lt;ul&gt;
&lt;li&gt;We started in late 2009 early 2010&lt;/li&gt;
&lt;li&gt;Our largest project has 2500 tests&lt;/li&gt;
&lt;li&gt;Our next largest has 1100&lt;/li&gt;
&lt;li&gt;We have pretty good coverage&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;How testing works    in Django

&lt;ul&gt;
&lt;li&gt;I'm not 100% sure on this&lt;/li&gt;
&lt;li&gt;Test runner setups up a new database&lt;/li&gt;
&lt;li&gt;Test runner finds and runs tests&lt;/li&gt;
&lt;li&gt;Tests run class setup&lt;/li&gt;
&lt;li&gt;Test runs each test in a test case

&lt;ul&gt;
&lt;li&gt;Load fixtures&lt;/li&gt;
&lt;li&gt;Tests run setup&lt;/li&gt;
&lt;li&gt;Tests runs the test&lt;/li&gt;
&lt;li&gt;Tests runs teardown&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Tests run class Teardown&lt;/li&gt;
&lt;li&gt;You get an F if you're bad and a . if your not.&lt;/li&gt;
&lt;li&gt;Now that you know it, you can hack it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;How we've hacked testing

&lt;ul&gt;
&lt;li&gt;2500 tests is a lot&lt;/li&gt;
&lt;li&gt;We no longer recreate the database when you run the test suite&lt;/li&gt;
&lt;li&gt;In each test case we just load the fixtures once.&lt;/li&gt;
&lt;li&gt;We rearrange the tests so things with the same fixture set run together&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Testing tools that we use at Mozilla

&lt;ul&gt;
&lt;li&gt;nose/django_nose&lt;/li&gt;
&lt;li&gt;nose plugins

&lt;ul&gt;
&lt;li&gt;nicedots&lt;/li&gt;
&lt;li&gt;progressive&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;coverage

&lt;ul&gt;
&lt;li&gt;git + whatchangedpy&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Testing everything, no excuses

&lt;ul&gt;
&lt;li&gt;100% Coverage isn't important&lt;/li&gt;
&lt;li&gt;80% is nice&lt;/li&gt;
&lt;li&gt;Good coverage on tricky things is important&lt;/li&gt;
&lt;li&gt;Some coverage on everything is important&lt;/li&gt;
&lt;li&gt;External&lt;/li&gt;
&lt;li&gt;If you start depending on APIs, Search or different tools you need to be able to test for them.&lt;/li&gt;
&lt;li&gt;Writing these test cases will take less time than this tutorial&lt;/li&gt;
&lt;li&gt;It will save you so much headache in the future.&lt;/li&gt;
&lt;li&gt;The same headaches you save yourself by writing &quot;normal&quot; tests&lt;/li&gt;
&lt;li&gt;Mock easy things

&lt;ul&gt;
&lt;li&gt;use a decorator on any test/view that might use redis&lt;/li&gt;
&lt;li&gt;if redis isn't setup, use the mock client&lt;/li&gt;
&lt;li&gt;mock client doesn't support everything,

&lt;ul&gt;
&lt;li&gt;just what I need to get my tests running -&lt;/li&gt;
&lt;li&gt;feel free to extend it if you use it&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Testing Redis&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Setup/Teardown for complicated tools

&lt;ul&gt;
&lt;li&gt;Good for search and APIs&lt;/li&gt;
&lt;li&gt;Raise SkipTest (nose) if the developer doesn't want to run these tests&lt;/li&gt;
&lt;li&gt;Non realtime tools

&lt;ul&gt;
&lt;li&gt;Testing Sphinx search&lt;/li&gt;
&lt;li&gt;SetupClass

&lt;ul&gt;
&lt;li&gt;load fixtures&lt;/li&gt;
&lt;li&gt;run indexer&lt;/li&gt;
&lt;li&gt;run server&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sphinx server now available for all tests in your test case&lt;/li&gt;
&lt;li&gt;Teardown

&lt;ul&gt;
&lt;li&gt;stop server&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Real time tools

&lt;ul&gt;
&lt;li&gt;Nicer, data can be added in post_save signals or elsewhere in your app&lt;/li&gt;
&lt;li&gt;Testing LDAP

&lt;ul&gt;
&lt;li&gt;Setup

&lt;ul&gt;
&lt;li&gt;Remove LDAP files&lt;/li&gt;
&lt;li&gt;Load an ldif&lt;/li&gt;
&lt;li&gt;Start slapd&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Your code can now touch LDAP&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Testing ElasticSearch

&lt;ul&gt;
&lt;li&gt;We leave ES running all the time.&lt;/li&gt;
&lt;li&gt;Setup

&lt;ul&gt;
&lt;li&gt;Checks for ES support or SkipTest&lt;/li&gt;
&lt;li&gt;Deletes index&lt;/li&gt;
&lt;li&gt;Creates index&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;You can now read/write to ES&lt;/li&gt;
&lt;li&gt;Teardown

&lt;ul&gt;
&lt;li&gt;Delete's index&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Fixtures

&lt;ul&gt;
&lt;li&gt;Fixture Magic&lt;/li&gt;
&lt;li&gt;Model Maker&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;pitfalls

&lt;ul&gt;
&lt;li&gt;dates&lt;/li&gt;
&lt;li&gt;using PDB&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

</content>
 </entry>
 
 <entry>
   <title>DjangoCon wrapup</title>
   <link href="http://davedash.com/2009/09/15/djangocon-wrapup/"/>
   <updated>2009-09-15T00:00:00-07:00</updated>
   <id>http://davedash.com/2009/09/15/djangocon-wrapup</id>
   <content type="html">&lt;p&gt;I went to &lt;a href=&quot;http://djangocon.org/&quot;&gt;DjangoCon&lt;/a&gt; this past week for work.  Django is one of my favorite frameworks.  I dropped PHP and the symfony framework to learn python and Django and I haven't looked back.  I think for Mozilla's webdev team it would be the framework of choice.  We have 100s of sites in many frameworks, but not a lot of resuability.  Django apps are built to built to be reusable.  If you build correctly you don't have to refactor, it's already done.&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;Here's a collection of notes I collected through the conference.&lt;/p&gt;

&lt;h3&gt;Day one&lt;/h3&gt;

&lt;h4&gt;Keynote - Avi Bryant&lt;/h4&gt;

&lt;blockquote&gt;&lt;p&gt;Frameworks lock us into RDBMS = bad&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This keynote mentioned the limits of modern frameworks and modern web development.  Essentially frameworks are great for getting started, but as a site grows, the framework gets replaced little by little.  Sometimes it can get in the way - such as with limitation of database choices.&lt;/p&gt;

&lt;h4&gt;UR doing it wrong - James Bennet&lt;/h4&gt;

&lt;p&gt;James outlined a few key problems that many Django developers run into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;learning python as you go&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; doesn't work unless you know some programming upfront&lt;/li&gt;
&lt;li&gt; do the python tutorial&lt;/li&gt;
&lt;li&gt; read python in a nutshell or dive into python&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Things you should know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;subclasses&lt;/li&gt;
&lt;li&gt;super()&lt;/li&gt;
&lt;li&gt;slides went too fast... hopefully they'll be posted&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;All in all RTFM for python and Django :)&lt;/p&gt;

&lt;p&gt;Learn about other py packages... like twisted.  If Twisted Matrix was implemented in Ruby it would be advertised as the second coming of Christ.&lt;/p&gt;

&lt;p&gt;Bennet's Django App review smoketests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;installable via pip, easy_install or setup.py

&lt;ul&gt;
&lt;li&gt;read distutils-guide&lt;/li&gt;
&lt;li&gt;stay away from setuptools&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;have a README&lt;/li&gt;
&lt;li&gt;INSTALL file list deps&lt;/li&gt;
&lt;li&gt;Write DOCUMENTATION

&lt;ul&gt;
&lt;li&gt;use sphinx.pocoo.org&lt;/li&gt;
&lt;li&gt;store it in your package &lt;em&gt;and&lt;/em&gt; upload package docs&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;LICENSE (most Django apps use BSD)&lt;/li&gt;
&lt;li&gt;Write unit tests&lt;/li&gt;
&lt;li&gt;django-lint - to look over code (like pep8.py)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;pro-django is a decent book, but not written by Bennet.&lt;/p&gt;

&lt;h4&gt;Testing - Eric Holscher&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Django 1.1 encourages you to test by auto-creating tests.py.&lt;/li&gt;
&lt;li&gt;Support for:

&lt;ul&gt;
&lt;li&gt;Unittests&lt;/li&gt;
&lt;li&gt;Doctest&lt;/li&gt;
&lt;li&gt;Tests done in a db transacation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Test Driven Documentation (TDD + DDD)&lt;/li&gt;
&lt;li&gt;Doctest

&lt;ul&gt;
&lt;li&gt;easy&lt;/li&gt;
&lt;li&gt;can't use PDB&lt;/li&gt;
&lt;li&gt;Hides certain failures&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Unittests via Django TestCase

&lt;ul&gt;
&lt;li&gt;XUnit&lt;/li&gt;
&lt;li&gt;setup/Teardown&lt;/li&gt;
&lt;li&gt;adds db fixtures&lt;/li&gt;
&lt;li&gt;assertions&lt;/li&gt;
&lt;li&gt;mail testing/inbox testing&lt;/li&gt;
&lt;li&gt;url testing&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;TestCase

&lt;ul&gt;
&lt;li&gt;Browserless Request/Response testing&lt;/li&gt;
&lt;li&gt;Similar to sfBrowser in symfony&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Google Summer of Code (for Django 1.2)

&lt;ul&gt;
&lt;li&gt;Coverage reports!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;I need to learn PDB&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;Deploying Django -&lt;/h4&gt;

&lt;p&gt;Run mod_wsgi in daemon mode.&lt;/p&gt;

&lt;h3&gt;Day 2&lt;/h3&gt;

&lt;h4&gt;&lt;a href=&quot;http://blog.ianbicking.org/2009/09/10/a-new-self-definition-for-foss/&quot;&gt;Keynote - Ian Bicking&lt;/a&gt;&lt;/h4&gt;

&lt;p&gt;GNU Manifest:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt; I consider that the golden rule requires that if I like a program I must share it with other people who like it. Software sellers want to divide the users and conquer them, making each user agree not to share with others. I refuse to break solidarity with other users in this way. I cannot in good conscience sign a nondisclosure agreement or a software license agreement. ...&lt;/p&gt;

&lt;p&gt;So that I can continue to use computers without dishonor, I have decided to put together a sufficient body of free software so that I will be able to get along without any software that is not free.&lt;/p&gt;&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;GNU manifesto was the idea of sharing software amongst friends&lt;/li&gt;
&lt;li&gt;GNU has purpose - BSD, etc is just a rule - free to share&lt;/li&gt;
&lt;li&gt;Free is not just the absense of copyright&lt;/li&gt;
&lt;li&gt;Free is not a reaction to existing rules, but a golden rule&lt;/li&gt;
&lt;li&gt;Not just a fight against MS&lt;/li&gt;
&lt;li&gt;Need to find morality (the why) within the practical (the law, or what you can do)&lt;/li&gt;
&lt;li&gt;Open sourcing closed source code isn't building open source&lt;/li&gt;
&lt;li&gt;This might apply to Mozilla... as webkit has taken off more than Gecko.&lt;/li&gt;
&lt;li&gt;Open source is person to person not company to company - despite sponsorship.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Using Django in Non-standard ways - Eric Florenzano&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Django loosely coupled&lt;/li&gt;
&lt;li&gt;Replace templating with Jinja 2&lt;/li&gt;
&lt;li&gt;Copy Django methods into djangoext to easily customize Django behavior&lt;/li&gt;
&lt;li&gt;Not using django.contrib.auth

&lt;ul&gt;
&lt;li&gt;reasons: writing a fb app - no auth needed&lt;/li&gt;
&lt;li&gt;no shoehorning needed - saves time - less overhead&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;skip the orm?

&lt;ul&gt;
&lt;li&gt;legacy dbs&lt;/li&gt;
&lt;li&gt;non standard or db (or non-relational database)&lt;/li&gt;
&lt;li&gt;no database&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;wsgi middleware has some cool shit

&lt;ul&gt;
&lt;li&gt;repose.bitblt: autoscales images&lt;/li&gt;
&lt;li&gt;repose.squeeze: will concat js/css on the fly based on statistical analysis&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;non standard Django based apps

&lt;ul&gt;
&lt;li&gt;YARDBird - IRCBot framework&lt;/li&gt;
&lt;li&gt;djng micro framework&lt;/li&gt;
&lt;li&gt;Jngo- singlefile cms&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;using admin in a nonstandard way is hard/impossible coupled with ORM and auth&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;Real-time web and other Buzzwords - Chris Wanstrath&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;more than just getting your rss feeds faster&lt;/li&gt;
&lt;li&gt;push vs. pull&lt;/li&gt;
&lt;li&gt;1 persisting connection vs polling&lt;/li&gt;
&lt;li&gt;comet/flash-xml/or html5 web socket&lt;/li&gt;
&lt;li&gt;orbitted - open source python comet server&lt;/li&gt;
&lt;li&gt;zeddicus - does the business logic&lt;/li&gt;
&lt;li&gt;orbitted has its own js libs - its a simple port/socket thing for your server code to deal with - not request/response.&lt;/li&gt;
&lt;li&gt;all connections are persisting browser/orbitted orbitted/zeddicus&lt;/li&gt;
&lt;li&gt;You can even use orbitted to connect straight to IRC and write a client in JS&lt;/li&gt;
&lt;li&gt;Jetty also is good for comet&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Also:
* see webhooks
* see pubsubhubub&lt;/p&gt;

&lt;h4&gt;&lt;a href=&quot;http://www.slideshare.net/nowells/djangocon-09-presentation-pluggable-applications&quot;&gt;Pluggable, Reusable Django Apps: A Use Case and Proposed Solution&lt;/a&gt; - Shawn Rider and Nowell Strite&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;PBS moved from perl to django - build a lot of reusable apps&lt;/li&gt;
&lt;li&gt;convincing your superiors

&lt;ul&gt;
&lt;li&gt;need a good story -&lt;/li&gt;
&lt;li&gt;existing base of python helped&lt;/li&gt;
&lt;li&gt;With Django easy to do things right without doing things slow&lt;/li&gt;
&lt;li&gt;be really good...&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;built a lot of apps to be very reusable, and pluggable based on requirements PBS had&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Day 3&lt;/h3&gt;

&lt;h4&gt;&lt;a href=&quot;http://www.slideshare.net/twleung/djangocon-2009-keynote&quot;&gt;Keynote&lt;/a&gt; - Ted Leung - Sun&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Django jobs are a growing market&lt;/li&gt;
&lt;li&gt;Preferred by startups&lt;/li&gt;
&lt;li&gt;Bespin/wave - cool&lt;/li&gt;
&lt;li&gt;APIs are big... still&lt;/li&gt;
&lt;li&gt;Physically impossible to create purely server-side interactions that are usable enough - rely on rest/comet/ajax/etc to bridge gap&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;&lt;a href=&quot;http://immike.net/files/scaling_django_dc09.pdf&quot;&gt;Scaling Django&lt;/a&gt; Mike Malone&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;MM from Pownce (now sixapart)&lt;/li&gt;
&lt;li&gt;Slides started out as &quot;Building Scalable Web Applications&quot;&lt;/li&gt;
&lt;li&gt;Django didn't get in the way too much when it came to scaling&lt;/li&gt;
&lt;li&gt;Django had tons of caching support&lt;/li&gt;
&lt;li&gt;Cached objects by hand (memcached) and object ID lists&lt;/li&gt;
&lt;li&gt;Use memache for sessions too&lt;/li&gt;
&lt;li&gt;use signals to signal cache invalidation&lt;/li&gt;
&lt;li&gt;race conditions...&lt;/li&gt;
&lt;li&gt;Queue shit... gearman, rabbit mq, etc.&lt;/li&gt;
&lt;li&gt;Memecached incr/decr operators are awesome&lt;/li&gt;
&lt;li&gt;See gh/mmalone/django-caching&lt;/li&gt;
&lt;li&gt;See gh:.../django-multidb&lt;/li&gt;
&lt;li&gt;to combat slavelag use a memcache key to alternate between master or slave&lt;/li&gt;
&lt;/ul&gt;


&lt;h4&gt;&lt;a href=&quot;http://heisel.org/blog/2009/09/11/gearman/&quot;&gt;Gearman - working later&lt;/a&gt; - Chris Heisel&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Gearman - a work later alt to rabbit mq&lt;/li&gt;
&lt;li&gt;Makes the most sense for something like cesium, with a bazillion worker &lt;strike&gt;bees&lt;/strike&gt; foxes feeding off a single queue&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Also at the con, I talked to someone about rebuilding large apps... and they took a PHP app and used URL rewriting to and a lot of PHP/Python glue code to build a seamless transitory app.  The rule is, all new functionality was done up in python while the old app was in maintenance mode.&lt;/p&gt;

&lt;p&gt;More talks &lt;a href=&quot;http://djangocon.pbworks.com/Slides&quot;&gt;here&lt;/a&gt;!&lt;/p&gt;
</content>
 </entry>
 

</feed>

