mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[soc2010/app-loading] store normalized version of INSTALLED_APPS in appcache
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13573 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
467441587c
commit
81dc507963
@ -40,6 +40,11 @@ class AppCache(object):
|
|||||||
# List of App instances
|
# List of App instances
|
||||||
app_instances = [],
|
app_instances = [],
|
||||||
|
|
||||||
|
# Normalized list of INSTALLED_APPS
|
||||||
|
# This stores the module name of settings.INSTALLED_APPS
|
||||||
|
# e.g. 'django.contrib.auth' for 'django.contrib.auth.AuthApp'
|
||||||
|
installed_apps = [],
|
||||||
|
|
||||||
# Mapping of app_labels to a dictionary of model names to model code.
|
# Mapping of app_labels to a dictionary of model names to model code.
|
||||||
app_models = SortedDict(),
|
app_models = SortedDict(),
|
||||||
|
|
||||||
@ -105,11 +110,13 @@ class AppCache(object):
|
|||||||
app_instance = self.find_app(app_name)
|
app_instance = self.find_app(app_name)
|
||||||
if not app_instance:
|
if not app_instance:
|
||||||
if '.' in app_name:
|
if '.' in app_name:
|
||||||
|
# get the app label from the full path
|
||||||
app_instance_name = app_name.rsplit('.', 1)[1]
|
app_instance_name = app_name.rsplit('.', 1)[1]
|
||||||
else:
|
else:
|
||||||
app_instance_name = app_name
|
app_instance_name = app_name
|
||||||
app_instance = app_class(app_instance_name)
|
app_instance = app_class(app_instance_name)
|
||||||
self.app_instances.append(app_instance)
|
self.app_instances.append(app_instance)
|
||||||
|
self.installed_apps.append(app_name)
|
||||||
|
|
||||||
# check if the app instance specifies a path to models
|
# check if the app instance specifies a path to models
|
||||||
# if not, we use the models.py file from the package dir
|
# if not, we use the models.py file from the package dir
|
||||||
|
@ -42,6 +42,7 @@ class AppCacheTestCase(unittest.TestCase):
|
|||||||
# because thread.RLock is un(deep)copyable
|
# because thread.RLock is un(deep)copyable
|
||||||
cache.app_models = SortedDict()
|
cache.app_models = SortedDict()
|
||||||
cache.app_instances = []
|
cache.app_instances = []
|
||||||
|
cache.installed_apps = []
|
||||||
|
|
||||||
cache.loaded = False
|
cache.loaded = False
|
||||||
cache.handled = {}
|
cache.handled = {}
|
||||||
@ -272,6 +273,15 @@ class LoadAppTests(AppCacheTestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertRaises(ImportError, cache.load_app, 'garageland')
|
self.assertRaises(ImportError, cache.load_app, 'garageland')
|
||||||
|
|
||||||
|
def test_installed_apps(self):
|
||||||
|
"""
|
||||||
|
Test that the installed_apps attribute is populated correctly
|
||||||
|
"""
|
||||||
|
settings.INSTALLED_APPS = ('model_app', 'nomodel_app.MyApp',)
|
||||||
|
# populate cache
|
||||||
|
cache.get_app_errors()
|
||||||
|
self.assertEqual(cache.installed_apps, ['model_app', 'nomodel_app',])
|
||||||
|
|
||||||
class RegisterModelsTests(AppCacheTestCase):
|
class RegisterModelsTests(AppCacheTestCase):
|
||||||
"""Tests for the register_models function"""
|
"""Tests for the register_models function"""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user