#7835: Provide the ability for model definitions that are only availably during testing ----------------------------------------+----------------------------------- Reporter: russellm | Owner: kkubasik Status: new | Milestone: Component: Testing framework | Version: SVN Resolution: | Keywords: feature test models Stage: Accepted | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | ----------------------------------------+----------------------------------- Comment (by julien):
Thanks for this. I thought I'd also remind here the hack (originally posted at http://groups.google.com/group/django- users/browse_thread/thread/559aa0a2d074a7b5) which I've successfully used in many applications, and which is reasonably succinct in terms of lines of code. This is in fact what served as a model for the patch I've posted in this ticket. Maybe that will be useful to someone until this ticket eventually gets fixed. Sample file structure: {{{ myapp/ tests/ fakeapp/ __init__.py models.py __init__.py models.py views.py urls.py }}} Here is the testing code (located in `myapp/tests/__init__.py`): {{{ import sys from django.test import TestCase from django.conf import settings from django.core.management import call_command from django.db.models.loading import load_app from fakeapp.models import FakeItem class TestMyApp(TestCase): def setUp(self): self.old_INSTALLED_APPS = settings.INSTALLED_APPS settings.INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'myapp', 'myapp.tests.fakeapp', ) load_app('myapp.tests.fakeapp') call_command('syncdb', verbosity=0, interactive=False) #Create tables for fakeapp def tearDown(self): settings.INSTALLED_APPS = self.old_INSTALLED_APPS def test_blah(self): item = FakeItem.objects.create(name="blah") #Do some testing here... }}} -- Ticket URL: <http://code.djangoproject.com/ticket/7835#comment:21> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---