From cf1a80fc2d19f359744a20bb6cb1f0a169ef506b Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 5 Jun 2025 16:18:56 -0400 Subject: Added validation to BaseSpatialFeatures.has__function. --- tests/gis_tests/geoapp/test_functions.py | 4 ++-- tests/gis_tests/tests.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/gis_tests/geoapp/test_functions.py b/tests/gis_tests/geoapp/test_functions.py index 3e881b41dc..9844905200 100644 --- a/tests/gis_tests/geoapp/test_functions.py +++ b/tests/gis_tests/geoapp/test_functions.py @@ -559,7 +559,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase): # Exact value depends on database and version. self.assertTrue(20 <= ptown.size <= 105) - @skipUnlessDBFeature("has_NumGeom_function") + @skipUnlessDBFeature("has_NumGeometries_function") def test_num_geom(self): # Both 'countries' only have two geometries. for c in Country.objects.annotate(num_geom=functions.NumGeometries("mpoly")): @@ -576,7 +576,7 @@ class GISFunctionsTests(FuncTestMixin, TestCase): else: self.assertEqual(1, city.num_geom) - @skipUnlessDBFeature("has_NumPoint_function") + @skipUnlessDBFeature("has_NumPoints_function") def test_num_points(self): coords = [(-95.363151, 29.763374), (-95.448601, 29.713803)] Track.objects.create(name="Foo", line=LineString(coords)) diff --git a/tests/gis_tests/tests.py b/tests/gis_tests/tests.py index ba084c636d..b852ffe789 100644 --- a/tests/gis_tests/tests.py +++ b/tests/gis_tests/tests.py @@ -1,8 +1,9 @@ import unittest from django.core.exceptions import ImproperlyConfigured -from django.db import ProgrammingError +from django.db import ProgrammingError, connection from django.db.backends.base.base import NO_DB_ALIAS +from django.test import TestCase try: from django.contrib.gis.db.backends.postgis.operations import PostGISOperations @@ -12,6 +13,16 @@ except ImportError: HAS_POSTGRES = False +class BaseSpatialFeaturesTests(TestCase): + def test_invalid_has_func_function(self): + msg = ( + 'DatabaseFeatures.has_Invalid_function isn\'t valid. Is "Invalid" ' + "missing from BaseSpatialOperations.unsupported_functions?" + ) + with self.assertRaisesMessage(ValueError, msg): + connection.features.has_Invalid_function + + if HAS_POSTGRES: class FakeConnection: -- cgit v1.3