Doing TDD in Django
So, as part of this link ranking website project, I’m trying to do TDD In Django, I’ve got a nice development setup with virtualenv with django installed locally in my development folder. My apps are added to sys.path through the PYTHONPATH environment variable and I set the DJANGO_SETTINGS_MODULE variable depending on what I’m developing at the moment. I also used easy_install to get the latest version of nose, my favorite test runner.
So, the first thing I do is write a simple smoke test to make sure that my application is setup correctly:
from django.test import TestCase
class IndexFunctionalTests(TestCase):
def testIndexReturns200(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
This requires the DJANGO_SETTINGS_MODULE environment variable to be set. I copied what django-tagging does, and have a tiny project settings.py specified within the tests folder. I also set up the urls.py file in the linkranking directory and reference it in tests.settings file.
This psuedo project will need to be expanded once I start developing templates. And I’m still running into problem #8358. I really should try this patch to see if it fixes it.
So far using nose with Django is pretty straightforward, if I use the Django TestCase object for all the database and client related stuff.
December 27th, 2008 at 12:34 am
[...] Saved by jwk2004 on Thu 25-12-2008 Why TDD is Unpopular Saved by sjrccepitech on Wed 17-12-2008 Doing TDD in Django Saved by bretw on Fri 12-12-2008 TDD from the customers point of view Saved by Wildarms7000 on [...]