mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Added test coverage for DatabaseOperations.sql_flush().
This commit is contained in:
parent
eeab63e57e
commit
8bcca47e83
5 changed files with 416 additions and 2 deletions
94
tests/backends/sqlite/test_operations.py
Normal file
94
tests/backends/sqlite/test_operations.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
import unittest
|
||||
|
||||
from django.core.management.color import no_style
|
||||
from django.db import connection
|
||||
from django.test import TestCase
|
||||
|
||||
from ..models import Person, Tag
|
||||
|
||||
|
||||
@unittest.skipUnless(connection.vendor == 'sqlite', 'SQLite tests.')
|
||||
class SQLiteOperationsTests(TestCase):
|
||||
def test_sql_flush(self):
|
||||
self.assertEqual(
|
||||
connection.ops.sql_flush(
|
||||
no_style(),
|
||||
[Person._meta.db_table, Tag._meta.db_table],
|
||||
[],
|
||||
),
|
||||
[
|
||||
'DELETE FROM "backends_person";',
|
||||
'DELETE FROM "backends_tag";',
|
||||
],
|
||||
)
|
||||
|
||||
def test_sql_flush_allow_cascade(self):
|
||||
statements = connection.ops.sql_flush(
|
||||
no_style(),
|
||||
[Person._meta.db_table, Tag._meta.db_table],
|
||||
[],
|
||||
allow_cascade=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
# The tables are processed in an unordered set.
|
||||
sorted(statements),
|
||||
[
|
||||
'DELETE FROM "backends_person";',
|
||||
'DELETE FROM "backends_tag";',
|
||||
'DELETE FROM "backends_verylongmodelnamezzzzzzzzzzzzzzzzzzzzzz'
|
||||
'zzzzzzzzzzzzzzzzzzzz_m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzz'
|
||||
'zzzzzzzzzzzzzzzzzzzzzzz";',
|
||||
],
|
||||
)
|
||||
|
||||
def test_sql_flush_sequences(self):
|
||||
# sequences doesn't change statements on SQLite.
|
||||
self.assertEqual(
|
||||
connection.ops.sql_flush(
|
||||
no_style(),
|
||||
[Person._meta.db_table, Tag._meta.db_table],
|
||||
[
|
||||
{
|
||||
'table': Person._meta.db_table,
|
||||
'column': Person._meta.pk.db_column,
|
||||
},
|
||||
{
|
||||
'table': Tag._meta.db_table,
|
||||
'column': Tag._meta.pk.db_column,
|
||||
},
|
||||
],
|
||||
),
|
||||
[
|
||||
'DELETE FROM "backends_person";',
|
||||
'DELETE FROM "backends_tag";',
|
||||
],
|
||||
)
|
||||
|
||||
def test_sql_flush_sequences_allow_cascade(self):
|
||||
# sequences doesn't change statements on SQLite.
|
||||
statements = connection.ops.sql_flush(
|
||||
no_style(),
|
||||
[Person._meta.db_table, Tag._meta.db_table],
|
||||
[
|
||||
{
|
||||
'table': Person._meta.db_table,
|
||||
'column': Person._meta.pk.db_column,
|
||||
},
|
||||
{
|
||||
'table': Tag._meta.db_table,
|
||||
'column': Tag._meta.pk.db_column,
|
||||
},
|
||||
],
|
||||
allow_cascade=True,
|
||||
)
|
||||
self.assertEqual(
|
||||
# The tables are processed in an unordered set.
|
||||
sorted(statements),
|
||||
[
|
||||
'DELETE FROM "backends_person";',
|
||||
'DELETE FROM "backends_tag";',
|
||||
'DELETE FROM "backends_verylongmodelnamezzzzzzzzzzzzzzzzzzzzzz'
|
||||
'zzzzzzzzzzzzzzzzzzzz_m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzz'
|
||||
'zzzzzzzzzzzzzzzzzzzzzzz";',
|
||||
],
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue