Ticket #4680: 4680-test.diff

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

Just a test case demonstrating the issue is still present

  • tests/regressiontests/initial_sql_regress/sql/simple.sql

    diff --git a/tests/regressiontests/initial_sql_regress/sql/simple.sql b/tests/regressiontests/initial_sql_regress/sql/simple.sql
    index ca9bd40..ef2be49 100644
    a b  
    1 INSERT INTO initial_sql_regress_simple (name) VALUES ('John');
     1-- a comment
     2INSERT INTO initial_sql_regress_simple (name) VALUES ('John'); -- another comment
     3INSERT INTO initial_sql_regress_simple (name) VALUES ('-- Comment Man');
    24INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul');
    35INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo');
    46INSERT INTO initial_sql_regress_simple (name) VALUES ('George');
  • tests/regressiontests/initial_sql_regress/tests.py

    diff --git a/tests/regressiontests/initial_sql_regress/tests.py b/tests/regressiontests/initial_sql_regress/tests.py
    index 815b75a..03a91cb 100644
    a b from .models import Simple 
    44
    55
    66class InitialSQLTests(TestCase):
    7     def test_initial_sql(self):
    8         # The format of the included SQL file for this test suite is important.
    9         # It must end with a trailing newline in order to test the fix for #2161.
     7    # The format of the included SQL file for this test suite is important.
     8    # It must end with a trailing newline in order to test the fix for #2161.
    109
    11         # However, as pointed out by #14661, test data loaded by custom SQL
     10    def test_initial_sql(self):
     11        # As pointed out by #14661, test data loaded by custom SQL
    1212        # can't be relied upon; as a result, the test framework flushes the
    1313        # data contents before every test. This test validates that this has
    1414        # occurred.
    1515        self.assertEqual(Simple.objects.count(), 0)
     16
     17    def test_custom_sql(self):
     18        from django.core.management.sql import custom_sql_for_model
     19        from django.core.management.color import no_style
     20        from django.db import connections, DEFAULT_DB_ALIAS
     21
     22        # Simulate the custom SQL loading by syncdb
     23        connection = connections[DEFAULT_DB_ALIAS]
     24        custom_sql = custom_sql_for_model(Simple, no_style(), connection)
     25        self.assertEqual(len(custom_sql), 8)
     26        cursor = connection.cursor()
     27        for sql in custom_sql:
     28            cursor.execute(sql)
     29        self.assertEqual(Simple.objects.count(), 8)
Back to Top