Ticket #10594: fix_null_geometry_querysets_with_tests.diff
File fix_null_geometry_querysets_with_tests.diff, 3.0 KB (added by , 15 years ago) |
---|
-
django/contrib/gis/db/models/sql/query.py
233 233 extra selection objects into Geometry and Distance objects. 234 234 TODO: Make converted objects 'lazy' for less overhead. 235 235 """ 236 if value == None: 237 return value 238 236 239 if SpatialBackend.oracle: 237 240 # Running through Oracle's first. 238 241 value = super(GeoQuery, self).convert_values(value, field or GeomField()) -
django/contrib/gis/tests/distapp/tests.py
8 8 from django.contrib.gis.tests.utils import oracle, postgis, spatialite, no_oracle, no_spatialite 9 9 10 10 from models import AustraliaCity, Interstate, SouthTexasInterstate, \ 11 SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode 11 SouthTexasCity, SouthTexasCityFt, CensusZipcode, SouthTexasZipcode, NullPointModel 12 12 from data import au_cities, interstates, stx_interstates, stx_cities, stx_zips 13 13 14 14 class DistanceTest(unittest.TestCase): … … 203 203 for i, z in enumerate(qs): 204 204 self.assertAlmostEqual(z.distance.m, dists_m[i], 5) 205 205 206 def test03d_distance_method(self): 207 "Testing the `distance` GeoQuerySet method with null geometries in models" 208 # Ensure that null geometry fields in distance method lookups don't kill the 209 # querysets (ticket #10594) 210 null = NullPointModel.objects.create(name="Null") 211 notnull = NullPointModel.objects.create(name="Not null", point=Point(0, 0)) 212 qs = NullPointModel.objects.distance(Point(0, 0)) 213 self.assertTrue(null in qs) 214 self.assertTrue(notnull in qs) 215 for obj in qs: 216 if obj.name == "Null": 217 self.assertEquals(obj.distance, None) 218 elif obj.name == "Not null": 219 self.assertEquals(obj.distance.m, 0) 220 206 221 def test04_distance_lookups(self): 207 222 "Testing the `distance_lt`, `distance_gt`, `distance_lte`, and `distance_gte` lookup types." 208 223 # Retrieving the cities within a 20km 'donut' w/a 7km radius 'hole' -
django/contrib/gis/tests/distapp/models.py
47 47 path = models.LineStringField(srid=32140) 48 48 objects = models.GeoManager() 49 49 def __unicode__(self): return self.name 50 51 class NullPointModel(models.Model): 52 name = models.CharField(max_length=30) 53 point = models.PointField(null=True) 54 objects = models.GeoManager() 55 def __unicode__(self): return self.name