Code

Ticket #4680: 4680-test.diff

File 4680-test.diff, 2.4 KB (added by claudep, 2 years ago)

Just a test case demonstrating the issue is still present

Line 
1diff --git a/tests/regressiontests/initial_sql_regress/sql/simple.sql b/tests/regressiontests/initial_sql_regress/sql/simple.sql
2index ca9bd40..ef2be49 100644
3--- a/tests/regressiontests/initial_sql_regress/sql/simple.sql
4+++ b/tests/regressiontests/initial_sql_regress/sql/simple.sql
5@@ -1,4 +1,6 @@
6-INSERT INTO initial_sql_regress_simple (name) VALUES ('John');
7+-- a comment
8+INSERT INTO initial_sql_regress_simple (name) VALUES ('John'); -- another comment
9+INSERT INTO initial_sql_regress_simple (name) VALUES ('-- Comment Man');
10 INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul');
11 INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo');
12 INSERT INTO initial_sql_regress_simple (name) VALUES ('George');
13diff --git a/tests/regressiontests/initial_sql_regress/tests.py b/tests/regressiontests/initial_sql_regress/tests.py
14index 815b75a..03a91cb 100644
15--- a/tests/regressiontests/initial_sql_regress/tests.py
16+++ b/tests/regressiontests/initial_sql_regress/tests.py
17@@ -4,12 +4,26 @@ from .models import Simple
18 
19 
20 class InitialSQLTests(TestCase):
21-    def test_initial_sql(self):
22-        # The format of the included SQL file for this test suite is important.
23-        # It must end with a trailing newline in order to test the fix for #2161.
24+    # The format of the included SQL file for this test suite is important.
25+    # It must end with a trailing newline in order to test the fix for #2161.
26 
27-        # However, as pointed out by #14661, test data loaded by custom SQL
28+    def test_initial_sql(self):
29+        # As pointed out by #14661, test data loaded by custom SQL
30         # can't be relied upon; as a result, the test framework flushes the
31         # data contents before every test. This test validates that this has
32         # occurred.
33         self.assertEqual(Simple.objects.count(), 0)
34+
35+    def test_custom_sql(self):
36+        from django.core.management.sql import custom_sql_for_model
37+        from django.core.management.color import no_style
38+        from django.db import connections, DEFAULT_DB_ALIAS
39+
40+        # Simulate the custom SQL loading by syncdb
41+        connection = connections[DEFAULT_DB_ALIAS]
42+        custom_sql = custom_sql_for_model(Simple, no_style(), connection)
43+        self.assertEqual(len(custom_sql), 8)
44+        cursor = connection.cursor()
45+        for sql in custom_sql:
46+            cursor.execute(sql)
47+        self.assertEqual(Simple.objects.count(), 8)