mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Refs #2333 - Added model test for the test Client.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3708 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d043200077
commit
826b9ff5e5
10 changed files with 198 additions and 2 deletions
|
@ -6,6 +6,7 @@ import unittest
|
|||
MODEL_TESTS_DIR_NAME = 'modeltests'
|
||||
REGRESSION_TESTS_DIR_NAME = 'regressiontests'
|
||||
TEST_DATABASE_NAME = 'django_test_db'
|
||||
TEST_TEMPLATE_DIR = 'templates'
|
||||
|
||||
MODEL_TEST_DIR = os.path.join(os.path.dirname(__file__), MODEL_TESTS_DIR_NAME)
|
||||
REGRESSION_TEST_DIR = os.path.join(os.path.dirname(__file__), REGRESSION_TESTS_DIR_NAME)
|
||||
|
@ -71,17 +72,23 @@ class InvalidModelTestCase(unittest.TestCase):
|
|||
def django_tests(verbosity, tests_to_run):
|
||||
from django.conf import settings
|
||||
from django.db.models.loading import get_apps, load_app
|
||||
|
||||
old_installed_apps = settings.INSTALLED_APPS
|
||||
old_test_database_name = settings.TEST_DATABASE_NAME
|
||||
old_root_urlconf = settings.ROOT_URLCONF
|
||||
old_template_dirs = settings.TEMPLATE_DIRS
|
||||
|
||||
# Redirect some settings for the duration of these tests
|
||||
settings.TEST_DATABASE_NAME = TEST_DATABASE_NAME
|
||||
settings.INSTALLED_APPS = ALWAYS_INSTALLED_APPS
|
||||
|
||||
settings.ROOT_URLCONF = 'urls'
|
||||
settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), TEST_TEMPLATE_DIR),)
|
||||
|
||||
# load all the ALWAYS_INSTALLED_APPS
|
||||
get_apps()
|
||||
|
||||
test_models = []
|
||||
# Load all the test model apps
|
||||
test_models = []
|
||||
for model_dir, model_name in get_test_models():
|
||||
model_label = '.'.join([model_dir, model_name])
|
||||
try:
|
||||
|
@ -112,6 +119,9 @@ def django_tests(verbosity, tests_to_run):
|
|||
# Restore the old settings
|
||||
settings.INSTALLED_APPS = old_installed_apps
|
||||
settings.TESTS_DATABASE_NAME = old_test_database_name
|
||||
settings.ROOT_URLCONF = old_root_urlconf
|
||||
settings.TEMPLATE_DIRS = old_template_dirs
|
||||
|
||||
if __name__ == "__main__":
|
||||
from optparse import OptionParser
|
||||
usage = "%prog [options] [model model model ...]"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue