diff options
| author | Claude Paroz <claude@2xlibre.net> | 2015-10-06 22:05:53 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-10-09 15:27:47 +0200 |
| commit | 37d06cfc46679759c47178a3380b12fbf22a4f25 (patch) | |
| tree | ea1c002d8bc9888c32a2a18e80ba8bcbe44f8970 /tests | |
| parent | 4a7b58210defea33a428b748ccbc97ae8fd49838 (diff) | |
Fixed #25499 -- Added the ability to pass an expression in distance lookups
Thanks Bibhas Debnath for the report and Tim Graham for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/distapp/models.py | 2 | ||||
| -rw-r--r-- | tests/gis_tests/distapp/tests.py | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/gis_tests/distapp/models.py b/tests/gis_tests/distapp/models.py index c04659f524..1632988534 100644 --- a/tests/gis_tests/distapp/models.py +++ b/tests/gis_tests/distapp/models.py @@ -21,6 +21,7 @@ class NamedModel(models.Model): class SouthTexasCity(NamedModel): "City model on projected coordinate system for South Texas." point = models.PointField(srid=32140) + radius = models.IntegerField(default=10000) class SouthTexasCityFt(NamedModel): @@ -31,6 +32,7 @@ class SouthTexasCityFt(NamedModel): class AustraliaCity(NamedModel): "City model for Australia, using WGS84." point = models.PointField() + radius = models.IntegerField(default=10000) class CensusZipcode(NamedModel): diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py index 56e4711ab7..322c8b7214 100644 --- a/tests/gis_tests/distapp/tests.py +++ b/tests/gis_tests/distapp/tests.py @@ -6,7 +6,7 @@ from django.contrib.gis.db.models.functions import ( from django.contrib.gis.geos import GEOSGeometry, LineString, Point from django.contrib.gis.measure import D # alias for Distance from django.db import connection -from django.db.models import Q +from django.db.models import F, Q from django.test import TestCase, ignore_warnings, skipUnlessDBFeature from django.utils.deprecation import RemovedInDjango20Warning @@ -323,6 +323,31 @@ class DistanceTest(TestCase): cities = self.get_names(qs) self.assertEqual(cities, ['Adelaide', 'Hobart', 'Shellharbour', 'Thirroul']) + @skipUnlessDBFeature("supports_distances_lookups") + def test_distance_lookups_with_expression_rhs(self): + qs = SouthTexasCity.objects.filter( + point__distance_lte=(self.stx_pnt, F('radius')), + ).order_by('name') + self.assertEqual( + self.get_names(qs), + ['Bellaire', 'Downtown Houston', 'Southside Place', 'West University Place'] + ) + + # With a combined expression + qs = SouthTexasCity.objects.filter( + point__distance_lte=(self.stx_pnt, F('radius') * 2), + ).order_by('name') + self.assertEqual(len(qs), 5) + self.assertIn('Pearland', self.get_names(qs)) + + # With spheroid param + if connection.features.supports_distance_geodetic: + hobart = AustraliaCity.objects.get(name='Hobart') + qs = AustraliaCity.objects.filter( + point__distance_lte=(hobart.point, F('radius') * 70, 'spheroid'), + ).order_by('name') + self.assertEqual(self.get_names(qs), ['Canberra', 'Hobart', 'Melbourne']) + @skipUnlessDBFeature("has_area_method") @ignore_warnings(category=RemovedInDjango20Warning) def test_area(self): |
