mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
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.
This commit is contained in:
parent
32a4df6c55
commit
423244bc6b
3 changed files with 39 additions and 16 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue