I`m looking into new ways to unittest my django code. The reason for this is that I find it cumbersome to always have to set up a real database, allthough using sqlite and :memory: makes it relatively easy, I was wondering if anybody has done it using mock/fake objects like Fudge? Writing unittests that involves using the django orm is a hassle. I`ve included my way of doing this at the bottom and would like comments on how to improve. Running it like this means it cannot be automated because the script asks for confirmation about creating a super-user.
http://farmdev.com/projects/fudge/using-fudge.html#fake-objects-without-patches-dependency-injection My hackish way of testing when the django orm is used: import unittest def configure(appName): from django.conf import settings, global_settings _INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.humanize', appName, ) the_module = __import__(appName) settings.configure(default_settings=global_settings, INSTALLED_APPS = _INSTALLED_APPS, DATABASE_NAME=':memory:', DATABASE_ENGINE='sqlite3', SETTINGS_MODULE = appName, ) from django import db from django.core.management import call_command reload(db) call_command('syncdb') configure('someapp') # someapp is a package in the python path from django.conf import settings from django.test.utils import setup_test_environment, teardown_test_environment class testSomeApp(unittest.TestCase): def setUp(self): setup_test_environment() def tearDown(self): teardown_test_environment() if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(testSomeApp) unittest.TextTestRunner(verbosity=2).run(suite) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

