Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added tests for some sql_* management commands

  • Loading branch information...
commit 718afcafc202940cd15799459178a2534b8217d5 1 parent d93edff
Claude Paroz authored February 09, 2013
0  tests/regressiontests/commands_sql/__init__.py
No changes.
7  tests/regressiontests/commands_sql/models.py
... ...
@@ -0,0 +1,7 @@
  1
+from django.db import models
  2
+from django.utils.encoding import python_2_unicode_compatible
  3
+
  4
+
  5
+@python_2_unicode_compatible
  6
+class Book(models.Model):
  7
+    title = models.CharField(max_length=100, db_index=True)
38  tests/regressiontests/commands_sql/tests.py
... ...
@@ -0,0 +1,38 @@
  1
+from __future__ import unicode_literals
  2
+
  3
+from django.core.management.color import no_style
  4
+from django.core.management.sql import (sql_create, sql_delete, sql_indexes,
  5
+    sql_all)
  6
+from django.db import connections, DEFAULT_DB_ALIAS, models
  7
+from django.test import TestCase
  8
+from django.utils import six
  9
+
  10
+# See also regressiontests/initial_sql_regress for 'custom_sql_for_model' tests
  11
+
  12
+
  13
+class SQLCommandsTestCase(TestCase):
  14
+    """Tests for several functions in django/core/management/sql.py"""
  15
+    def test_sql_create(self):
  16
+        app = models.get_app('commands_sql')
  17
+        output = sql_create(app, no_style(), connections[DEFAULT_DB_ALIAS])
  18
+        six.assertRegex(self, output[0], r'^CREATE TABLE .commands_sql_book.*')
  19
+
  20
+    def test_sql_delete(self):
  21
+        app = models.get_app('commands_sql')
  22
+        output = sql_delete(app, no_style(), connections[DEFAULT_DB_ALIAS])
  23
+        six.assertRegex(self, output[0], r'^DROP TABLE .commands_sql_book.*')
  24
+
  25
+    def test_sql_indexes(self):
  26
+        app = models.get_app('commands_sql')
  27
+        output = sql_indexes(app, no_style(), connections[DEFAULT_DB_ALIAS])
  28
+        # PostgreSQL creates two indexes
  29
+        self.assertIn(len(output), [1, 2])
  30
+        self.assertTrue(output[0].startswith("CREATE INDEX"))
  31
+
  32
+    def test_sql_all(self):
  33
+        app = models.get_app('commands_sql')
  34
+        output = sql_all(app, no_style(), connections[DEFAULT_DB_ALIAS])
  35
+        # PostgreSQL creates two indexes
  36
+        self.assertIn(len(output), [2, 3])
  37
+        self.assertTrue(output[0].startswith('CREATE TABLE'))
  38
+        self.assertTrue(output[1].startswith('CREATE INDEX'))

0 notes on commit 718afca

Please sign in to comment.
Something went wrong with that request. Please try again.