From 75866b93cc285c87cfc764a32d081493b19c1dc5 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 18 Apr 2020 09:38:42 -0700 Subject: Fixed #31479 -- Added support to reset sequences on SQLite. --- tests/backends/sqlite/test_operations.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'tests/backends/sqlite') diff --git a/tests/backends/sqlite/test_operations.py b/tests/backends/sqlite/test_operations.py index 0ee70061f8..863a978580 100644 --- a/tests/backends/sqlite/test_operations.py +++ b/tests/backends/sqlite/test_operations.py @@ -40,7 +40,6 @@ class SQLiteOperationsTests(TestCase): ) def test_sql_flush_sequences(self): - # sequences doesn't change statements on SQLite. self.assertEqual( connection.ops.sql_flush( no_style(), @@ -50,11 +49,12 @@ class SQLiteOperationsTests(TestCase): [ 'DELETE FROM "backends_person";', 'DELETE FROM "backends_tag";', + 'UPDATE "sqlite_sequence" SET "seq" = 0 WHERE "name" IN ' + '(\'backends_person\', \'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], @@ -63,7 +63,7 @@ class SQLiteOperationsTests(TestCase): ) self.assertEqual( # The tables are processed in an unordered set. - sorted(statements), + sorted(statements[:-1]), [ 'DELETE FROM "backends_person";', 'DELETE FROM "backends_tag";', @@ -72,3 +72,14 @@ class SQLiteOperationsTests(TestCase): 'zzzzzzzzzzzzzzzzzzzzzzz";', ], ) + self.assertIs(statements[-1].startswith( + 'UPDATE "sqlite_sequence" SET "seq" = 0 WHERE "name" IN (' + ), True) + self.assertIn("'backends_person'", statements[-1]) + self.assertIn("'backends_tag'", statements[-1]) + self.assertIn( + "'backends_verylongmodelnamezzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzz_m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzz'", + statements[-1], + ) -- cgit v1.3