Author: arthurk
Date: 2010-08-16 11:29:17 -0500 (Mon, 16 Aug 2010)
New Revision: 13597

Modified:
   django/branches/soc2010/app-loading/django/core/apps.py
   django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py
   django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
Log:
[soc2010/app-loading] check if there is more than one app with the same 
db_prefix

Modified: django/branches/soc2010/app-loading/django/core/apps.py
===================================================================
--- django/branches/soc2010/app-loading/django/core/apps.py     2010-08-16 
06:51:15 UTC (rev 13596)
+++ django/branches/soc2010/app-loading/django/core/apps.py     2010-08-16 
16:29:17 UTC (rev 13597)
@@ -24,7 +24,6 @@
     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 @@
                                 % 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:

Modified: 
django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py
===================================================================
--- 
django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py   
    2010-08-16 06:51:15 UTC (rev 13596)
+++ 
django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py   
    2010-08-16 16:29:17 UTC (rev 13597)
@@ -6,3 +6,7 @@
     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'

Modified: django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
===================================================================
--- django/branches/soc2010/app-loading/tests/appcachetests/runtests.py 
2010-08-16 06:51:15 UTC (rev 13596)
+++ django/branches/soc2010/app-loading/tests/appcachetests/runtests.py 
2010-08-16 16:29:17 UTC (rev 13597)
@@ -97,6 +97,14 @@
         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"""
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to