1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +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
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')]

View File

@ -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.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.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):
"""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"""