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
|
|
|
|
|
2020-04-15 09:20:46 +00:00
|
|
|
from ..models import Person, Tag
|
2020-04-15 09:20:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(connection.vendor == 'mysql', 'MySQL tests.')
|
|
|
|
class MySQLOperationsTests(SimpleTestCase):
|
|
|
|
def test_sql_flush(self):
|
|
|
|
# allow_cascade doesn't change statements on MySQL.
|
|
|
|
for allow_cascade in [False, True]:
|
|
|
|
with self.subTest(allow_cascade=allow_cascade):
|
|
|
|
self.assertEqual(
|
2020-04-15 09:20:46 +00:00
|
|
|
connection.ops.sql_flush(
|
|
|
|
no_style(),
|
|
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
|
|
|
allow_cascade=allow_cascade,
|
|
|
|
),
|
2020-04-15 09:20:46 +00:00
|
|
|
[
|
2020-04-15 09:20:46 +00:00
|
|
|
'SET FOREIGN_KEY_CHECKS = 0;',
|
2020-04-15 09:20:46 +00:00
|
|
|
'DELETE FROM `backends_person`;',
|
|
|
|
'DELETE FROM `backends_tag`;',
|
2020-04-15 09:20:46 +00:00
|
|
|
'SET FOREIGN_KEY_CHECKS = 1;',
|
2020-04-15 09:20:46 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_sql_flush_sequences(self):
|
|
|
|
# allow_cascade doesn't change statements on MySQL.
|
|
|
|
for allow_cascade in [False, True]:
|
|
|
|
with self.subTest(allow_cascade=allow_cascade):
|
|
|
|
self.assertEqual(
|
2020-04-15 09:20:46 +00:00
|
|
|
connection.ops.sql_flush(
|
|
|
|
no_style(),
|
|
|
|
[Person._meta.db_table, Tag._meta.db_table],
|
|
|
|
reset_sequences=True,
|
|
|
|
allow_cascade=allow_cascade,
|
|
|
|
),
|
2020-04-15 09:20:46 +00:00
|
|
|
[
|
2020-04-15 09:20:46 +00:00
|
|
|
'SET FOREIGN_KEY_CHECKS = 0;',
|
2020-04-15 09:20:46 +00:00
|
|
|
'TRUNCATE `backends_person`;',
|
|
|
|
'TRUNCATE `backends_tag`;',
|
2020-04-15 09:20:46 +00:00
|
|
|
'SET FOREIGN_KEY_CHECKS = 1;',
|
2020-04-15 09:20:46 +00:00
|
|
|
],
|
|
|
|
)
|