From 84ad7f34043c112a932b3ea396ebc98717bfd7e7 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 25 Jan 2021 08:40:46 +0100 Subject: [PATCH] Refs #32380 -- Added test for distance lookups with F() expression. Fixed in 5935a9aeade517aebdceea989467d2b46c44d96f. --- tests/gis_tests/distapp/models.py | 1 + tests/gis_tests/distapp/tests.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/gis_tests/distapp/models.py b/tests/gis_tests/distapp/models.py index 1971741c54..b7b60ebf38 100644 --- a/tests/gis_tests/distapp/models.py +++ b/tests/gis_tests/distapp/models.py @@ -29,6 +29,7 @@ class AustraliaCity(NamedModel): point = models.PointField() radius = models.IntegerField(default=10000) allowed_distance = models.FloatField(default=0.5) + ref_point = models.PointField(null=True) class CensusZipcode(NamedModel): diff --git a/tests/gis_tests/distapp/tests.py b/tests/gis_tests/distapp/tests.py index 571d091cb8..bb03fc20c3 100644 --- a/tests/gis_tests/distapp/tests.py +++ b/tests/gis_tests/distapp/tests.py @@ -204,10 +204,12 @@ class DistanceTest(TestCase): # 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']) + AustraliaCity.objects.update(ref_point=hobart.point) + for ref_point in [hobart.point, F('ref_point')]: + qs = AustraliaCity.objects.filter( + point__distance_lte=(ref_point, F('radius') * 70, 'spheroid'), + ).order_by('name') + self.assertEqual(self.get_names(qs), ['Canberra', 'Hobart', 'Melbourne']) # With a complex geometry expression self.assertFalse(SouthTexasCity.objects.filter(point__distance_gt=(Union('point', 'point'), 0)))