From 423244bc6b670abc2b7d6896add5c1baf0b4ef2a Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 21 Jul 2012 14:24:29 +0200 Subject: Fixed #4680 -- Improved initial_sql parsing In particular, allow the '--' sequence to be present in string values without being interpreted as comment marker. Thanks Tim Chase for the report and shaleh for the initial patch. --- .../initial_sql_regress/sql/simple.sql | 6 ++++-- tests/regressiontests/initial_sql_regress/tests.py | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'tests/regressiontests/initial_sql_regress') diff --git a/tests/regressiontests/initial_sql_regress/sql/simple.sql b/tests/regressiontests/initial_sql_regress/sql/simple.sql index ca9bd40dab..18fd8a401e 100644 --- a/tests/regressiontests/initial_sql_regress/sql/simple.sql +++ b/tests/regressiontests/initial_sql_regress/sql/simple.sql @@ -1,8 +1,10 @@ -INSERT INTO initial_sql_regress_simple (name) VALUES ('John'); +-- 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 ('This line has a Windows line ending'); +INSERT INTO initial_sql_regress_simple (name) VALUES ('This line has a Windows line ending'); diff --git a/tests/regressiontests/initial_sql_regress/tests.py b/tests/regressiontests/initial_sql_regress/tests.py index 815b75a9bb..03a91cb807 100644 --- a/tests/regressiontests/initial_sql_regress/tests.py +++ b/tests/regressiontests/initial_sql_regress/tests.py @@ -4,12 +4,26 @@ from .models import Simple class InitialSQLTests(TestCase): - def test_initial_sql(self): - # 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. + # 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. - # However, as pointed out by #14661, test data loaded by custom SQL + 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): + from django.core.management.sql import custom_sql_for_model + from django.core.management.color import no_style + from django.db import connections, DEFAULT_DB_ALIAS + + # 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), 8) + cursor = connection.cursor() + for sql in custom_sql: + cursor.execute(sql) + self.assertEqual(Simple.objects.count(), 8) -- cgit v1.3 From 9ecd978e269f28f711080fa66e47c84e6ff08d90 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 21 Jul 2012 15:38:24 +0200 Subject: Re-added Windows line ending stripped in previous commit Thanks Aymeric Augustin for noticing the issue. --- tests/regressiontests/initial_sql_regress/sql/simple.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/regressiontests/initial_sql_regress') diff --git a/tests/regressiontests/initial_sql_regress/sql/simple.sql b/tests/regressiontests/initial_sql_regress/sql/simple.sql index 18fd8a401e..39363baa9a 100644 --- a/tests/regressiontests/initial_sql_regress/sql/simple.sql +++ b/tests/regressiontests/initial_sql_regress/sql/simple.sql @@ -6,5 +6,5 @@ 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 ('This line has a Windows line ending'); +INSERT INTO initial_sql_regress_simple (name) VALUES ('This line has a Windows line ending'); -- cgit v1.3