mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Renamed AppCache to Apps.
Also renamed app_cache to apps and "app cache" to "app registry". Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps.cache import AppCache
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import TotallyNormal, SoAlternative, new_app_cache
|
||||
|
||||
|
||||
class AppCacheTests(TestCase):
|
||||
|
||||
def test_models_py(self):
|
||||
"""
|
||||
Tests that the models in the models.py file were loaded correctly.
|
||||
"""
|
||||
self.assertEqual(app_cache.get_model("app_cache", "TotallyNormal"), TotallyNormal)
|
||||
self.assertEqual(app_cache.get_model("app_cache", "SoAlternative"), None)
|
||||
|
||||
self.assertEqual(new_app_cache.get_model("app_cache", "TotallyNormal"), None)
|
||||
self.assertEqual(new_app_cache.get_model("app_cache", "SoAlternative"), SoAlternative)
|
||||
|
||||
def test_dynamic_load(self):
|
||||
"""
|
||||
Makes a new model at runtime and ensures it goes into the right place.
|
||||
"""
|
||||
old_models = app_cache.get_models(app_cache.get_app_config("app_cache").models_module)
|
||||
# Construct a new model in a new app cache
|
||||
body = {}
|
||||
new_app_cache = AppCache()
|
||||
meta_contents = {
|
||||
'app_label': "app_cache",
|
||||
'app_cache': new_app_cache,
|
||||
}
|
||||
meta = type("Meta", tuple(), meta_contents)
|
||||
body['Meta'] = meta
|
||||
body['__module__'] = TotallyNormal.__module__
|
||||
temp_model = type("SouthPonies", (models.Model,), body)
|
||||
# Make sure it appeared in the right place!
|
||||
self.assertEqual(
|
||||
old_models,
|
||||
app_cache.get_models(app_cache.get_app_config("app_cache").models_module),
|
||||
)
|
||||
self.assertEqual(new_app_cache.get_model("app_cache", "SouthPonies"), temp_model)
|
||||
|
||||
def test_singleton_master(self):
|
||||
"""
|
||||
Ensures that only one master app cache can exist.
|
||||
"""
|
||||
with self.assertRaises(RuntimeError):
|
||||
AppCache(master=True)
|
||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import os
|
||||
import sys
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.test import TestCase
|
||||
from django.utils._os import upath
|
||||
from django.utils import six
|
||||
@@ -17,11 +17,11 @@ class EggLoadingTest(TestCase):
|
||||
|
||||
# The models need to be removed after the test in order to prevent bad
|
||||
# interactions with the flush operation in other tests.
|
||||
self._old_models = app_cache.all_models['app_loading'].copy()
|
||||
self._old_models = apps.all_models['app_loading'].copy()
|
||||
|
||||
def tearDown(self):
|
||||
app_cache.all_models['app_loading'] = self._old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.all_models['app_loading'] = self._old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
sys.path = self.old_path
|
||||
|
||||
@@ -30,7 +30,7 @@ class EggLoadingTest(TestCase):
|
||||
egg_name = '%s/modelapp.egg' % self.egg_dir
|
||||
sys.path.append(egg_name)
|
||||
with self.settings(INSTALLED_APPS=['app_with_models']):
|
||||
models_module = app_cache.get_app_config('app_with_models').models_module
|
||||
models_module = apps.get_app_config('app_with_models').models_module
|
||||
self.assertIsNotNone(models_module)
|
||||
|
||||
def test_egg2(self):
|
||||
@@ -38,7 +38,7 @@ class EggLoadingTest(TestCase):
|
||||
egg_name = '%s/nomodelapp.egg' % self.egg_dir
|
||||
sys.path.append(egg_name)
|
||||
with self.settings(INSTALLED_APPS=['app_no_models']):
|
||||
models_module = app_cache.get_app_config('app_no_models').models_module
|
||||
models_module = apps.get_app_config('app_no_models').models_module
|
||||
self.assertIsNone(models_module)
|
||||
|
||||
def test_egg3(self):
|
||||
@@ -46,7 +46,7 @@ class EggLoadingTest(TestCase):
|
||||
egg_name = '%s/omelet.egg' % self.egg_dir
|
||||
sys.path.append(egg_name)
|
||||
with self.settings(INSTALLED_APPS=['omelet.app_with_models']):
|
||||
models_module = app_cache.get_app_config('app_with_models').models_module
|
||||
models_module = apps.get_app_config('app_with_models').models_module
|
||||
self.assertIsNotNone(models_module)
|
||||
|
||||
def test_egg4(self):
|
||||
@@ -54,7 +54,7 @@ class EggLoadingTest(TestCase):
|
||||
egg_name = '%s/omelet.egg' % self.egg_dir
|
||||
sys.path.append(egg_name)
|
||||
with self.settings(INSTALLED_APPS=['omelet.app_no_models']):
|
||||
models_module = app_cache.get_app_config('app_no_models').models_module
|
||||
models_module = apps.get_app_config('app_no_models').models_module
|
||||
self.assertIsNone(models_module)
|
||||
|
||||
def test_egg5(self):
|
||||
@@ -73,26 +73,26 @@ class GetModelsTest(TestCase):
|
||||
|
||||
def test_get_model_only_returns_installed_models(self):
|
||||
self.assertEqual(
|
||||
app_cache.get_model("not_installed", "NotInstalledModel"), None)
|
||||
apps.get_model("not_installed", "NotInstalledModel"), None)
|
||||
|
||||
def test_get_model_with_not_installed(self):
|
||||
self.assertEqual(
|
||||
app_cache.get_model(
|
||||
apps.get_model(
|
||||
"not_installed", "NotInstalledModel", only_installed=False),
|
||||
self.not_installed_module.NotInstalledModel)
|
||||
|
||||
def test_get_models_only_returns_installed_models(self):
|
||||
self.assertNotIn(
|
||||
"NotInstalledModel",
|
||||
[m.__name__ for m in app_cache.get_models()])
|
||||
[m.__name__ for m in apps.get_models()])
|
||||
|
||||
def test_get_models_with_app_label_only_returns_installed_models(self):
|
||||
self.assertEqual(app_cache.get_models(self.not_installed_module), [])
|
||||
self.assertEqual(apps.get_models(self.not_installed_module), [])
|
||||
|
||||
def test_get_models_with_not_installed(self):
|
||||
self.assertIn(
|
||||
"NotInstalledModel",
|
||||
[m.__name__ for m in app_cache.get_models(only_installed=False)])
|
||||
[m.__name__ for m in apps.get_models(only_installed=False)])
|
||||
|
||||
|
||||
class NotInstalledModelsTest(TestCase):
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
|
||||
# We're testing app cache presence on load, so this is handy.
|
||||
# We're testing app registry presence on load, so this is handy.
|
||||
|
||||
new_app_cache = AppCache()
|
||||
new_apps = Apps()
|
||||
|
||||
|
||||
class TotallyNormal(models.Model):
|
||||
@@ -14,4 +14,4 @@ class SoAlternative(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
51
tests/apps/tests.py
Normal file
51
tests/apps/tests.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.apps import apps
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import TotallyNormal, SoAlternative, new_apps
|
||||
|
||||
|
||||
class AppsTests(TestCase):
|
||||
|
||||
def test_models_py(self):
|
||||
"""
|
||||
Tests that the models in the models.py file were loaded correctly.
|
||||
"""
|
||||
self.assertEqual(apps.get_model("apps", "TotallyNormal"), TotallyNormal)
|
||||
self.assertEqual(apps.get_model("apps", "SoAlternative"), None)
|
||||
|
||||
self.assertEqual(new_apps.get_model("apps", "TotallyNormal"), None)
|
||||
self.assertEqual(new_apps.get_model("apps", "SoAlternative"), SoAlternative)
|
||||
|
||||
def test_dynamic_load(self):
|
||||
"""
|
||||
Makes a new model at runtime and ensures it goes into the right place.
|
||||
"""
|
||||
old_models = apps.get_models(apps.get_app_config("apps").models_module)
|
||||
# Construct a new model in a new app registry
|
||||
body = {}
|
||||
new_apps = Apps()
|
||||
meta_contents = {
|
||||
'app_label': "apps",
|
||||
'apps': new_apps,
|
||||
}
|
||||
meta = type("Meta", tuple(), meta_contents)
|
||||
body['Meta'] = meta
|
||||
body['__module__'] = TotallyNormal.__module__
|
||||
temp_model = type("SouthPonies", (models.Model,), body)
|
||||
# Make sure it appeared in the right place!
|
||||
self.assertEqual(
|
||||
old_models,
|
||||
apps.get_models(apps.get_app_config("apps").models_module),
|
||||
)
|
||||
self.assertEqual(new_apps.get_model("apps", "SouthPonies"), temp_model)
|
||||
|
||||
def test_singleton_master(self):
|
||||
"""
|
||||
Ensures that only one master registry can exist.
|
||||
"""
|
||||
with self.assertRaises(RuntimeError):
|
||||
Apps(master=True)
|
||||
@@ -5,7 +5,7 @@ from django.utils import six
|
||||
|
||||
|
||||
# The models definitions below used to crash. Generating models dynamically
|
||||
# at runtime is a bad idea because it pollutes the app cache. This doesn't
|
||||
# at runtime is a bad idea because it pollutes the app registry. This doesn't
|
||||
# integrate well with the test suite but at least it prevents regressions.
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.core.management import ManagementUtility
|
||||
from django.utils.six import StringIO
|
||||
|
||||
@@ -85,6 +85,6 @@ class BashCompletionTests(unittest.TestCase):
|
||||
self._user_input('django-admin.py sqlall a')
|
||||
output = self._run_autocomplete()
|
||||
a_labels = sorted(app_config.label
|
||||
for app_config in app_cache.get_app_configs()
|
||||
for app_config in apps.get_app_configs()
|
||||
if app_config.label.startswith('a'))
|
||||
self.assertEqual(output, a_labels)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.core.management.color import no_style
|
||||
from django.core.management.sql import (sql_create, sql_delete, sql_indexes,
|
||||
sql_destroy_indexes, sql_all)
|
||||
@@ -17,7 +17,7 @@ class SQLCommandsTestCase(TestCase):
|
||||
return len([o for o in output if o.startswith(cmd)])
|
||||
|
||||
def test_sql_create(self):
|
||||
app = app_cache.get_app_config('commands_sql').models_module
|
||||
app = apps.get_app_config('commands_sql').models_module
|
||||
output = sql_create(app, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
create_tables = [o for o in output if o.startswith('CREATE TABLE')]
|
||||
self.assertEqual(len(create_tables), 3)
|
||||
@@ -26,7 +26,7 @@ class SQLCommandsTestCase(TestCase):
|
||||
six.assertRegex(self, sql, r'^create table .commands_sql_book.*')
|
||||
|
||||
def test_sql_delete(self):
|
||||
app = app_cache.get_app_config('commands_sql').models_module
|
||||
app = apps.get_app_config('commands_sql').models_module
|
||||
output = sql_delete(app, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
drop_tables = [o for o in output if o.startswith('DROP TABLE')]
|
||||
self.assertEqual(len(drop_tables), 3)
|
||||
@@ -35,19 +35,19 @@ class SQLCommandsTestCase(TestCase):
|
||||
six.assertRegex(self, sql, r'^drop table .commands_sql_comment.*')
|
||||
|
||||
def test_sql_indexes(self):
|
||||
app = app_cache.get_app_config('commands_sql').models_module
|
||||
app = apps.get_app_config('commands_sql').models_module
|
||||
output = sql_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
# PostgreSQL creates one additional index for CharField
|
||||
self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4])
|
||||
|
||||
def test_sql_destroy_indexes(self):
|
||||
app = app_cache.get_app_config('commands_sql').models_module
|
||||
app = apps.get_app_config('commands_sql').models_module
|
||||
output = sql_destroy_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
# PostgreSQL creates one additional index for CharField
|
||||
self.assertIn(self.count_ddl(output, 'DROP INDEX'), [3, 4])
|
||||
|
||||
def test_sql_all(self):
|
||||
app = app_cache.get_app_config('commands_sql').models_module
|
||||
app = apps.get_app_config('commands_sql').models_module
|
||||
output = sql_all(app, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
|
||||
self.assertEqual(self.count_ddl(output, 'CREATE TABLE'), 3)
|
||||
@@ -69,7 +69,7 @@ class SQLCommandsRouterTestCase(TestCase):
|
||||
router.routers = self._old_routers
|
||||
|
||||
def test_router_honored(self):
|
||||
app = app_cache.get_app_config('commands_sql').models_module
|
||||
app = apps.get_app_config('commands_sql').models_module
|
||||
for sql_command in (sql_all, sql_create, sql_delete, sql_indexes, sql_destroy_indexes):
|
||||
output = sql_command(app, no_style(), connections[DEFAULT_DB_ALIAS])
|
||||
self.assertEqual(len(output), 0,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
@@ -61,7 +61,7 @@ class ContentTypesViewsTests(TestCase):
|
||||
class Meta:
|
||||
verbose_name = 'a model created on the fly'
|
||||
app_label = 'my_great_app'
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
ct = ContentType.objects.get_for_model(ModelCreatedOnTheFly)
|
||||
self.assertEqual(ct.app_label, 'my_great_app')
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from operator import attrgetter
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.sessions.backends.db import SessionStore
|
||||
from django.db.models import Count
|
||||
@@ -102,7 +102,7 @@ class DeferRegressionTest(TestCase):
|
||||
klasses = set(
|
||||
map(
|
||||
attrgetter("__name__"),
|
||||
app_cache.get_models(app_cache.get_app_config("defer_regress").models_module)
|
||||
apps.get_models(apps.get_app_config("defer_regress").models_module)
|
||||
)
|
||||
)
|
||||
self.assertIn("Child", klasses)
|
||||
@@ -110,13 +110,13 @@ class DeferRegressionTest(TestCase):
|
||||
self.assertNotIn("Child_Deferred_value", klasses)
|
||||
self.assertNotIn("Item_Deferred_name", klasses)
|
||||
self.assertFalse(any(
|
||||
k._deferred for k in app_cache.get_models(app_cache.get_app_config("defer_regress").models_module)))
|
||||
k._deferred for k in apps.get_models(apps.get_app_config("defer_regress").models_module)))
|
||||
|
||||
klasses_with_deferred = set(
|
||||
map(
|
||||
attrgetter("__name__"),
|
||||
app_cache.get_models(
|
||||
app_cache.get_app_config("defer_regress").models_module, include_deferred=True
|
||||
apps.get_models(
|
||||
apps.get_app_config("defer_regress").models_module, include_deferred=True
|
||||
),
|
||||
)
|
||||
)
|
||||
@@ -125,8 +125,8 @@ class DeferRegressionTest(TestCase):
|
||||
self.assertIn("Child_Deferred_value", klasses_with_deferred)
|
||||
self.assertIn("Item_Deferred_name", klasses_with_deferred)
|
||||
self.assertTrue(any(
|
||||
k._deferred for k in app_cache.get_models(
|
||||
app_cache.get_app_config("defer_regress").models_module, include_deferred=True))
|
||||
k._deferred for k in apps.get_models(
|
||||
apps.get_app_config("defer_regress").models_module, include_deferred=True))
|
||||
)
|
||||
|
||||
@override_settings(SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.core.management.validation import get_validation_errors
|
||||
from django.test import override_settings
|
||||
from django.utils.six import StringIO
|
||||
@@ -32,7 +32,7 @@ class InvalidModelTestCase(unittest.TestCase):
|
||||
TEST_SWAPPED_MODEL_BAD_MODEL='not_an_app.Target',
|
||||
)
|
||||
def test_invalid_models(self):
|
||||
module = app_cache.get_app_config("invalid_models").models_module
|
||||
module = apps.get_app_config("invalid_models").models_module
|
||||
get_validation_errors(self.stdout, module)
|
||||
|
||||
self.stdout.seek(0)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.db import models
|
||||
from django.template import Context, Template
|
||||
from django.test import TestCase, override_settings
|
||||
@@ -110,7 +110,7 @@ class ManagersRegressionTests(TestCase):
|
||||
def test_swappable_manager(self):
|
||||
# The models need to be removed after the test in order to prevent bad
|
||||
# interactions with the flush operation in other tests.
|
||||
_old_models = app_cache.app_configs['managers_regress'].models.copy()
|
||||
_old_models = apps.app_configs['managers_regress'].models.copy()
|
||||
|
||||
try:
|
||||
class SwappableModel(models.Model):
|
||||
@@ -126,15 +126,15 @@ class ManagersRegressionTests(TestCase):
|
||||
self.assertEqual(str(e), "Manager isn't available; SwappableModel has been swapped for 'managers_regress.Parent'")
|
||||
|
||||
finally:
|
||||
app_cache.app_configs['managers_regress'].models = _old_models
|
||||
app_cache.all_models['managers_regress'] = _old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.app_configs['managers_regress'].models = _old_models
|
||||
apps.all_models['managers_regress'] = _old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
@override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent')
|
||||
def test_custom_swappable_manager(self):
|
||||
# The models need to be removed after the test in order to prevent bad
|
||||
# interactions with the flush operation in other tests.
|
||||
_old_models = app_cache.app_configs['managers_regress'].models.copy()
|
||||
_old_models = apps.app_configs['managers_regress'].models.copy()
|
||||
|
||||
try:
|
||||
class SwappableModel(models.Model):
|
||||
@@ -154,15 +154,15 @@ class ManagersRegressionTests(TestCase):
|
||||
self.assertEqual(str(e), "Manager isn't available; SwappableModel has been swapped for 'managers_regress.Parent'")
|
||||
|
||||
finally:
|
||||
app_cache.app_configs['managers_regress'].models = _old_models
|
||||
app_cache.all_models['managers_regress'] = _old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.app_configs['managers_regress'].models = _old_models
|
||||
apps.all_models['managers_regress'] = _old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
@override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent')
|
||||
def test_explicit_swappable_manager(self):
|
||||
# The models need to be removed after the test in order to prevent bad
|
||||
# interactions with the flush operation in other tests.
|
||||
_old_models = app_cache.app_configs['managers_regress'].models.copy()
|
||||
_old_models = apps.app_configs['managers_regress'].models.copy()
|
||||
|
||||
try:
|
||||
class SwappableModel(models.Model):
|
||||
@@ -182,9 +182,9 @@ class ManagersRegressionTests(TestCase):
|
||||
self.assertEqual(str(e), "Manager isn't available; SwappableModel has been swapped for 'managers_regress.Parent'")
|
||||
|
||||
finally:
|
||||
app_cache.app_configs['managers_regress'].models = _old_models
|
||||
app_cache.all_models['managers_regress'] = _old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.app_configs['managers_regress'].models = _old_models
|
||||
apps.all_models['managers_regress'] = _old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
def test_regress_3871(self):
|
||||
related = RelatedModel.objects.create()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
|
||||
@@ -12,7 +12,7 @@ class UnicodeModel(models.Model):
|
||||
|
||||
class Meta:
|
||||
# Disable auto loading of this model as we load it on our own
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
verbose_name = 'úñí©óðé µóðéø'
|
||||
verbose_name_plural = 'úñí©óðé µóðéøß'
|
||||
|
||||
@@ -32,4 +32,4 @@ class UnserializableModel(models.Model):
|
||||
|
||||
class Meta:
|
||||
# Disable auto loading of this model as we load it on our own
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
@@ -5,7 +5,7 @@ import codecs
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.core.management import call_command, CommandError
|
||||
from django.test import override_settings
|
||||
from django.utils import six
|
||||
@@ -131,12 +131,12 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||
self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
|
||||
self.migration_dir = os.path.join(self.test_dir, 'migrations_%d' % self.creation_counter)
|
||||
self.migration_pkg = "migrations.migrations_%d" % self.creation_counter
|
||||
self._old_models = app_cache.app_configs['migrations'].models.copy()
|
||||
self._old_models = apps.app_configs['migrations'].models.copy()
|
||||
|
||||
def tearDown(self):
|
||||
app_cache.app_configs['migrations'].models = self._old_models
|
||||
app_cache.all_models['migrations'] = self._old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.app_configs['migrations'].models = self._old_models
|
||||
apps.all_models['migrations'] = self._old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
os.chdir(self.test_dir)
|
||||
try:
|
||||
@@ -152,7 +152,7 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||
|
||||
def test_files_content(self):
|
||||
self.assertTableNotExists("migrations_unicodemodel")
|
||||
app_cache.register_model('migrations', UnicodeModel)
|
||||
apps.register_model('migrations', UnicodeModel)
|
||||
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
|
||||
call_command("makemigrations", "migrations", verbosity=0)
|
||||
|
||||
@@ -188,7 +188,7 @@ class MakeMigrationsTests(MigrationTestBase):
|
||||
|
||||
def test_failing_migration(self):
|
||||
#21280 - If a migration fails to serialize, it shouldn't generate an empty file.
|
||||
app_cache.register_model('migrations', UnserializableModel)
|
||||
apps.register_model('migrations', UnserializableModel)
|
||||
|
||||
with six.assertRaisesRegex(self, ValueError, r'Cannot serialize'):
|
||||
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
|
||||
|
||||
@@ -43,7 +43,7 @@ class LoaderTests(TestCase):
|
||||
def test_load(self):
|
||||
"""
|
||||
Makes sure the loader can load the migrations for the test apps,
|
||||
and then render them out to a new AppCache.
|
||||
and then render them out to a new Apps.
|
||||
"""
|
||||
# Load and test the plan
|
||||
migration_loader = MigrationLoader(connection)
|
||||
|
||||
@@ -203,8 +203,8 @@ class OperationTests(MigrationTestBase):
|
||||
self.assertColumnNotExists("test_adflmm_pony", "stables")
|
||||
# Make sure the M2M field actually works
|
||||
with atomic():
|
||||
new_app_cache = new_state.render()
|
||||
Pony = new_app_cache.get_model("test_adflmm", "Pony")
|
||||
new_apps = new_state.render()
|
||||
Pony = new_apps.get_model("test_adflmm", "Pony")
|
||||
p = Pony.objects.create(pink=False, weight=4.55)
|
||||
p.stables.create()
|
||||
self.assertEqual(p.stables.count(), 1)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
from django.db.migrations.state import ProjectState, ModelState, InvalidBasesError
|
||||
from django.test import TestCase
|
||||
@@ -11,10 +11,10 @@ class StateTests(TestCase):
|
||||
|
||||
def test_create(self):
|
||||
"""
|
||||
Tests making a ProjectState from an AppCache
|
||||
Tests making a ProjectState from an Apps
|
||||
"""
|
||||
|
||||
new_app_cache = AppCache()
|
||||
new_apps = Apps()
|
||||
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
@@ -23,13 +23,13 @@ class StateTests(TestCase):
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
unique_together = ["name", "bio"]
|
||||
|
||||
class AuthorProxy(Author):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
proxy = True
|
||||
ordering = ["name"]
|
||||
|
||||
@@ -40,11 +40,11 @@ class StateTests(TestCase):
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
verbose_name = "tome"
|
||||
db_table = "test_tome"
|
||||
|
||||
project_state = ProjectState.from_app_cache(new_app_cache)
|
||||
project_state = ProjectState.from_apps(new_apps)
|
||||
author_state = project_state.models['migrations', 'author']
|
||||
author_proxy_state = project_state.models['migrations', 'authorproxy']
|
||||
book_state = project_state.models['migrations', 'book']
|
||||
@@ -75,7 +75,7 @@ class StateTests(TestCase):
|
||||
|
||||
def test_render(self):
|
||||
"""
|
||||
Tests rendering a ProjectState into an AppCache.
|
||||
Tests rendering a ProjectState into an Apps.
|
||||
"""
|
||||
project_state = ProjectState()
|
||||
project_state.add_model_state(ModelState(
|
||||
@@ -90,9 +90,9 @@ class StateTests(TestCase):
|
||||
None,
|
||||
))
|
||||
|
||||
new_app_cache = project_state.render()
|
||||
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
|
||||
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)
|
||||
new_apps = project_state.render()
|
||||
self.assertEqual(new_apps.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
|
||||
self.assertEqual(new_apps.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)
|
||||
|
||||
def test_render_model_inheritance(self):
|
||||
class Book(models.Model):
|
||||
@@ -100,90 +100,90 @@ class StateTests(TestCase):
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
class Novel(Book):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
# First, test rendering individually
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
# We shouldn't be able to render yet
|
||||
ms = ModelState.from_model(Novel)
|
||||
with self.assertRaises(InvalidBasesError):
|
||||
ms.render(app_cache)
|
||||
ms.render(apps)
|
||||
|
||||
# Once the parent model is in the app cache, it should be fine
|
||||
ModelState.from_model(Book).render(app_cache)
|
||||
ModelState.from_model(Novel).render(app_cache)
|
||||
# Once the parent model is in the app registry, it should be fine
|
||||
ModelState.from_model(Book).render(apps)
|
||||
ModelState.from_model(Novel).render(apps)
|
||||
|
||||
def test_render_model_with_multiple_inheritance(self):
|
||||
class Foo(models.Model):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
class Bar(models.Model):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
class FooBar(Foo, Bar):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
# We shouldn't be able to render yet
|
||||
ms = ModelState.from_model(FooBar)
|
||||
with self.assertRaises(InvalidBasesError):
|
||||
ms.render(app_cache)
|
||||
ms.render(apps)
|
||||
|
||||
# Once the parent models are in the app cache, it should be fine
|
||||
ModelState.from_model(Foo).render(app_cache)
|
||||
ModelState.from_model(Bar).render(app_cache)
|
||||
ModelState.from_model(FooBar).render(app_cache)
|
||||
# Once the parent models are in the app registry, it should be fine
|
||||
ModelState.from_model(Foo).render(apps)
|
||||
ModelState.from_model(Bar).render(apps)
|
||||
ModelState.from_model(FooBar).render(apps)
|
||||
|
||||
def test_render_project_dependencies(self):
|
||||
"""
|
||||
Tests that the ProjectState render method correctly renders models
|
||||
to account for inter-model base dependencies.
|
||||
"""
|
||||
new_app_cache = AppCache()
|
||||
new_apps = Apps()
|
||||
|
||||
class A(models.Model):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class B(A):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class C(B):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class D(A):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class E(B):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
proxy = True
|
||||
|
||||
class F(D):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
proxy = True
|
||||
|
||||
# Make a ProjectState and render it
|
||||
@@ -194,8 +194,8 @@ class StateTests(TestCase):
|
||||
project_state.add_model_state(ModelState.from_model(D))
|
||||
project_state.add_model_state(ModelState.from_model(E))
|
||||
project_state.add_model_state(ModelState.from_model(F))
|
||||
final_app_cache = project_state.render()
|
||||
self.assertEqual(len(final_app_cache.get_models()), 6)
|
||||
final_apps = project_state.render()
|
||||
self.assertEqual(len(final_apps.get_models()), 6)
|
||||
|
||||
# Now make an invalid ProjectState and make sure it fails
|
||||
project_state = ProjectState()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ class NoModelTests(TestCase):
|
||||
|
||||
def test_no_models(self):
|
||||
"""Test that it's possible to load an app with no models.py file."""
|
||||
app_config = app_cache.get_app_config('no_models')
|
||||
app_config = apps.get_app_config('no_models')
|
||||
self.assertIsNone(app_config.models_module)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.contrib import admin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core import management
|
||||
@@ -155,7 +155,7 @@ class ProxyModelTests(TestCase):
|
||||
def test_swappable(self):
|
||||
# The models need to be removed after the test in order to prevent bad
|
||||
# interactions with the flush operation in other tests.
|
||||
_old_models = app_cache.app_configs['proxy_models'].models.copy()
|
||||
_old_models = apps.app_configs['proxy_models'].models.copy()
|
||||
|
||||
try:
|
||||
class SwappableModel(models.Model):
|
||||
@@ -173,9 +173,9 @@ class ProxyModelTests(TestCase):
|
||||
class Meta:
|
||||
proxy = True
|
||||
finally:
|
||||
app_cache.app_configs['proxy_models'].models = _old_models
|
||||
app_cache.all_models['proxy_models'] = _old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.app_configs['proxy_models'].models = _old_models
|
||||
apps.all_models['proxy_models'] = _old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
def test_myperson_manager(self):
|
||||
Person.objects.create(name="fred")
|
||||
|
||||
@@ -80,13 +80,13 @@ def get_test_modules():
|
||||
|
||||
|
||||
def get_installed():
|
||||
from django.apps import app_cache
|
||||
return [app_config.name for app_config in app_cache.get_app_configs()]
|
||||
from django.apps import apps
|
||||
return [app_config.name for app_config in apps.get_app_configs()]
|
||||
|
||||
|
||||
def setup(verbosity, test_labels):
|
||||
import django
|
||||
from django.apps import app_cache, AppConfig
|
||||
from django.apps import apps, AppConfig
|
||||
from django.conf import settings
|
||||
from django.test import TransactionTestCase, TestCase
|
||||
|
||||
@@ -128,7 +128,7 @@ def setup(verbosity, test_labels):
|
||||
# Load all the ALWAYS_INSTALLED_APPS.
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', DeprecationWarning)
|
||||
app_cache.populate_models()
|
||||
apps.populate_models()
|
||||
|
||||
# Load all the test model apps.
|
||||
test_modules = get_test_modules()
|
||||
@@ -168,9 +168,9 @@ def setup(verbosity, test_labels):
|
||||
if module_label not in settings.INSTALLED_APPS:
|
||||
settings.INSTALLED_APPS.append(module_label)
|
||||
app_config = AppConfig.create(module_label)
|
||||
app_config.import_models(app_cache.all_models[app_config.label])
|
||||
app_cache.app_configs[app_config.label] = app_config
|
||||
app_cache.get_models.cache_clear()
|
||||
app_config.import_models(apps.all_models[app_config.label])
|
||||
apps.app_configs[app_config.label] = app_config
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
return state
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
|
||||
# Because we want to test creation and deletion of these as separate things,
|
||||
# these models are all inserted into a separate AppCache so the main test
|
||||
# these models are all inserted into a separate Apps so the main test
|
||||
# runner doesn't migrate them.
|
||||
|
||||
new_app_cache = AppCache()
|
||||
new_apps = Apps()
|
||||
|
||||
|
||||
class Author(models.Model):
|
||||
@@ -13,14 +13,14 @@ class Author(models.Model):
|
||||
height = models.PositiveIntegerField(null=True, blank=True)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
|
||||
class AuthorWithM2M(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
@@ -30,7 +30,7 @@ class Book(models.Model):
|
||||
# tags = models.ManyToManyField("Tag", related_name="books")
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
|
||||
class BookWithM2M(models.Model):
|
||||
@@ -40,7 +40,7 @@ class BookWithM2M(models.Model):
|
||||
tags = models.ManyToManyField("TagM2MTest", related_name="books")
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
|
||||
class BookWithSlug(models.Model):
|
||||
@@ -50,7 +50,7 @@ class BookWithSlug(models.Model):
|
||||
slug = models.CharField(max_length=20, unique=True)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
db_table = "schema_book"
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class Tag(models.Model):
|
||||
slug = models.SlugField(unique=True)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
|
||||
class TagM2MTest(models.Model):
|
||||
@@ -67,7 +67,7 @@ class TagM2MTest(models.Model):
|
||||
slug = models.SlugField(unique=True)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
|
||||
class TagIndexed(models.Model):
|
||||
@@ -75,7 +75,7 @@ class TagIndexed(models.Model):
|
||||
slug = models.SlugField(unique=True)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
index_together = [["slug", "title"]]
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class TagUniqueRename(models.Model):
|
||||
slug2 = models.SlugField(unique=True)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
db_table = "schema_tag"
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class UniqueTest(models.Model):
|
||||
slug = models.SlugField(unique=False)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
unique_together = ["year", "slug"]
|
||||
|
||||
|
||||
@@ -101,4 +101,4 @@ class BookWithLongName(models.Model):
|
||||
author_foreign_key_with_really_long_field_name = models.ForeignKey(Author)
|
||||
|
||||
class Meta:
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.utils.six import StringIO
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core import management
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
from django.db import connection
|
||||
from django.core.management.color import no_style
|
||||
@@ -26,7 +26,7 @@ class TablespacesTests(TestCase):
|
||||
def setUp(self):
|
||||
# The unmanaged models need to be removed after the test in order to
|
||||
# prevent bad interactions with the flush operation in other tests.
|
||||
self._old_models = app_cache.app_configs['tablespaces'].models.copy()
|
||||
self._old_models = apps.app_configs['tablespaces'].models.copy()
|
||||
|
||||
for model in Article, Authors, Reviewers, Scientist:
|
||||
model._meta.managed = True
|
||||
@@ -35,9 +35,9 @@ class TablespacesTests(TestCase):
|
||||
for model in Article, Authors, Reviewers, Scientist:
|
||||
model._meta.managed = False
|
||||
|
||||
app_cache.app_configs['tablespaces'].models = self._old_models
|
||||
app_cache.all_models['tablespaces'] = self._old_models
|
||||
app_cache.get_models.cache_clear()
|
||||
apps.app_configs['tablespaces'].models = self._old_models
|
||||
apps.all_models['tablespaces'] = self._old_models
|
||||
apps.get_models.cache_clear()
|
||||
|
||||
def assertNumContains(self, haystack, needle, count):
|
||||
real_count = haystack.count(needle)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import unittest
|
||||
|
||||
from django.apps import app_cache
|
||||
from django.apps import apps
|
||||
from django.test.utils import IgnoreAllDeprecationWarningsMixin
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class SuiteOverrideTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
|
||||
"""
|
||||
|
||||
from django.test.simple import build_suite
|
||||
app_config = app_cache.get_app_config("test_suite_override")
|
||||
app_config = apps.get_app_config("test_suite_override")
|
||||
suite = build_suite(app_config)
|
||||
self.assertEqual(suite.countTestCases(), 1)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
@@ -58,7 +58,7 @@ class GetUniqueCheckTests(unittest.TestCase):
|
||||
|
||||
Meta = type(str('Meta'), (), {
|
||||
'unique_together': unique_together,
|
||||
'app_cache': AppCache()
|
||||
'apps': Apps()
|
||||
})
|
||||
|
||||
checks, _ = M()._get_unique_checks()
|
||||
|
||||
Reference in New Issue
Block a user