From 5afd8c69404d718d254399fb5804efe0aa24fa8a Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 21 Feb 2023 08:42:28 +0100 Subject: [PATCH] Refs #16969 -- Added test for not initializing PostGIS-specific stuff for non-db connections. --- tests/gis_tests/tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/gis_tests/tests.py b/tests/gis_tests/tests.py index 9da2b4df99..ba084c636d 100644 --- a/tests/gis_tests/tests.py +++ b/tests/gis_tests/tests.py @@ -2,6 +2,7 @@ import unittest from django.core.exceptions import ImproperlyConfigured from django.db import ProgrammingError +from django.db.backends.base.base import NO_DB_ALIAS try: from django.contrib.gis.db.backends.postgis.operations import PostGISOperations @@ -83,3 +84,18 @@ class TestPostGISVersionCheck(unittest.TestCase): ops = FakePostGISOperations() with self.assertRaises(ImproperlyConfigured): ops.spatial_version + + +@unittest.skipUnless(HAS_POSTGRES, "PostGIS-specific tests.") +class TestPostGISBackend(unittest.TestCase): + def test_non_db_connection_classes(self): + from django.contrib.gis.db.backends.postgis.base import DatabaseWrapper + from django.db.backends.postgresql.features import DatabaseFeatures + from django.db.backends.postgresql.introspection import DatabaseIntrospection + from django.db.backends.postgresql.operations import DatabaseOperations + + wrapper = DatabaseWrapper(settings_dict={}, alias=NO_DB_ALIAS) + # PostGIS-specific stuff is not initialized for non-db connections. + self.assertIs(wrapper.features_class, DatabaseFeatures) + self.assertIs(wrapper.ops_class, DatabaseOperations) + self.assertIs(wrapper.introspection_class, DatabaseIntrospection)