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

Added error messages for GIS DB functions when used with rasters.

This commit is contained in:
Daniel Wiesmann
2016-08-15 18:21:12 +01:00
committed by Tim Graham
parent d6b9aab37c
commit 082f5bfdbc
2 changed files with 22 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import json
from django.contrib.gis.db.models.functions import Distance
from django.contrib.gis.db.models.lookups import (
DistanceLookupBase, gis_lookups,
)
@@ -326,3 +327,18 @@ class RasterFieldTest(TransactionTestCase):
msg = "Couldn't create spatial object from lookup value '%s'." % obj
with self.assertRaisesMessage(ValueError, msg):
RasterModel.objects.filter(geom__intersects=obj)
def test_db_function_errors(self):
"""
Errors are raised when using DB functions with raster content.
"""
point = GEOSGeometry("SRID=3086;POINT (-697024.9213808845 683729.1705516104)")
rast = GDALRaster(json.loads(JSON_RASTER))
msg = "Please provide a geometry object."
with self.assertRaisesMessage(TypeError, msg):
RasterModel.objects.annotate(distance_from_point=Distance("geom", rast))
with self.assertRaisesMessage(TypeError, msg):
RasterModel.objects.annotate(distance_from_point=Distance("rastprojected", rast))
msg = "Geometry functions not supported for raster fields."
with self.assertRaisesMessage(TypeError, msg):
RasterModel.objects.annotate(distance_from_point=Distance("rastprojected", point)).count()