1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #33379 -- Added minimum database version checks.

Thanks Tim Graham for the review.
This commit is contained in:
Hasan Ramezani
2021-12-27 19:04:59 +01:00
committed by Mariusz Felisiak
parent 737542390a
commit 9ac3ef59f9
16 changed files with 166 additions and 41 deletions

View File

@@ -4,10 +4,8 @@ import tempfile
import threading
import unittest
from pathlib import Path
from sqlite3 import dbapi2
from unittest import mock
from django.core.exceptions import ImproperlyConfigured
from django.db import NotSupportedError, connection, transaction
from django.db.models import Aggregate, Avg, CharField, StdDev, Sum, Variance
from django.db.utils import ConnectionHandler
@@ -21,28 +19,11 @@ from django.test.utils import isolate_apps
from ..models import Author, Item, Object, Square
try:
from django.db.backends.sqlite3.base import check_sqlite_version
except ImproperlyConfigured:
# Ignore "SQLite is too old" when running tests on another database.
pass
@unittest.skipUnless(connection.vendor == "sqlite", "SQLite tests")
class Tests(TestCase):
longMessage = True
def test_check_sqlite_version(self):
msg = "SQLite 3.9.0 or later is required (found 3.8.11.1)."
with mock.patch.object(
dbapi2, "sqlite_version_info", (3, 8, 11, 1)
), mock.patch.object(
dbapi2, "sqlite_version", "3.8.11.1"
), self.assertRaisesMessage(
ImproperlyConfigured, msg
):
check_sqlite_version()
def test_aggregation(self):
"""Raise NotSupportedError when aggregating on date/time fields."""
for aggregate in (Sum, Avg, Variance, StdDev):
@@ -125,6 +106,13 @@ 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, 8))
def test_check_database_version_supported(self, mocked_get_database_version):
msg = "SQLite 3.9 or later is required (found 3.8)."
with self.assertRaisesMessage(NotSupportedError, msg):
connection.check_database_version_supported()
self.assertTrue(mocked_get_database_version.called)
@unittest.skipUnless(connection.vendor == "sqlite", "SQLite tests")
@isolate_apps("backends")