From 5456919782e5cd0b885dd383d57e187a06148307 Mon Sep 17 00:00:00 2001 From: Justin Bronn Date: Sat, 26 Apr 2008 00:36:15 +0000 Subject: [PATCH] gis: The `WKTAdaptor` needs the SRID for Oracle; now test geodetic `dwithin` lookups on Oracle. git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7464 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/gis/db/backend/adaptor.py | 3 +- django/contrib/gis/tests/distapp/tests.py | 39 ++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/django/contrib/gis/db/backend/adaptor.py b/django/contrib/gis/db/backend/adaptor.py index 1f01cb01e2..b2397e61dd 100644 --- a/django/contrib/gis/db/backend/adaptor.py +++ b/django/contrib/gis/db/backend/adaptor.py @@ -5,9 +5,10 @@ class WKTAdaptor(object): """ def __init__(self, geom): self.wkt = geom.wkt + self.srid = geom.srid def __eq__(self, other): - return self.wkt == other.wkt + return self.wkt == other.wkt and self.srid == other.srid def __str__(self): return self.wkt diff --git a/django/contrib/gis/tests/distapp/tests.py b/django/contrib/gis/tests/distapp/tests.py index 3bedb19b4c..d1fe83ebc5 100644 --- a/django/contrib/gis/tests/distapp/tests.py +++ b/django/contrib/gis/tests/distapp/tests.py @@ -41,21 +41,36 @@ class DistanceTest(unittest.TestCase): def test02_dwithin(self): "Testing the `dwithin` lookup type." - pnt = self.stx_pnt - dists = [7000, D(km=7), D(mi=4.349)] - for dist in dists: - qs = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist)) - self.assertEqual(['Downtown Houston', 'Southside Place'], self.get_cities(qs)) + # Distances -- all should be equal (except for the + # degree/meter pair in au_cities, that's somewhat + # approximate). + tx_dists = [7000, D(km=7), D(mi=4.349)] + au_dists = [(0.5, 32000), D(km=32), D(mi=19.884)] + + # Expected cities for Australia and Texas. + tx_cities = ['Downtown Houston', 'Southside Place'] + au_cities = ['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong'] - if isinstance(dist, D): - # A TypeError should be raised when trying to pass Distance objects - # into a DWithin query using a geodetic field. - qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)) + for dist in tx_dists: + qs = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist)) + self.assertEqual(tx_cities, self.get_cities(qs)) + + for dist in au_dists: + if isinstance(dist, D) and not oracle: type_error = True + else: type_error = False + + if isinstance(dist, tuple): + if oracle: dist = dist[1] + else: dist = dist[0] + + # Creating the query set. + qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, dist)).order_by('name') + if type_error: + # A TypeError should be raised on PostGIS when trying to pass + # Distance objects into a DWithin query using a geodetic field. self.assertRaises(TypeError, qs.count) else: - # Actually using a distance value of 0.5 degrees. - qs = AustraliaCity.objects.filter(point__dwithin=(self.au_pnt, 0.5)).order_by('name') - self.assertEqual(['Mittagong', 'Shellharbour', 'Thirroul', 'Wollongong'], self.get_cities(qs)) + self.assertEqual(au_cities, self.get_cities(qs)) def test03_distance_aggregate(self): "Testing the `distance` GeoQuerySet method."