diff options
-rw-r--r-- | django/core/apps.py | 2 | ||||
-rw-r--r-- | tests/appcachetests/runtests.py | 70 |
2 files changed, 40 insertions, 32 deletions
diff --git a/django/core/apps.py b/django/core/apps.py index df8355ca12..4a9be1893a 100644 --- a/django/core/apps.py +++ b/django/core/apps.py @@ -189,7 +189,7 @@ class AppCache(object): return self.loaded def get_apps(self): - "Returns a list of all installed modules that contain models." + "Returns a list of all models modules." self._populate() return [app.models_module for app in self.app_instances\ if hasattr(app, 'models_module')] diff --git a/tests/appcachetests/runtests.py b/tests/appcachetests/runtests.py index 2b2821f6a8..ba98dac1ed 100644 --- a/tests/appcachetests/runtests.py +++ b/tests/appcachetests/runtests.py @@ -84,23 +84,31 @@ class AppCacheReadyTests(AppCacheTestCase): class GetAppsTests(AppCacheTestCase): """Tests for the get_apps function""" - def test_get_apps(self): - """Test that the correct models modules are returned""" - settings.INSTALLED_APPS = ('django.contrib.sites', - 'django.contrib.contenttypes', - 'django.contrib.auth', - 'django.contrib.flatpages',) + def test_app_classes(self): + """ + Test that the correct models modules are returned for apps installed + via the APP_CLASSES setting + """ + settings.APP_CLASSES = ('model_app.apps.MyApp',) + apps = cache.get_apps() + self.assertTrue(cache.app_cache_ready()) + self.assertEquals(apps[0].__name__, 'model_app.othermodels') + + def test_installed_apps(self): + """ + Test that the correct models modules are returned for apps installed + via the INSTALLED_APPS setting + """ + settings.INSTALLED_APPS = ('model_app',) apps = cache.get_apps() - self.assertEqual(len(apps), 4) - self.assertTrue(apps[0], 'django.contrib.auth.models') - self.assertTrue(apps[1], 'django.contrib.flatpages.models') - self.assertTrue(apps[2], 'django.contrib.sites.models') - self.assertTrue(apps[3], 'django.contrib.contenttypes.models') self.assertTrue(cache.app_cache_ready()) + self.assertEquals(apps[0].__name__, 'model_app.models') def test_empty_models(self): - """Test that modules that don't contain models are not returned""" - settings.INSTALLED_APPS = ('django.contrib.csrf',) + """ + Test that modules that don't contain models are not returned + """ + settings.INSTALLED_APPS = ('nomodel_app',) self.assertEqual(cache.get_apps(), []) self.assertTrue(cache.app_cache_ready()) @@ -116,13 +124,23 @@ class GetAppsTests(AppCacheTestCase): class GetAppTests(AppCacheTestCase): """Tests for the get_app function""" - def test_get_app(self): - """Test that the correct module is returned""" - settings.INSTALLED_APPS = ('django.contrib.contenttypes', - 'django.contrib.auth',) - module = cache.get_app('auth') - self.assertTrue(module, 'django.contrib.auth.models') - self.assertTrue(cache.app_cache_ready()) + def test_app_classes(self): + """ + Test that the correct module is returned when the app was installed + via the APP_CLASSES setting + """ + settings.APP_CLASSES = ('model_app.apps.MyApp',) + rv = cache.get_app('model_app') + self.assertEquals(rv.__name__, 'model_app.othermodels') + + def test_installed_apps(self): + """ + Test that the correct module is returned when the app was installed + via the INSTALLED_APPS setting + """ + settings.INSTALLED_APPS = ('model_app',) + rv = cache.get_app('model_app') + self.assertEquals(rv.__name__, 'model_app.models') def test_not_found_exception(self): """ @@ -130,7 +148,7 @@ class GetAppTests(AppCacheTestCase): could not be found """ self.assertRaises(ImproperlyConfigured, cache.get_app, - 'django.contrib.auth') + 'notarealapp') self.assertTrue(cache.app_cache_ready()) def test_emptyOK(self): @@ -143,16 +161,6 @@ class GetAppTests(AppCacheTestCase): self.failUnless(module is None) self.assertTrue(cache.app_cache_ready()) - def test_load_app_modules(self): - """ - Test that only apps that are listed in the INSTALLED_APPS setting - are searched (unlike the get_apps function, which also searches - apps that are loaded via load_app) - """ - cache.load_app('django.contrib.sites') - self.assertRaises(ImproperlyConfigured, cache.get_app, 'sites') - self.assertTrue(cache.app_cache_ready()) - class GetAppErrorsTests(AppCacheTestCase): """Tests for the get_app_errors function""" |