Anonymous avatar Anonymous committed a5c756d

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

Comments (0)

Files changed (2)

django/core/apps.py

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

tests/appcachetests/runtests.py

 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"""
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.