mirror of
https://github.com/django/django.git
synced 2024-12-26 02:56:25 +00:00
75410228df
The sql_flush() positional argument sequences is replaced by the boolean keyword-only argument reset_sequences. This ensures that the old function signature can't be used by mistake when upgrading Django. When the new argument is True, the sequences of the truncated tables will reset. Using a single boolean value, rather than a list, allows making a binary yes/no choice as to whether to reset all sequences rather than a working on a completely different set.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
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],
|
|
reset_sequences=True,
|
|
),
|
|
['TRUNCATE "backends_person", "backends_tag" RESTART IDENTITY;'],
|
|
)
|
|
|
|
def test_sql_flush_sequences_allow_cascade(self):
|
|
self.assertEqual(
|
|
connection.ops.sql_flush(
|
|
no_style(),
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
|
reset_sequences=True,
|
|
allow_cascade=True,
|
|
),
|
|
['TRUNCATE "backends_person", "backends_tag" RESTART IDENTITY CASCADE;'],
|
|
)
|