1. import unittest
    
  2. 
    
  3. from django.core.management.color import no_style
    
  4. from django.db import connection
    
  5. from django.test import SimpleTestCase
    
  6. 
    
  7. from ..models import Person, Tag
    
  8. 
    
  9. 
    
  10. @unittest.skipUnless(connection.vendor == "mysql", "MySQL tests.")
    
  11. class MySQLOperationsTests(SimpleTestCase):
    
  12.     def test_sql_flush(self):
    
  13.         # allow_cascade doesn't change statements on MySQL.
    
  14.         for allow_cascade in [False, True]:
    
  15.             with self.subTest(allow_cascade=allow_cascade):
    
  16.                 self.assertEqual(
    
  17.                     connection.ops.sql_flush(
    
  18.                         no_style(),
    
  19.                         [Person._meta.db_table, Tag._meta.db_table],
    
  20.                         allow_cascade=allow_cascade,
    
  21.                     ),
    
  22.                     [
    
  23.                         "SET FOREIGN_KEY_CHECKS = 0;",
    
  24.                         "DELETE FROM `backends_person`;",
    
  25.                         "DELETE FROM `backends_tag`;",
    
  26.                         "SET FOREIGN_KEY_CHECKS = 1;",
    
  27.                     ],
    
  28.                 )
    
  29. 
    
  30.     def test_sql_flush_sequences(self):
    
  31.         # allow_cascade doesn't change statements on MySQL.
    
  32.         for allow_cascade in [False, True]:
    
  33.             with self.subTest(allow_cascade=allow_cascade):
    
  34.                 self.assertEqual(
    
  35.                     connection.ops.sql_flush(
    
  36.                         no_style(),
    
  37.                         [Person._meta.db_table, Tag._meta.db_table],
    
  38.                         reset_sequences=True,
    
  39.                         allow_cascade=allow_cascade,
    
  40.                     ),
    
  41.                     [
    
  42.                         "SET FOREIGN_KEY_CHECKS = 0;",
    
  43.                         "TRUNCATE `backends_person`;",
    
  44.                         "TRUNCATE `backends_tag`;",
    
  45.                         "SET FOREIGN_KEY_CHECKS = 1;",
    
  46.                     ],
    
  47.                 )