summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Koziel <arthur@arthurkoziel.com>2010-08-16 16:29:17 +0000
committerArthur Koziel <arthur@arthurkoziel.com>2010-08-16 16:29:17 +0000
commit5e17e835a073d489d6325ea540c29a86bb18fc38 (patch)
treeb024e1dd2c6f9f3a0a8af81b76815b5c7d9dfe93
parent2f027bf5dd4b92c7fcb325a1cea2abcabcfa2c90 (diff)
downloaddjango-5e17e835a073d489d6325ea540c29a86bb18fc38.tar.gz
[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
-rw-r--r--django/core/apps.py11
-rw-r--r--tests/appcachetests/model_app/__init__.py4
-rw-r--r--tests/appcachetests/runtests.py8
3 files changed, 22 insertions, 1 deletions
diff --git a/django/core/apps.py b/django/core/apps.py
index faec0886fd..2bb640aef1 100644
--- a/django/core/apps.py
+++ b/django/core/apps.py
@@ -24,7 +24,6 @@ class App(object):
def __init__(self, name):
self.name = name
self.verbose_name = _(name.title())
- self.verbose_name_plural = _(name.title())
self.db_prefix = name
self.errors = []
self.models = []
@@ -97,6 +96,16 @@ class AppCache(object):
% app_label)
for model in models.itervalues():
app_instance.models.append(model)
+ # check if there is more than one app with the same
+ # db_prefix attribute
+ for app in self.app_instances:
+ for app_cmp in self.app_instances:
+ if app != app_cmp and \
+ app.db_prefix == app_cmp.db_prefix:
+ raise ImproperlyConfigured(
+ 'The apps "%s" and "%s" have the same '
+ 'db_prefix "%s"'
+ % (app, app_cmp, app.db_prefix))
self.loaded = True
self.unbound_models = {}
finally:
diff --git a/tests/appcachetests/model_app/__init__.py b/tests/appcachetests/model_app/__init__.py
index 214e438e38..96abf9439f 100644
--- a/tests/appcachetests/model_app/__init__.py
+++ b/tests/appcachetests/model_app/__init__.py
@@ -6,3 +6,7 @@ class MyApp(App):
def __repr__(self):
return '<MyApp: %s>' % self.name
+class MyOtherApp(MyApp):
+ def __init__(self, name):
+ super(MyOtherApp, self).__init__(name)
+ self.db_prefix = 'nomodel_app'
diff --git a/tests/appcachetests/runtests.py b/tests/appcachetests/runtests.py
index 0a64d9f11a..ff6deaf7ed 100644
--- a/tests/appcachetests/runtests.py
+++ b/tests/appcachetests/runtests.py
@@ -97,6 +97,14 @@ class GetAppsTests(AppCacheTestCase):
self.assertEqual(cache.get_apps(), [])
self.assertTrue(cache.app_cache_ready())
+ def test_db_prefix_exception(self):
+ """
+ Test that an exception is raised if two app instances
+ have the same db_prefix attribute
+ """
+ settings.INSTALLED_APPS = ('nomodel_app.MyApp', 'model_app.MyOtherApp',)
+ self.assertRaises(ImproperlyConfigured, cache.get_apps)
+
class GetAppTests(AppCacheTestCase):
"""Tests for the get_app function"""