Skip to content

Commit 81dc507

Browse files
committed
[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
1 parent 4674415 commit 81dc507

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

django/core/apps.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class AppCache(object):
4040
# List of App instances
4141
app_instances = [],
4242

43+
# Normalized list of INSTALLED_APPS
44+
# This stores the module name of settings.INSTALLED_APPS
45+
# e.g. 'django.contrib.auth' for 'django.contrib.auth.AuthApp'
46+
installed_apps = [],
47+
4348
# Mapping of app_labels to a dictionary of model names to model code.
4449
app_models = SortedDict(),
4550

@@ -105,11 +110,13 @@ def load_app(self, app_name, can_postpone=False):
105110
app_instance = self.find_app(app_name)
106111
if not app_instance:
107112
if '.' in app_name:
113+
# get the app label from the full path
108114
app_instance_name = app_name.rsplit('.', 1)[1]
109115
else:
110116
app_instance_name = app_name
111117
app_instance = app_class(app_instance_name)
112118
self.app_instances.append(app_instance)
119+
self.installed_apps.append(app_name)
113120

114121
# check if the app instance specifies a path to models
115122
# if not, we use the models.py file from the package dir

tests/appcachetests/runtests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def tearDown(self):
4242
# because thread.RLock is un(deep)copyable
4343
cache.app_models = SortedDict()
4444
cache.app_instances = []
45+
cache.installed_apps = []
4546

4647
cache.loaded = False
4748
cache.handled = {}
@@ -272,6 +273,15 @@ def test_importerror(self):
272273
"""
273274
self.assertRaises(ImportError, cache.load_app, 'garageland')
274275

276+
def test_installed_apps(self):
277+
"""
278+
Test that the installed_apps attribute is populated correctly
279+
"""
280+
settings.INSTALLED_APPS = ('model_app', 'nomodel_app.MyApp',)
281+
# populate cache
282+
cache.get_app_errors()
283+
self.assertEqual(cache.installed_apps, ['model_app', 'nomodel_app',])
284+
275285
class RegisterModelsTests(AppCacheTestCase):
276286
"""Tests for the register_models function"""
277287

0 commit comments

Comments
 (0)