Loading django/contrib/gis/tests/layermap/tests.py +3 −9 Original line number Diff line number Diff line Loading @@ -8,9 +8,9 @@ import unittest from unittest import skipUnless from django.contrib.gis.gdal import HAS_GDAL from django.db import connection, router from django.db import connection from django.conf import settings from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, override_settings, skipUnlessDBFeature from django.utils._os import upath if HAS_GDAL: Loading Loading @@ -328,15 +328,9 @@ class OtherRouter(object): @skipUnless(HAS_GDAL, "LayerMapRouterTest needs GDAL support") @skipUnlessDBFeature("gis_enabled") @override_settings(DATABASE_ROUTERS=[OtherRouter()]) class LayerMapRouterTest(TestCase): def setUp(self): self.old_routers = router.routers router.routers = [OtherRouter()] def tearDown(self): router.routers = self.old_routers @unittest.skipUnless(len(settings.DATABASES) > 1, 'multiple databases required') def test_layermapping_default_db(self): lm = LayerMapping(City, city_shp, city_mapping) Loading tests/cache/tests.py +19 −23 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ from django.core import management from django.core.cache import (cache, caches, CacheKeyWarning, InvalidCacheBackendError, DEFAULT_CACHE_ALIAS) from django.core.context_processors import csrf from django.db import connection, connections, router, transaction from django.db import connection, connections, transaction from django.core.cache.utils import make_template_fragment_key from django.http import HttpResponse, StreamingHttpResponse from django.middleware.cache import (FetchFromCacheMiddleware, Loading Loading @@ -974,10 +974,8 @@ class DBCacheRouter(object): class CreateCacheTableForDBCacheTests(TestCase): multi_db = True @override_settings(DATABASE_ROUTERS=[DBCacheRouter()]) def test_createcachetable_observes_database_router(self): old_routers = router.routers try: router.routers = [DBCacheRouter()] # cache table should not be created on 'default' with self.assertNumQueries(0, using='default'): management.call_command('createcachetable', Loading @@ -995,8 +993,6 @@ class CreateCacheTableForDBCacheTests(TestCase): management.call_command('createcachetable', database='other', verbosity=0, interactive=False) finally: router.routers = old_routers class PicklingSideEffect(object): Loading tests/commands_sql/tests.py +3 −8 Original line number Diff line number Diff line Loading @@ -7,8 +7,8 @@ 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) from django.db import connections, DEFAULT_DB_ALIAS, router from django.test import TestCase from django.db import connections, DEFAULT_DB_ALIAS from django.test import TestCase, override_settings from django.utils import six # See also initial_sql_regress for 'custom_sql_for_model' tests Loading Loading @@ -91,13 +91,8 @@ class TestRouter(object): return False @override_settings(DATABASE_ROUTERS=[TestRouter()]) class SQLCommandsRouterTestCase(TestCase): def setUp(self): self._old_routers = router.routers router.routers = [TestRouter()] def tearDown(self): router.routers = self._old_routers def test_router_honored(self): app_config = apps.get_app_config('commands_sql') Loading tests/contenttypes_tests/tests.py +4 −9 Original line number Diff line number Diff line Loading @@ -8,9 +8,9 @@ from django.contrib.contenttypes.fields import ( from django.contrib.contenttypes import management from django.contrib.contenttypes.models import ContentType from django.core import checks from django.db import connections, models, router from django.test import TestCase from django.test.utils import captured_stdout, override_settings from django.db import connections, models from django.test import TestCase, override_settings from django.test.utils import captured_stdout from django.utils.encoding import force_str from .models import Author, Article, SchemeIncludedURL Loading Loading @@ -397,12 +397,10 @@ class TestRouter(object): return 'default' @override_settings(DATABASE_ROUTERS=[TestRouter()]) class ContentTypesMultidbTestCase(TestCase): def setUp(self): self.old_routers = router.routers router.routers = [TestRouter()] # Whenever a test starts executing, only the "default" database is # connected. We explicitly connect to the "other" database here. If we # don't do it, then it will be implicitly connected later when we query Loading @@ -411,9 +409,6 @@ class ContentTypesMultidbTestCase(TestCase): # "SET SQL_AUTO_IS_NULL = 0"), which will affect assertNumQueries(). connections['other'].ensure_connection() def tearDown(self): router.routers = self.old_routers def test_multidb(self): """ Test that, when using multiple databases, we use the db_for_read (see Loading tests/migrations/test_operations.py +3 −11 Original line number Diff line number Diff line Loading @@ -8,13 +8,13 @@ except ImportError: sqlparse = None from django import test from django.test import override_settings from django.db import connection, migrations, models, router from django.db import connection, migrations, models from django.db.migrations.migration import Migration from django.db.migrations.state import ProjectState from django.db.models.fields import NOT_PROVIDED from django.db.transaction import atomic from django.db.utils import IntegrityError, DatabaseError from django.test import override_settings from django.utils import six from .test_base import MigrationTestBase Loading Loading @@ -1566,18 +1566,10 @@ class MigrateNothingRouter(object): return False @override_settings(DATABASE_ROUTERS=[MigrateNothingRouter()]) class MultiDBOperationTests(MigrationTestBase): multi_db = True def setUp(self): # Make the 'other' database appear to be a replica of the 'default' self.old_routers = router.routers router.routers = [MigrateNothingRouter()] def tearDown(self): # Restore the 'other' database as an independent database router.routers = self.old_routers def test_create_model(self): """ Tests that CreateModel honours multi-db settings. Loading Loading
django/contrib/gis/tests/layermap/tests.py +3 −9 Original line number Diff line number Diff line Loading @@ -8,9 +8,9 @@ import unittest from unittest import skipUnless from django.contrib.gis.gdal import HAS_GDAL from django.db import connection, router from django.db import connection from django.conf import settings from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, override_settings, skipUnlessDBFeature from django.utils._os import upath if HAS_GDAL: Loading Loading @@ -328,15 +328,9 @@ class OtherRouter(object): @skipUnless(HAS_GDAL, "LayerMapRouterTest needs GDAL support") @skipUnlessDBFeature("gis_enabled") @override_settings(DATABASE_ROUTERS=[OtherRouter()]) class LayerMapRouterTest(TestCase): def setUp(self): self.old_routers = router.routers router.routers = [OtherRouter()] def tearDown(self): router.routers = self.old_routers @unittest.skipUnless(len(settings.DATABASES) > 1, 'multiple databases required') def test_layermapping_default_db(self): lm = LayerMapping(City, city_shp, city_mapping) Loading
tests/cache/tests.py +19 −23 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ from django.core import management from django.core.cache import (cache, caches, CacheKeyWarning, InvalidCacheBackendError, DEFAULT_CACHE_ALIAS) from django.core.context_processors import csrf from django.db import connection, connections, router, transaction from django.db import connection, connections, transaction from django.core.cache.utils import make_template_fragment_key from django.http import HttpResponse, StreamingHttpResponse from django.middleware.cache import (FetchFromCacheMiddleware, Loading Loading @@ -974,10 +974,8 @@ class DBCacheRouter(object): class CreateCacheTableForDBCacheTests(TestCase): multi_db = True @override_settings(DATABASE_ROUTERS=[DBCacheRouter()]) def test_createcachetable_observes_database_router(self): old_routers = router.routers try: router.routers = [DBCacheRouter()] # cache table should not be created on 'default' with self.assertNumQueries(0, using='default'): management.call_command('createcachetable', Loading @@ -995,8 +993,6 @@ class CreateCacheTableForDBCacheTests(TestCase): management.call_command('createcachetable', database='other', verbosity=0, interactive=False) finally: router.routers = old_routers class PicklingSideEffect(object): Loading
tests/commands_sql/tests.py +3 −8 Original line number Diff line number Diff line Loading @@ -7,8 +7,8 @@ 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) from django.db import connections, DEFAULT_DB_ALIAS, router from django.test import TestCase from django.db import connections, DEFAULT_DB_ALIAS from django.test import TestCase, override_settings from django.utils import six # See also initial_sql_regress for 'custom_sql_for_model' tests Loading Loading @@ -91,13 +91,8 @@ class TestRouter(object): return False @override_settings(DATABASE_ROUTERS=[TestRouter()]) class SQLCommandsRouterTestCase(TestCase): def setUp(self): self._old_routers = router.routers router.routers = [TestRouter()] def tearDown(self): router.routers = self._old_routers def test_router_honored(self): app_config = apps.get_app_config('commands_sql') Loading
tests/contenttypes_tests/tests.py +4 −9 Original line number Diff line number Diff line Loading @@ -8,9 +8,9 @@ from django.contrib.contenttypes.fields import ( from django.contrib.contenttypes import management from django.contrib.contenttypes.models import ContentType from django.core import checks from django.db import connections, models, router from django.test import TestCase from django.test.utils import captured_stdout, override_settings from django.db import connections, models from django.test import TestCase, override_settings from django.test.utils import captured_stdout from django.utils.encoding import force_str from .models import Author, Article, SchemeIncludedURL Loading Loading @@ -397,12 +397,10 @@ class TestRouter(object): return 'default' @override_settings(DATABASE_ROUTERS=[TestRouter()]) class ContentTypesMultidbTestCase(TestCase): def setUp(self): self.old_routers = router.routers router.routers = [TestRouter()] # Whenever a test starts executing, only the "default" database is # connected. We explicitly connect to the "other" database here. If we # don't do it, then it will be implicitly connected later when we query Loading @@ -411,9 +409,6 @@ class ContentTypesMultidbTestCase(TestCase): # "SET SQL_AUTO_IS_NULL = 0"), which will affect assertNumQueries(). connections['other'].ensure_connection() def tearDown(self): router.routers = self.old_routers def test_multidb(self): """ Test that, when using multiple databases, we use the db_for_read (see Loading
tests/migrations/test_operations.py +3 −11 Original line number Diff line number Diff line Loading @@ -8,13 +8,13 @@ except ImportError: sqlparse = None from django import test from django.test import override_settings from django.db import connection, migrations, models, router from django.db import connection, migrations, models from django.db.migrations.migration import Migration from django.db.migrations.state import ProjectState from django.db.models.fields import NOT_PROVIDED from django.db.transaction import atomic from django.db.utils import IntegrityError, DatabaseError from django.test import override_settings from django.utils import six from .test_base import MigrationTestBase Loading Loading @@ -1566,18 +1566,10 @@ class MigrateNothingRouter(object): return False @override_settings(DATABASE_ROUTERS=[MigrateNothingRouter()]) class MultiDBOperationTests(MigrationTestBase): multi_db = True def setUp(self): # Make the 'other' database appear to be a replica of the 'default' self.old_routers = router.routers router.routers = [MigrateNothingRouter()] def tearDown(self): # Restore the 'other' database as an independent database router.routers = self.old_routers def test_create_model(self): """ Tests that CreateModel honours multi-db settings. Loading