Lab 4: Testing your TurboGears application

Due:  Tuesday, October 9, via Subversion and a quick demo (see turning in your work, below).

Goals:

Collaboration: Please continue working with your team from Lab 3. (Don't worry, you will have your project teams soon.) You may obtain help from anyone you wish, but you should clearly document that help. You need turn in only one assignment per team.

Contents:

Introduction

This lab is intended to give you practice testing a TurboGears application.  Ideally, we would have written these tests as we made changes to the application, but I know some of you are already finished or close to finished with Lab 3(b).

Some things to think about (which I may ask you about, hint hint):

I expect you to complete Lab 3(b) and the steps on this page, but I believe it won't matter which order you do them in. Please consult me if you run into snags.

Getting started

Go to your working directory for this project.  Type
	ls beadgallery/tests
You should see that there are some tests already here.  Try running them using
	nosetests -v

What happens? Why?

Comment out the contents of beadgallery/tests/test_controllers.py. Uncomment the contents of beadgallery/tests/test_model.py.

Now try running nosetests -v again. What happens? At this point, all of the tests should succeed; try to fix any problems you run into.

Testing the model

In beadgallery/tests/test_model.py, add a new TestItem class, which should inherit from testutil.DBTest.

Just like in the TestUser class, the class should specify which model it is testing and provide tests of creating and retrieving instances of the model. Here are some things you should think about testing in the TestItem class:
Be sure to check in your tests periodically. You will also find you need to fix at least one subtle bug in the starter code I gave you. (Feel free to ask me when you think you've found this.)

Testing the controllers

Testing the controllers is a big job: mainly because we want to test how the site works differently for administrators and non-administrators.  For this reason, I've given you some code to get you started.

Download test_controllers.py and copy it over the default version of this file in the beadgallery/tests directory. Commit the new version.

Read over the tests in beadgallery/tests/test_controllers.py. Some things to think about:

For the tests to run properly, you will also need to add some things to your test.cfg file in the working directory. The contents of this file should be as follows:

# You can place test-specific configuration options here (like test db uri, etc)
sqlobject.dburi = "sqlite:///:memory:"
beadgallery.images = "./test-images"
visit.on = True
identity.on = True
Make these additions and commit the file.

Now try running the tests.  What happens?

Review beadgallery/tests/test_controllers.py, focusing on any tests that failed. If necessary, change your controller code so the tests pass, or comment out the tests if you've not yet implemented the code it is testing.

Note that some controller procedures are never tested. Let's fix that to the extent possible:

Turning in your work

Remember to check your code into Subversion. Remember to complete Lab 3(b) (to the extent that you can) as well as the tests described here.

Then, come show me what you did! Sign up for a 15-minute office hour slot on Tuesday, October 9. If you can't come to my office hours, make an appointment with me for some other time this week. Your team should plan to all meet with me together.

You'll give me a demo, I'll ask you a few questions, and you'll have a chance to ask me any further questions.

I'll also look at the tests you wrote by checking them out of Subversion.


Janet Davis (davisjan@cs.grinnell.edu)

Created October 5, 2007
Last revised October 5, 2007