8000 [soc2010/app-loading] check if there is more than one app with the sa… · alex-python/django@5e17e83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e17e83

Browse files
committed
[soc2010/app-loading] check if there is more than one app with the same db_prefix
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/app-loading@13597 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent 2f027bf commit 5e17e83

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

django/core/apps.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class App(object):
2424
def __init__(self, name):
2525
self.name = name
2626
self.verbose_name = _(name.title())
27-
self.verbose_name_plural = _(name.title())
2827
self.db_prefix = name
2928
self.errors = []
3029
self.models = []
@@ -97,6 +96,16 @@ def _populate(self):
9796
% app_label)
9897
for model in models.itervalues():
9998
app_instance.models.append(model)
99+
# check if there is more than one app with the same
100+
# db_prefix attribute
101+
for app in self.app_instances:
102+
for app_cmp in self.app_instances:
103+
if app != app_cmp and \
104+
app.db_prefix == app_cmp.db_prefix:
105+
raise ImproperlyConfigured(
106+
'The apps "%s" and "%s" have the same '
107+
'db_prefix "%s"'
108+
% (app, app_cmp, app.db_prefix))
100109
self.loaded = True
101110
self.unbound_models = {}
102111
finally:

tests/appcachetests/model_app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ class MyApp(App):
66
def __repr__(self):
77
return '<MyApp: %s>' % self.name
88

9+
class MyOtherApp(MyApp):
10+
def __init__(self, name):
11+
super(MyOtherApp, self).__init__(name)
12+
self.db_prefix = 'nomodel_app'

tests/appcachetests/runtests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ def test_empty_models(self):
9797
self.assertEqual(cache.get_apps(), [])
9898
self.assertTrue(cache.app_cache_ready())
9999

100+
def test_db_prefix_exception(self):
101+
"""
102+
Test that an exception is raised if two app instances
103+
have the same db_prefix attribute
104+
"""
105+
settings.INSTALLED_APPS = ('nomodel_app.MyApp', 'model_app.MyOtherApp',)
106+
self.assertRaises(ImproperlyConfigured, cache.get_apps)
107+
100108
class GetAppTests(AppCacheTestCase):
101109
"""Tests for the get_app function"""
102110

0 commit comments

Comments
 (0)
0