summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-08-04 06:35:13 +0200
committerGitHub <noreply@github.com>2023-08-04 06:35:13 +0200
commit2b582387d51c44fa928351ca55f05fc8b8d2986e (patch)
tree79eb0423530ab2a9ce8dbdbd20431bab073a5b71 /tests
parentf46a6b2816819ed12d4d0150c99d66920070ca15 (diff)
Fixed #34760 -- Dropped support for SQLite < 3.27.
Diffstat (limited to 'tests')
-rw-r--r--tests/backends/sqlite/tests.py48
-rw-r--r--tests/migrations/test_operations.py29
-rw-r--r--tests/schema/tests.py19
3 files changed, 17 insertions, 79 deletions
diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py
index 88b514270a..2b728f8409 100644
--- a/tests/backends/sqlite/tests.py
+++ b/tests/backends/sqlite/tests.py
@@ -7,17 +7,12 @@ from pathlib import Path
from unittest import mock
from django.db import NotSupportedError, connection, transaction
-from django.db.models import Aggregate, Avg, CharField, StdDev, Sum, Variance
+from django.db.models import Aggregate, Avg, StdDev, Sum, Variance
from django.db.utils import ConnectionHandler
-from django.test import (
- TestCase,
- TransactionTestCase,
- override_settings,
- skipIfDBFeature,
-)
+from django.test import TestCase, TransactionTestCase, override_settings
from django.test.utils import isolate_apps
-from ..models import Author, Item, Object, Square
+from ..models import Item, Object, Square
@unittest.skipUnless(connection.vendor == "sqlite", "SQLite tests")
@@ -106,9 +101,9 @@ class Tests(TestCase):
connections["default"].close()
self.assertTrue(os.path.isfile(os.path.join(tmp, "test.db")))
- @mock.patch.object(connection, "get_database_version", return_value=(3, 20))
+ @mock.patch.object(connection, "get_database_version", return_value=(3, 26))
def test_check_database_version_supported(self, mocked_get_database_version):
- msg = "SQLite 3.21 or later is required (found 3.20)."
+ msg = "SQLite 3.27 or later is required (found 3.26)."
with self.assertRaisesMessage(NotSupportedError, msg):
connection.check_database_version_supported()
self.assertTrue(mocked_get_database_version.called)
@@ -167,39 +162,6 @@ class SchemaTests(TransactionTestCase):
self.assertFalse(constraint_checks_enabled())
self.assertTrue(constraint_checks_enabled())
- @skipIfDBFeature("supports_atomic_references_rename")
- def test_field_rename_inside_atomic_block(self):
- """
- NotImplementedError is raised when a model field rename is attempted
- inside an atomic block.
- """
- new_field = CharField(max_length=255, unique=True)
- new_field.set_attributes_from_name("renamed")
- msg = (
- "Renaming the 'backends_author'.'name' column while in a "
- "transaction is not supported on SQLite < 3.26 because it would "
- "break referential integrity. Try adding `atomic = False` to the "
- "Migration class."
- )
- with self.assertRaisesMessage(NotSupportedError, msg):
- with connection.schema_editor(atomic=True) as editor:
- editor.alter_field(Author, Author._meta.get_field("name"), new_field)
-
- @skipIfDBFeature("supports_atomic_references_rename")
- def test_table_rename_inside_atomic_block(self):
- """
- NotImplementedError is raised when a table rename is attempted inside
- an atomic block.
- """
- msg = (
- "Renaming the 'backends_author' table while in a transaction is "
- "not supported on SQLite < 3.26 because it would break referential "
- "integrity. Try adding `atomic = False` to the Migration class."
- )
- with self.assertRaisesMessage(NotSupportedError, msg):
- with connection.schema_editor(atomic=True) as editor:
- editor.alter_db_table(Author, "backends_author", "renamed_table")
-
@unittest.skipUnless(connection.vendor == "sqlite", "Test only for SQLite")
@override_settings(DEBUG=True)
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 58213ff642..617bd3d7b0 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -805,10 +805,7 @@ class OperationTests(OperationTestBase):
)
# Migrate forwards
new_state = project_state.clone()
- atomic_rename = connection.features.supports_atomic_references_rename
- new_state = self.apply_operations(
- "test_rnmo", new_state, [operation], atomic=atomic_rename
- )
+ new_state = self.apply_operations("test_rnmo", new_state, [operation])
# Test new state and database
self.assertNotIn(("test_rnmo", "pony"), new_state.models)
self.assertIn(("test_rnmo", "horse"), new_state.models)
@@ -828,7 +825,7 @@ class OperationTests(OperationTestBase):
)
# Migrate backwards
original_state = self.unapply_operations(
- "test_rnmo", project_state, [operation], atomic=atomic_rename
+ "test_rnmo", project_state, [operation]
)
# Test original state and database
self.assertIn(("test_rnmo", "pony"), original_state.models)
@@ -907,8 +904,7 @@ class OperationTests(OperationTestBase):
self.assertFKNotExists(
"test_rmwsrf_rider", ["friend_id"], ("test_rmwsrf_horserider", "id")
)
- atomic_rename = connection.features.supports_atomic_references_rename
- with connection.schema_editor(atomic=atomic_rename) as editor:
+ with connection.schema_editor() as editor:
operation.database_forwards("test_rmwsrf", editor, project_state, new_state)
self.assertTableNotExists("test_rmwsrf_rider")
self.assertTableExists("test_rmwsrf_horserider")
@@ -922,7 +918,7 @@ class OperationTests(OperationTestBase):
("test_rmwsrf_horserider", "id"),
)
# And test reversal
- with connection.schema_editor(atomic=atomic_rename) as editor:
+ with connection.schema_editor() as editor:
operation.database_backwards(
"test_rmwsrf", editor, new_state, project_state
)
@@ -972,9 +968,7 @@ class OperationTests(OperationTestBase):
self.assertFKNotExists(
"test_rmwsc_rider", ["pony_id"], ("test_rmwsc_shetlandpony", "id")
)
- with connection.schema_editor(
- atomic=connection.features.supports_atomic_references_rename
- ) as editor:
+ with connection.schema_editor() as editor:
operation.database_forwards("test_rmwsc", editor, project_state, new_state)
# Now we have a little horse table, not shetland pony
self.assertTableNotExists("test_rmwsc_shetlandpony")
@@ -1031,7 +1025,6 @@ class OperationTests(OperationTestBase):
operations=[
migrations.RenameModel("ReflexivePony", "ReflexivePony2"),
],
- atomic=connection.features.supports_atomic_references_rename,
)
Pony = project_state.apps.get_model(app_label, "ReflexivePony2")
pony = Pony.objects.create()
@@ -1070,7 +1063,6 @@ class OperationTests(OperationTestBase):
operations=[
migrations.RenameModel("Pony", "Pony2"),
],
- atomic=connection.features.supports_atomic_references_rename,
)
Pony = project_state.apps.get_model(app_label, "Pony2")
Rider = project_state.apps.get_model(app_label, "Rider")
@@ -1125,7 +1117,6 @@ class OperationTests(OperationTestBase):
app_label_2,
project_state,
operations=[migrations.RenameModel("Rider", "Pony")],
- atomic=connection.features.supports_atomic_references_rename,
)
m2m_table = f"{app_label_2}_pony_riders"
@@ -1146,7 +1137,6 @@ class OperationTests(OperationTestBase):
app_label_2,
project_state_2,
operations=[migrations.RenameModel("Rider", "Pony")],
- atomic=connection.features.supports_atomic_references_rename,
)
m2m_table = f"{app_label_2}_rider_riders"
self.assertColumnExists(m2m_table, "to_rider_id")
@@ -1178,7 +1168,6 @@ class OperationTests(OperationTestBase):
app_label,
project_state,
operations=[migrations.RenameModel("Pony", "PinkPony")],
- atomic=connection.features.supports_atomic_references_rename,
)
Pony = new_state.apps.get_model(app_label, "PinkPony")
Rider = new_state.apps.get_model(app_label, "Rider")
@@ -1219,7 +1208,6 @@ class OperationTests(OperationTestBase):
operations=[
migrations.RenameModel("Rider", "Rider2"),
],
- atomic=connection.features.supports_atomic_references_rename,
)
Pony = project_state.apps.get_model(app_label, "Pony")
Rider = project_state.apps.get_model(app_label, "Rider2")
@@ -1341,7 +1329,6 @@ class OperationTests(OperationTestBase):
),
migrations.RenameModel(old_name="Rider", new_name="Jockey"),
],
- atomic=connection.features.supports_atomic_references_rename,
)
Pony = project_state.apps.get_model(app_label, "Pony")
Jockey = project_state.apps.get_model(app_label, "Jockey")
@@ -2042,13 +2029,12 @@ class OperationTests(OperationTestBase):
second_state = first_state.clone()
operation = migrations.AlterModelTable(name="pony", table=None)
operation.state_forwards(app_label, second_state)
- atomic_rename = connection.features.supports_atomic_references_rename
- with connection.schema_editor(atomic=atomic_rename) as editor:
+ with connection.schema_editor() as editor:
operation.database_forwards(app_label, editor, first_state, second_state)
self.assertTableExists(new_m2m_table)
self.assertTableNotExists(original_m2m_table)
# And test reversal
- with connection.schema_editor(atomic=atomic_rename) as editor:
+ with connection.schema_editor() as editor:
operation.database_backwards(app_label, editor, second_state, first_state)
self.assertTableExists(original_m2m_table)
self.assertTableNotExists(new_m2m_table)
@@ -2988,7 +2974,6 @@ class OperationTests(OperationTestBase):
"Pony", "id", models.CharField(primary_key=True, max_length=99)
),
],
- atomic=connection.features.supports_atomic_references_rename,
)
def test_rename_field(self):
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index aff7b08bd9..9f620331bc 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2075,9 +2075,7 @@ class SchemaTests(TransactionTestCase):
editor.create_model(Book)
new_field = CharField(max_length=255, unique=True)
new_field.set_attributes_from_name("renamed")
- with connection.schema_editor(
- atomic=connection.features.supports_atomic_references_rename
- ) as editor:
+ with connection.schema_editor() as editor:
editor.alter_field(Author, Author._meta.get_field("name"), new_field)
# Ensure the foreign key reference was updated.
self.assertForeignKeyExists(Book, "author_id", "schema_author", "renamed")
@@ -2122,9 +2120,7 @@ class SchemaTests(TransactionTestCase):
new_field = IntegerField(db_default=1985)
new_field.set_attributes_from_name("renamed_year")
new_field.model = AuthorDbDefault
- with connection.schema_editor(
- atomic=connection.features.supports_atomic_references_rename
- ) as editor:
+ with connection.schema_editor() as editor:
editor.alter_field(AuthorDbDefault, old_field, new_field, strict=True)
columns = self.column_classes(AuthorDbDefault)
self.assertEqual(columns["renamed_year"][1].default, "1985")
@@ -3550,9 +3546,7 @@ class SchemaTests(TransactionTestCase):
connection.features.introspected_field_types["CharField"],
)
# Alter the table
- with connection.schema_editor(
- atomic=connection.features.supports_atomic_references_rename
- ) as editor:
+ with connection.schema_editor() as editor:
editor.alter_db_table(Author, "schema_author", "schema_otherauthor")
Author._meta.db_table = "schema_otherauthor"
columns = self.column_classes(Author)
@@ -3563,9 +3557,7 @@ class SchemaTests(TransactionTestCase):
# Ensure the foreign key reference was updated
self.assertForeignKeyExists(Book, "author_id", "schema_otherauthor")
# Alter the table again
- with connection.schema_editor(
- atomic=connection.features.supports_atomic_references_rename
- ) as editor:
+ with connection.schema_editor() as editor:
editor.alter_db_table(Author, "schema_otherauthor", "schema_author")
# Ensure the table is still there
Author._meta.db_table = "schema_author"
@@ -5130,8 +5122,7 @@ class SchemaTests(TransactionTestCase):
editor.add_field(Book, author)
def test_rename_table_renames_deferred_sql_references(self):
- atomic_rename = connection.features.supports_atomic_references_rename
- with connection.schema_editor(atomic=atomic_rename) as editor:
+ with connection.schema_editor() as editor:
editor.create_model(Author)
editor.create_model(Book)
editor.alter_db_table(Author, "schema_author", "schema_renamed_author")