1. Luke Plant
  2. django

Commits

art...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed a5c756d

[soc2010/app-loading] update get_app/get_apps tests

  • Participants
  • Parent commits 7a2cc48
  • Branches soc2010/app-loading

Comments (0)

Files changed (2)

File django/core/apps.py

View file
         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')]

File tests/appcachetests/runtests.py

View file
 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())
 
 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):
         """
         could not be found
         """
         self.assertRaises(ImproperlyConfigured, cache.get_app,
-                          'django.contrib.auth')
+                          'notarealapp')
         self.assertTrue(cache.app_cache_ready())
 
     def test_emptyOK(self):
         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"""