summaryrefslogtreecommitdiff
path: root/tests/initial_sql_regress
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-04-18 17:16:39 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-04-18 17:16:39 +0100
commit7f3678dc4cd7146c49bac3fb8f5211f647636aa3 (patch)
treefdd2a60ccd1a9a3162d89f970db44502e35a3b3f /tests/initial_sql_regress
parentb62e82365ad56ca930f7abb1d1dbdf9ce5a7c7c3 (diff)
parent93c1576f17f6c5ee73f94f8de007f3c33010dc81 (diff)
Merge branch 'master' into schema-alteration
Conflicts: django/db/backends/__init__.py django/db/backends/mysql/base.py django/db/backends/oracle/base.py django/db/backends/oracle/creation.py django/db/backends/postgresql_psycopg2/base.py django/db/backends/sqlite3/base.py django/db/models/fields/related.py
Diffstat (limited to 'tests/initial_sql_regress')
-rw-r--r--tests/initial_sql_regress/__init__.py0
-rw-r--r--tests/initial_sql_regress/models.py10
-rw-r--r--tests/initial_sql_regress/sql/simple.sql12
-rw-r--r--tests/initial_sql_regress/tests.py47
4 files changed, 69 insertions, 0 deletions
diff --git a/tests/initial_sql_regress/__init__.py b/tests/initial_sql_regress/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/initial_sql_regress/__init__.py
diff --git a/tests/initial_sql_regress/models.py b/tests/initial_sql_regress/models.py
new file mode 100644
index 0000000000..76de6d3bcb
--- /dev/null
+++ b/tests/initial_sql_regress/models.py
@@ -0,0 +1,10 @@
+"""
+Regression tests for initial SQL insertion.
+"""
+
+from django.db import models
+
+
+class Simple(models.Model):
+ name = models.CharField(max_length = 50)
+
diff --git a/tests/initial_sql_regress/sql/simple.sql b/tests/initial_sql_regress/sql/simple.sql
new file mode 100644
index 0000000000..c3edb11c5a
--- /dev/null
+++ b/tests/initial_sql_regress/sql/simple.sql
@@ -0,0 +1,12 @@
+-- a comment
+INSERT INTO initial_sql_regress_simple (name) VALUES ('John'); -- another comment
+INSERT INTO initial_sql_regress_simple (name) VALUES ('-- Comment Man');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul');
+INSERT INTO
+ initial_sql_regress_simple (name) VALUES ('Ringo');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('George');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('Miles O''Brien');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('Semicolon;Man');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('"100%" of % are not placeholders');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('This line has a Windows line ending');
+
diff --git a/tests/initial_sql_regress/tests.py b/tests/initial_sql_regress/tests.py
new file mode 100644
index 0000000000..bd23aab15d
--- /dev/null
+++ b/tests/initial_sql_regress/tests.py
@@ -0,0 +1,47 @@
+from django.core.management.color import no_style
+from django.core.management.sql import custom_sql_for_model
+from django.db import connections, DEFAULT_DB_ALIAS
+from django.test import TestCase
+from django.test.utils import override_settings
+
+from .models import Simple
+
+
+class InitialSQLTests(TestCase):
+ """
+ The format of the included SQL file for this test suite is important.
+ It must end with a trailing newline in order to test the fix for #2161.
+ """
+
+ def test_initial_sql(self):
+ """
+ As pointed out by #14661, test data loaded by custom SQL
+ can't be relied upon; as a result, the test framework flushes the
+ data contents before every test. This test validates that this has
+ occurred.
+ """
+ self.assertEqual(Simple.objects.count(), 0)
+
+ def test_custom_sql(self):
+ """
+ Simulate the custom SQL loading by syncdb.
+ """
+ connection = connections[DEFAULT_DB_ALIAS]
+ custom_sql = custom_sql_for_model(Simple, no_style(), connection)
+ self.assertEqual(len(custom_sql), 9)
+ cursor = connection.cursor()
+ for sql in custom_sql:
+ cursor.execute(sql)
+ self.assertEqual(Simple.objects.count(), 9)
+ self.assertEqual(
+ Simple.objects.get(name__contains='placeholders').name,
+ '"100%" of % are not placeholders'
+ )
+
+ @override_settings(DEBUG=True)
+ def test_custom_sql_debug(self):
+ """
+ Same test, ensure that CursorDebugWrapper doesn't alter sql loading
+ (#3485).
+ """
+ self.test_custom_sql()