mirror of
https://github.com/django/django.git
synced 2025-12-15 21:45:20 +00:00
Deprecated get_app().
This commit is contained in:
parent
2732edc5f2
commit
69039becde
13 changed files with 55 additions and 62 deletions
|
|
@ -27,7 +27,7 @@ class AppCacheTests(TestCase):
|
|||
"""
|
||||
Makes a new model at runtime and ensures it goes into the right place.
|
||||
"""
|
||||
old_models = app_cache.get_models(app_cache.get_app("app_cache"))
|
||||
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 = BaseAppCache()
|
||||
|
|
@ -42,6 +42,6 @@ class AppCacheTests(TestCase):
|
|||
# Make sure it appeared in the right place!
|
||||
self.assertEqual(
|
||||
old_models,
|
||||
app_cache.get_models(app_cache.get_app("app_cache")),
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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('commands_sql')
|
||||
app = app_cache.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('commands_sql')
|
||||
app = app_cache.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('commands_sql')
|
||||
app = app_cache.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('commands_sql')
|
||||
app = app_cache.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('commands_sql')
|
||||
app = app_cache.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('commands_sql')
|
||||
app = app_cache.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,
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class DeferRegressionTest(TestCase):
|
|||
klasses = set(
|
||||
map(
|
||||
attrgetter("__name__"),
|
||||
app_cache.get_models(app_cache.get_app("defer_regress"))
|
||||
app_cache.get_models(app_cache.get_app_config("defer_regress").models_module)
|
||||
)
|
||||
)
|
||||
self.assertIn("Child", klasses)
|
||||
|
|
@ -111,13 +111,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("defer_regress"))))
|
||||
k._deferred for k in app_cache.get_models(app_cache.get_app_config("defer_regress").models_module)))
|
||||
|
||||
klasses_with_deferred = set(
|
||||
map(
|
||||
attrgetter("__name__"),
|
||||
app_cache.get_models(
|
||||
app_cache.get_app("defer_regress"), include_deferred=True
|
||||
app_cache.get_app_config("defer_regress").models_module, include_deferred=True
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
@ -127,7 +127,7 @@ class DeferRegressionTest(TestCase):
|
|||
self.assertIn("Item_Deferred_name", klasses_with_deferred)
|
||||
self.assertTrue(any(
|
||||
k._deferred for k in app_cache.get_models(
|
||||
app_cache.get_app("defer_regress"), include_deferred=True))
|
||||
app_cache.get_app_config("defer_regress").models_module, include_deferred=True))
|
||||
)
|
||||
|
||||
@override_settings(SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from django.apps import app_cache
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import six
|
||||
|
|
@ -31,6 +30,6 @@ class NoModelTests(TestCase):
|
|||
"""
|
||||
@override_settings(INSTALLED_APPS=("empty.no_models",))
|
||||
def test_no_models(self):
|
||||
with six.assertRaisesRegex(self, ImproperlyConfigured,
|
||||
with six.assertRaisesRegex(self, LookupError,
|
||||
"No app with label 'no_models'."):
|
||||
app_cache.get_app('no_models')
|
||||
app_cache.get_app_config('no_models')
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class SuiteOverrideTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
|
|||
"""
|
||||
|
||||
from django.test.simple import build_suite
|
||||
app = app_cache.get_app("test_suite_override")
|
||||
app = app_cache.get_app_config("test_suite_override").models_module
|
||||
suite = build_suite(app)
|
||||
self.assertEqual(suite.countTestCases(), 1)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue