summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <simon.charette@zapier.com>2019-08-17 10:32:56 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-23 21:28:28 +0200
commitbb9e82f2748ace292a584841ab9af8696df27f53 (patch)
treeda8acb9d8ca4685fe40fe2d1091c439bf66e0ab9 /tests
parent92c72b68b759d0b12d90e029f03a98c6a8f661fe (diff)
Fixed #29955 -- Added support for distance expression to the dwithin lookup.
This was missed when adding support to other distance lookups in refs #25499. Thanks Peter Bex for the report and Mariusz for testcases.
Diffstat (limited to 'tests')
-rw-r--r--tests/gis_tests/distapp/models.py1
-rw-r--r--tests/gis_tests/distapp/tests.py24
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/gis_tests/distapp/models.py b/tests/gis_tests/distapp/models.py
index fcad6fc097..1971741c54 100644
--- a/tests/gis_tests/distapp/models.py
+++ b/tests/gis_tests/distapp/models.py
@@ -28,6 +28,7 @@ class AustraliaCity(NamedModel):
"City model for Australia, using WGS84."
point = models.PointField()
radius = models.IntegerField(default=10000)
+ allowed_distance = models.FloatField(default=0.5)
class CensusZipcode(NamedModel):
diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py
index d84e829868..2cdd0e8f0e 100644
--- a/tests/gis_tests/distapp/tests.py
+++ b/tests/gis_tests/distapp/tests.py
@@ -234,6 +234,30 @@ class DistanceTest(TestCase):
).filter(annotated_value=True)
self.assertEqual(self.get_names(qs), ['77002', '77025', '77401'])
+ @skipUnlessDBFeature('supports_dwithin_lookup', 'supports_dwithin_distance_expr')
+ def test_dwithin_with_expression_rhs(self):
+ # LineString of Wollongong and Adelaide coords.
+ ls = LineString(((150.902, -34.4245), (138.6, -34.9258)), srid=4326)
+ qs = AustraliaCity.objects.filter(
+ point__dwithin=(ls, F('allowed_distance')),
+ ).order_by('name')
+ self.assertEqual(
+ self.get_names(qs),
+ ['Adelaide', 'Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong'],
+ )
+
+ @skipIfDBFeature('supports_dwithin_distance_expr')
+ def test_dwithin_with_expression_rhs_not_supported(self):
+ ls = LineString(((150.902, -34.4245), (138.6, -34.9258)), srid=4326)
+ msg = (
+ 'This backend does not support expressions for specifying '
+ 'distance in the dwithin lookup.'
+ )
+ with self.assertRaisesMessage(NotSupportedError, msg):
+ list(AustraliaCity.objects.filter(
+ point__dwithin=(ls, F('allowed_distance')),
+ ))
+
'''
=============================