diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/gis_tests/distapp/models.py | 1 | ||||
| -rw-r--r-- | tests/gis_tests/distapp/tests.py | 24 |
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')), + )) + ''' ============================= |
