8000 [soc2010/app-loading] update get_app/get_apps tests · alex-python/django@c9b188c · GitHub
[go: up one dir, main page]

Skip to content

Commit c9b188c

Browse files
committed
[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
1 parent 3273307 commit c9b188c

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

django/core/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def app_cache_ready(self):
189189
return self.loaded
190190

191191
def get_apps(self):
192-
"Returns a list of all installed modules that contain models."
192+
"Returns a list of all models modules."
193193
self._populate()
194194
return [app.models_module for app in self.app_instances\
195195
if hasattr(app, 'models_module')]

tests/appcachetests/runtests.py

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,31 @@ def test_load_app(self):
8484
class GetAppsTests(AppCacheTestCase):
8585
"""Tests for the get_apps function"""
8686

87-
def test_get_apps(self):
88-
"""Test that the correct models modules are returned"""
89-
settings.INSTALLED_APPS = ('django.contrib.sites',
90-
'django.contrib.contenttypes',
91-
'django.contrib.auth',
92-
'django.contrib.flatpages',)
87+
def test_app_classes(self):
88+
"""
89+
Test that the correct models modules are returned for apps installed
90+
via the APP_CLASSES setting
91+
"""
92+
settings.APP_CLASSES = ('model_app.apps.MyApp',)
93+
apps = cache.get_apps()
94+
self.assertTrue(cache.app_cache_ready())
95+
self.assertEquals(apps[0].__name__, 'model_app.othermodels')
96+
97+
def test_installed_apps(self):
98+
"""
99+
Test that the correct models modules are returned for apps installed
100+
via the INSTALLED_APPS setting
101+
"""
102+
settings.INSTALLED_APPS = ('model_app',)
93103
apps = cache.get_apps()
94-
self.assertEqual(len(apps), 4)
95-
self.assertTrue(apps[0], 'django.contrib.auth.models')
96-
self.assertTrue(apps[1], 'django.contrib.flatpages.models')
97-
self.assertTrue(apps[2], 'django.contrib.sites.models')
98-
self.assertTrue(apps[3], 'django.contrib.contenttypes.models')
99104
self.assertTrue(cache.app_cache_ready())
105+
self.assertEquals(apps[0].__name__, 'model_app.models')
100106

101107
def test_empty_models(self):
102-
"""Test that modules that don't contain models are not returned"""
103-
settings.INSTALLED_APPS = ('django.contrib.csrf',)
108+
"""
109+
Test that modules that don't contain models are not returned
110+
"""
111+
settings.INSTALLED_APPS = ('nomodel_app',)
104112
self.assertEqual(cache.get_apps(), [])
105113
self.assertTrue(cache.app_cache_ready())
106114

@@ -116,21 +124,31 @@ def test_db_prefix_exception(self):
116124
class GetAppTests(AppCacheTestCase):
117125
"""Tests for the get_app function"""
118126

119-
def test_get_app(self):
120-
"""Test that the correct module is returned"""
121-
settings.INSTALLED_APPS = ('django.contrib.contenttypes',
122-
'django.contrib.auth',)
123-
module = cache.get_app('auth')
124-
self.assertTrue(module, 'django.contrib.auth.models')
125-
self.assertTrue(cache.app_cache_ready())
127+
def test_app_classes(self):
128+
"""
129+
Test that the correct module is returned when the app was installed
130+
via the APP_CLASSES setting
131+
"""
132+
settings.APP_CLASSES = ('model_app.apps.MyApp',)
133+
rv = cache.get_app('model_app')
134+
self.assertEquals(rv.__name__, 'model_app.othermodels')
135+
136+
def test_installed_apps(self):
137+
"""
138+
Test that the correct module is returned when the app was installed
139+
via the INSTALLED_APPS setting
140+
"""
141+
settings.INSTALLED_APPS = ('model_app',)
142+
rv = cache.get_app('model_app')
143+
self.assertEquals(rv.__name__, 'model_app.models')
126144

127145
def test_not_found_exception(self):
128146
"""
129147
Test that an ImproperlyConfigured exception is raised if an app
130148
could not be found
131149
"""
132150
self.assertRaises(ImproperlyConfigured, cache.get_app,
133-
'django.contrib.auth')
151+
'notarealapp')
134152
self.assertTrue(cache.app_cache_ready())
135153

136154
def test_emptyOK(self):
@@ -143,16 +161,6 @@ def test_emptyOK(self):
143161
self.failUnless(module is None)
144162
self.assertTrue(cache.app_cache_ready())
145163

146-
def test_load_app_modules(self):
147-
"""
148-
Test that only apps that are listed in the INSTALLED_APPS setting
149-
are searched (unlike the get_apps function, which also searches
150-
apps that are loaded via load_app)
151-
"""
152-
cache.load_app('django.contrib.sites')
153-
self.assertRaises(ImproperlyConfigured, cache.get_app, 'sites')
154-
self.assertTrue(cache.app_cache_ready())
155-
156164
class GetAppErrorsTests(AppCacheTestCase):
157165
"""Tests for the get_app_errors function"""
158166

0 commit comments

Comments
 (0)
0