summaryrefslogtreecommitdiff
path: root/tests/commands_sql
diff options
context:
space:
mode:
authorFlorian Apolloner <florian@apolloner.eu>2013-02-26 09:53:47 +0100
committerFlorian Apolloner <florian@apolloner.eu>2013-02-26 14:36:57 +0100
commit89f40e36246100df6a11316c31a76712ebc6c501 (patch)
tree6e65639683ddaf2027908d1ecb1739e0e2ff853b /tests/commands_sql
parentb3d2ccb5bfbaf6e7fe1f98843baaa48c35a70950 (diff)
downloaddjango-89f40e36246100df6a11316c31a76712ebc6c501.tar.gz
Merged regressiontests and modeltests into the test root.
Diffstat (limited to 'tests/commands_sql')
-rw-r--r--tests/commands_sql/__init__.py0
-rw-r--r--tests/commands_sql/models.py7
-rw-r--r--tests/commands_sql/tests.py52
3 files changed, 59 insertions, 0 deletions
diff --git a/tests/commands_sql/__init__.py b/tests/commands_sql/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/commands_sql/__init__.py
diff --git a/tests/commands_sql/models.py b/tests/commands_sql/models.py
new file mode 100644
index 0000000000..089aa96f30
--- /dev/null
+++ b/tests/commands_sql/models.py
@@ -0,0 +1,7 @@
+from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+
+
+@python_2_unicode_compatible
+class Book(models.Model):
+ title = models.CharField(max_length=100, db_index=True)
diff --git a/tests/commands_sql/tests.py b/tests/commands_sql/tests.py
new file mode 100644
index 0000000000..949032ae6f
--- /dev/null
+++ b/tests/commands_sql/tests.py
@@ -0,0 +1,52 @@
+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.test import TestCase
+from django.utils import six
+
+# See also regressiontests/initial_sql_regress for 'custom_sql_for_model' tests
+
+
+class SQLCommandsTestCase(TestCase):
+ """Tests for several functions in django/core/management/sql.py"""
+ def test_sql_create(self):
+ app = models.get_app('commands_sql')
+ output = sql_create(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ # Lower so that Oracle's upper case tbl names wont break
+ sql = output[0].lower()
+ six.assertRegex(self, sql, r'^create table .commands_sql_book.*')
+
+ def test_sql_delete(self):
+ app = models.get_app('commands_sql')
+ output = sql_delete(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ # Oracle produces DROP SEQUENCE and DROP TABLE for this command.
+ if connections[DEFAULT_DB_ALIAS].vendor == 'oracle':
+ sql = output[1].lower()
+ else:
+ sql = output[0].lower()
+ six.assertRegex(self, sql, r'^drop table .commands_sql_book.*')
+
+ def test_sql_indexes(self):
+ app = models.get_app('commands_sql')
+ output = sql_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ # PostgreSQL creates two indexes
+ self.assertIn(len(output), [1, 2])
+ self.assertTrue(output[0].startswith("CREATE INDEX"))
+
+ def test_sql_destroy_indexes(self):
+ app = models.get_app('commands_sql')
+ output = sql_destroy_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ # PostgreSQL creates two indexes
+ self.assertIn(len(output), [1, 2])
+ self.assertTrue(output[0].startswith("DROP INDEX"))
+
+ def test_sql_all(self):
+ app = models.get_app('commands_sql')
+ output = sql_all(app, no_style(), connections[DEFAULT_DB_ALIAS])
+ # PostgreSQL creates two indexes
+ self.assertIn(len(output), [2, 3])
+ self.assertTrue(output[0].startswith('CREATE TABLE'))
+ self.assertTrue(output[1].startswith('CREATE INDEX'))