[Gabriel Falcão] Introducing Sponge, a python web framework aimed on testing

Sponge first prage

Some time ago, a friend of mine created a cherrypy-based continuous integration application, we both work with Django, but we think that its stack is too big for simple web projects, specially when we do not need to access SQL databases.

More on Django

In adition, I think that Django-powered applications are hard to make unit tests, mostly related to the fact that models, templates and other django helpers need the DJANGO_SETTINGS_MODULE environment variable set, which turn its tests wired.

We have created a few patterns to make Django projects unit-testable, but it is for another post :)

Are you trying to say that Django is not a good framework ?

Nope! I work with Django, and I just LOVE Django, that is a great framework. Its models, forms, and everything else are awesome, and help me to write web applications without much effort, thus keeping high level of quality.

So, why did you create another framework ?

As I’ve just said some posts ago, I really enjoy agile, and I use to write simple web applications that does not demand the whole Django stack, and I need to have agility to write my tests.

CherryPy is a good solution for me, I don’t want another huge-ish framework, even if its based on cherrypy. I just need a few helpers functions, and a pattern to follow.

Idealizing sponge

Bernardo and me wrote a few web applications with cherrypy, and always focusing in TDD, we needed to create some helper classes to cherrypy. Sometime after, we figured out that those helpers could be grouped in a simple library, or a kind of tiny framework.

I started some mashups, and Sponge has been developed.

The name comes from the fact that a sponge can be used to dry stuff. We like the concept of DRY, hence the name :)

Sponge has been developed with TDD, but that is not all.

I’m trying to keep 100% of code coverage in both unit + functional tests, at minimum. It’s because 100% of coverage does not assure that the code works. Lines of code can be covered with some tests, but the same lines can have one or more different behaviours that won’t be found with 100% of coverage.

Principles

  • Help and incentivate developer to write unit and functional tests
  • Less friction as possible
  • Be simple to configure
  • Be simple to deploy
  • Be 100% testable, specially with unit tests
  • Provide pretty URLS through a rails-like syntax
  • Be as most compliant as possible, with package-systems, such as APT
  • Free software (LGPL-3)
  • Comes with jQuery javascript library and 960 grid system
  • Fun to use :)

Hands on!

Installing

If you are using Debian Unstable, just run:

sudo aptitude install python-sponge

If not, you will need, unfortunately, to use setuptools:

In this case, just grab the bleeding edge version through git:

git clone git://github.com/gabrielfalcao/sponge.git

Or just the latest stable relase:

Sponge 0.3.1

Extract, if needed, and run:

sudo python setup.py install

Tutorial

Sponge comes with a simple tutorial within its documentation, but you can access it online