#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 bmathieu):
The following is not a proposed changed since it is a hack, but here is
what I have done to have models during testing:
In my app I have a folder "tests". It contains "testingmodels.py". In my
test case (defined in tests/__init__.py) I have redefined _pre_setup()
like this:
{{{
import sys
import new
from django.db.models import loading
from django.core.management import call_command
from django.test import TestCase
from . import testingmodels
class MyTestCase(TestCase)
def _pre_setup(self):
# register tests models
# we'll fake an app named 'my_test_app'
module = new.module('my_test_app')
module.__file__ = __file__ # somewhere django looks at __file__.
Feed it.
module.models = testingmodels
testingmodels.__name__ = 'my_test_app.models'
sys.modules['my_test_app'] = module
# register fake app in django and create DB models
from django.conf import settings
settings.INSTALLED_APPS += ('my_test_app',)
loading.load_app('my_test_app')
call_command('syncdb', verbosity=0, interactive=False)
return super(MyTestCase, self)._pre_setup()
}}}
Note: due to django constraints the app must contains an empty
"models.py".
I'm using this with success under django 1.0.2. I can't say I would
recommend it as a general solution, but maybe it can help or inspire
someone?
--
Ticket URL: <http://code.djangoproject.com/ticket/7835#comment:20>
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 [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-updates?hl=en
-~----------~----~----~----~------~----~------~--~---