Loading tests/apps/models.py +3 −0 Original line number Diff line number Diff line from __future__ import unicode_literals from django.apps.registry import Apps from django.db import models # We're testing app registry presence on load, so this is handy. new_apps = Apps() Loading tests/apps/tests.py +69 −4 Original line number Diff line number Diff line from __future__ import absolute_import from __future__ import absolute_import, unicode_literals from django.apps import apps from django.apps.registry import Apps from django.conf import settings from django.db import models from django.test import TestCase from django.test import TestCase, override_settings from .models import TotallyNormal, SoAlternative, new_apps # Small list with a variety of cases for tests that iterate on installed apps. # Intentionally not in alphabetical order to check if the order is preserved. SOME_INSTALLED_APPS = [ 'apps.apps.MyAdmin', 'apps.apps.MyAuth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] SOME_INSTALLED_APPS_NAMES = [ 'django.contrib.admin', 'django.contrib.auth', ] + SOME_INSTALLED_APPS[2:] SOME_INSTALLED_APPS_WTH_MODELS_NAMES = SOME_INSTALLED_APPS_NAMES[:4] class AppsTests(TestCase): def test_singleton_master(self): Loading @@ -33,6 +53,51 @@ class AppsTests(TestCase): # ready regardless of whether populate_models() has run. self.assertTrue(apps.ready) @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_configs(self): """ Tests get_app_configs(). """ app_configs = apps.get_app_configs() self.assertListEqual( [app_config.name for app_config in app_configs], SOME_INSTALLED_APPS_NAMES) @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_configs_with_models(self): """ Tests get_app_configs(only_with_models_module=True). """ app_configs = apps.get_app_configs(only_with_models_module=True) self.assertListEqual( [app_config.name for app_config in app_configs], SOME_INSTALLED_APPS_WTH_MODELS_NAMES) @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_config(self): """ Tests get_app_config(). """ app_config = apps.get_app_config('admin') self.assertEqual(app_config.name, 'django.contrib.admin') app_config = apps.get_app_config('staticfiles') self.assertEqual(app_config.name, 'django.contrib.staticfiles') with self.assertRaises(LookupError): apps.get_app_config('webdesign') @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_config_with_models(self): """ Tests get_app_config(only_with_models_module=True). """ app_config = apps.get_app_config('admin', only_with_models_module=True) self.assertEqual(app_config.name, 'django.contrib.admin') with self.assertRaises(LookupError): apps.get_app_config('staticfiles', only_with_models_module=True) def test_models_py(self): """ Tests that the models in the models.py file were loaded correctly. Loading @@ -55,10 +120,10 @@ class AppsTests(TestCase): 'app_label': "apps", 'apps': new_apps, } meta = type("Meta", tuple(), meta_contents) meta = type(str("Meta"), tuple(), meta_contents) body['Meta'] = meta body['__module__'] = TotallyNormal.__module__ temp_model = type("SouthPonies", (models.Model,), body) temp_model = type(str("SouthPonies"), (models.Model,), body) # Make sure it appeared in the right place! self.assertEqual( old_models, Loading Loading
tests/apps/models.py +3 −0 Original line number Diff line number Diff line from __future__ import unicode_literals from django.apps.registry import Apps from django.db import models # We're testing app registry presence on load, so this is handy. new_apps = Apps() Loading
tests/apps/tests.py +69 −4 Original line number Diff line number Diff line from __future__ import absolute_import from __future__ import absolute_import, unicode_literals from django.apps import apps from django.apps.registry import Apps from django.conf import settings from django.db import models from django.test import TestCase from django.test import TestCase, override_settings from .models import TotallyNormal, SoAlternative, new_apps # Small list with a variety of cases for tests that iterate on installed apps. # Intentionally not in alphabetical order to check if the order is preserved. SOME_INSTALLED_APPS = [ 'apps.apps.MyAdmin', 'apps.apps.MyAuth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] SOME_INSTALLED_APPS_NAMES = [ 'django.contrib.admin', 'django.contrib.auth', ] + SOME_INSTALLED_APPS[2:] SOME_INSTALLED_APPS_WTH_MODELS_NAMES = SOME_INSTALLED_APPS_NAMES[:4] class AppsTests(TestCase): def test_singleton_master(self): Loading @@ -33,6 +53,51 @@ class AppsTests(TestCase): # ready regardless of whether populate_models() has run. self.assertTrue(apps.ready) @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_configs(self): """ Tests get_app_configs(). """ app_configs = apps.get_app_configs() self.assertListEqual( [app_config.name for app_config in app_configs], SOME_INSTALLED_APPS_NAMES) @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_configs_with_models(self): """ Tests get_app_configs(only_with_models_module=True). """ app_configs = apps.get_app_configs(only_with_models_module=True) self.assertListEqual( [app_config.name for app_config in app_configs], SOME_INSTALLED_APPS_WTH_MODELS_NAMES) @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_config(self): """ Tests get_app_config(). """ app_config = apps.get_app_config('admin') self.assertEqual(app_config.name, 'django.contrib.admin') app_config = apps.get_app_config('staticfiles') self.assertEqual(app_config.name, 'django.contrib.staticfiles') with self.assertRaises(LookupError): apps.get_app_config('webdesign') @override_settings(INSTALLED_APPS=SOME_INSTALLED_APPS) def test_get_app_config_with_models(self): """ Tests get_app_config(only_with_models_module=True). """ app_config = apps.get_app_config('admin', only_with_models_module=True) self.assertEqual(app_config.name, 'django.contrib.admin') with self.assertRaises(LookupError): apps.get_app_config('staticfiles', only_with_models_module=True) def test_models_py(self): """ Tests that the models in the models.py file were loaded correctly. Loading @@ -55,10 +120,10 @@ class AppsTests(TestCase): 'app_label': "apps", 'apps': new_apps, } meta = type("Meta", tuple(), meta_contents) meta = type(str("Meta"), tuple(), meta_contents) body['Meta'] = meta body['__module__'] = TotallyNormal.__module__ temp_model = type("SouthPonies", (models.Model,), body) temp_model = type(str("SouthPonies"), (models.Model,), body) # Make sure it appeared in the right place! self.assertEqual( old_models, Loading