diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2021-12-27 19:04:59 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-18 13:37:49 +0100 |
| commit | 9ac3ef59f9538cfb520e3607af743532434d1755 (patch) | |
| tree | 62aeb20ea258d03b49fab140b61a40d2634011ae /tests/backends/sqlite | |
| parent | 737542390af27616d93f86cd418e2d7f3e874b27 (diff) | |
Fixed #33379 -- Added minimum database version checks.
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/backends/sqlite')
| -rw-r--r-- | tests/backends/sqlite/tests.py | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py index e167e09dcf..97505eaa36 100644 --- a/tests/backends/sqlite/tests.py +++ b/tests/backends/sqlite/tests.py @@ -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") |
