Testing in TurboGears

I finally got time to continue on my GTD application. I wrote unit tests for all controller methods.

My first idea was to include a mock framework so I wouldn’t need to execute external logic in my tests, but then I realized that would be overkill. I’m using an in-memory database (SQLite) and executing the whole application stack (except for javascript). All tests runs within 10 seconds, which is acceptable.

TurboGears includes Nose, which is a test discovery and running process for unittest. Typing “nosetests” on the command line runs all tests in the project.

I’ve decided to later use AJAX in my application, and a good way to test the whole stack including javascript is to test with Selenium. I’ll leave this for later.

It just works

I have never felt such a joy developing a web application. I get into flow more often. Things just work and I rarely show the ‘what the heck happened’-face.


from turbogears import testutil
from turbogtd.controllers import Root
from turbogtd import model
import cherrypy

cherrypy.root = Root()
cherrypy.config.update({"sqlalchemy.dburi" : "sqlite:///:memory:"})
cherrypy.config.update({'sessionFilter.on': True})

class BaseTest:
  def setUp(self):
    # a 'dummy' call to initialize the database
  def tearDown(self):


class TestProject(BaseTest):
  def test_create(self):
    page = cherrypy.response.body[0]
    assert 'Project added' in page, "text not found. page: " +page
    project = Project.get(1)
    assert 'title' == project.title, "error in title: " +project.title
    assert 'notes' == project.notes, "error in notes: " +project.notes

4 Responses to Testing in TurboGears

  1. Web directory Annuaire de referencement des sites web…


  2. continuously i used to read smaller posts which as well clear their motive, and that is also
    happening with this post which I am reading at this time.

  3. Asking questions are genuinely fastidious thing if you are not understanding something entirely, however this post gives good
    understanding even.

  4. good advice says:

    It’s truly a nice and helpful piece of info. I’m
    happy that you just shared this helpful information with us.
    Please keep us up to date like this. Thanks for sharing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: