1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

[soc2010/app-loading] update get_app/get_apps tests

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13811 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Arthur Koziel 2010-09-12 21:52:56 +00:00
parent 3273307490
commit c9b188c4ec
2 changed files with 40 additions and 32 deletions

View File

@ -189,7 +189,7 @@ class AppCache(object):
return self.loaded return self.loaded
def get_apps(self): def get_apps(self):
"Returns a list of all installed modules that contain models." "Returns a list of all models modules."
self._populate() self._populate()
return [app.models_module for app in self.app_instances\ return [app.models_module for app in self.app_instances\
if hasattr(app, 'models_module')] if hasattr(app, 'models_module')]

View File

@ -84,23 +84,31 @@ class AppCacheReadyTests(AppCacheTestCase):
class GetAppsTests(AppCacheTestCase): class GetAppsTests(AppCacheTestCase):
"""Tests for the get_apps function""" """Tests for the get_apps function"""
def test_get_apps(self): def test_app_classes(self):
"""Test that the correct models modules are returned""" """
settings.INSTALLED_APPS = ('django.contrib.sites', Test that the correct models modules are returned for apps installed
'django.contrib.contenttypes', via the APP_CLASSES setting
'django.contrib.auth', """
'django.contrib.flatpages',) settings.APP_CLASSES = ('model_app.apps.MyApp',)
apps = cache.get_apps() 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.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.assertTrue(cache.app_cache_ready())
self.assertEquals(apps[0].__name__, 'model_app.models')
def test_empty_models(self): 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.assertEqual(cache.get_apps(), [])
self.assertTrue(cache.app_cache_ready()) self.assertTrue(cache.app_cache_ready())
@ -116,13 +124,23 @@ class GetAppsTests(AppCacheTestCase):
class GetAppTests(AppCacheTestCase): class GetAppTests(AppCacheTestCase):
"""Tests for the get_app function""" """Tests for the get_app function"""
def test_get_app(self): def test_app_classes(self):
"""Test that the correct module is returned""" """
settings.INSTALLED_APPS = ('django.contrib.contenttypes', Test that the correct module is returned when the app was installed
'django.contrib.auth',) via the APP_CLASSES setting
module = cache.get_app('auth') """
self.assertTrue(module, 'django.contrib.auth.models') settings.APP_CLASSES = ('model_app.apps.MyApp',)
self.assertTrue(cache.app_cache_ready()) 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): def test_not_found_exception(self):
""" """
@ -130,7 +148,7 @@ class GetAppTests(AppCacheTestCase):
could not be found could not be found
""" """
self.assertRaises(ImproperlyConfigured, cache.get_app, self.assertRaises(ImproperlyConfigured, cache.get_app,
'django.contrib.auth') 'notarealapp')
self.assertTrue(cache.app_cache_ready()) self.assertTrue(cache.app_cache_ready())
def test_emptyOK(self): def test_emptyOK(self):
@ -143,16 +161,6 @@ class GetAppTests(AppCacheTestCase):
self.failUnless(module is None) self.failUnless(module is None)
self.assertTrue(cache.app_cache_ready()) 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): class GetAppErrorsTests(AppCacheTestCase):
"""Tests for the get_app_errors function""" """Tests for the get_app_errors function"""