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 == "postgresql", "PostgreSQL tests.")
    
  11. class PostgreSQLOperationsTests(SimpleTestCase):
    
  12.     def test_sql_flush(self):
    
  13.         self.assertEqual(
    
  14.             connection.ops.sql_flush(
    
  15.                 no_style(),
    
  16.                 [Person._meta.db_table, Tag._meta.db_table],
    
  17.             ),
    
  18.             ['TRUNCATE "backends_person", "backends_tag";'],
    
  19.         )
    
  20. 
    
  21.     def test_sql_flush_allow_cascade(self):
    
  22.         self.assertEqual(
    
  23.             connection.ops.sql_flush(
    
  24.                 no_style(),
    
  25.                 [Person._meta.db_table, Tag._meta.db_table],
    
  26.                 allow_cascade=True,
    
  27.             ),
    
  28.             ['TRUNCATE "backends_person", "backends_tag" CASCADE;'],
    
  29.         )
    
  30. 
    
  31.     def test_sql_flush_sequences(self):
    
  32.         self.assertEqual(
    
  33.             connection.ops.sql_flush(
    
  34.                 no_style(),
    
  35.                 [Person._meta.db_table, Tag._meta.db_table],
    
  36.                 reset_sequences=True,
    
  37.             ),
    
  38.             ['TRUNCATE "backends_person", "backends_tag" RESTART IDENTITY;'],
    
  39.         )
    
  40. 
    
  41.     def test_sql_flush_sequences_allow_cascade(self):
    
  42.         self.assertEqual(
    
  43.             connection.ops.sql_flush(
    
  44.                 no_style(),
    
  45.                 [Person._meta.db_table, Tag._meta.db_table],
    
  46.                 reset_sequences=True,
    
  47.                 allow_cascade=True,
    
  48.             ),
    
  49.             ['TRUNCATE "backends_person", "backends_tag" RESTART IDENTITY CASCADE;'],
    
  50.         )