summaryrefslogtreecommitdiff
path: root/tests/commands_sql
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-10-16 17:58:05 +0200
committerClaude Paroz <claude@2xlibre.net>2013-10-16 18:02:32 +0200
commit2992f428614349b0dfe0f4183905f492fd3f62c2 (patch)
treec9342dc1f454678e2fa6efcbb76c8ba1c5898911 /tests/commands_sql
parent91c77eeab837ff793311ac5b0321015a4e66d6da (diff)
downloaddjango-2992f428614349b0dfe0f4183905f492fd3f62c2.tar.gz
Fixed #19657 -- Made sql commands honor allow_migrate
Thanks Manel Clos for the report and the initial patch, and Marc Tamlyn and Tim Graham for the review.
Diffstat (limited to 'tests/commands_sql')
-rw-r--r--tests/commands_sql/tests.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py
index e083d3977a..1a1a190ec5 100644
--- a/tests/commands_sql/tests.py
+++ b/tests/commands_sql/tests.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
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, models
+from django.db import connections, DEFAULT_DB_ALIAS, models, router
from django.test import TestCase
from django.utils import six
@@ -52,3 +52,23 @@ class SQLCommandsTestCase(TestCase):
self.assertEqual(self.count_ddl(output, 'CREATE TABLE'), 3)
# PostgreSQL creates one additional index for CharField
self.assertIn(self.count_ddl(output, 'CREATE INDEX'), [3, 4])
+
+
+class TestRouter(object):
+ def allow_migrate(self, db, model):
+ return False
+
+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 = models.get_app('commands_sql')
+ 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,
+ "%s command is not honoring routers" % sql_command.__name__)