2020-04-15 09:20:46 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from django.core.management.color import no_style
|
|
|
|
from django.db import connection
|
|
|
|
from django.test import SimpleTestCase
|
|
|
|
|
|
|
|
from ..models import Person, Tag
|
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(connection.vendor == "postgresql", "PostgreSQL tests.")
|
|
|
|
class PostgreSQLOperationsTests(SimpleTestCase):
|
|
|
|
def test_sql_flush(self):
|
|
|
|
self.assertEqual(
|
|
|
|
connection.ops.sql_flush(
|
|
|
|
no_style(),
|
|
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
|
|
|
),
|
|
|
|
['TRUNCATE "backends_person", "backends_tag";'],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_sql_flush_allow_cascade(self):
|
|
|
|
self.assertEqual(
|
|
|
|
connection.ops.sql_flush(
|
|
|
|
no_style(),
|
|
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
|
|
|
allow_cascade=True,
|
|
|
|
),
|
|
|
|
['TRUNCATE "backends_person", "backends_tag" CASCADE;'],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_sql_flush_sequences(self):
|
|
|
|
self.assertEqual(
|
|
|
|
connection.ops.sql_flush(
|
|
|
|
no_style(),
|
|
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
2020-04-15 09:20:46 +00:00
|
|
|
reset_sequences=True,
|
2020-04-15 09:20:46 +00:00
|
|
|
),
|
2020-04-15 09:20:46 +00:00
|
|
|
['TRUNCATE "backends_person", "backends_tag" RESTART IDENTITY;'],
|
2020-04-15 09:20:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_sql_flush_sequences_allow_cascade(self):
|
|
|
|
self.assertEqual(
|
|
|
|
connection.ops.sql_flush(
|
|
|
|
no_style(),
|
|
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
2020-04-15 09:20:46 +00:00
|
|
|
reset_sequences=True,
|
2020-04-15 09:20:46 +00:00
|
|
|
allow_cascade=True,
|
|
|
|
),
|
2020-04-15 09:20:46 +00:00
|
|
|
['TRUNCATE "backends_person", "backends_tag" RESTART IDENTITY CASCADE;'],
|
2020-04-15 09:20:46 +00:00
|
|
|
)
|