Ticket #13670: 13670.1.patch

File 13670.1.patch, 2.3 KB (added by John Paulett, 13 years ago)

Fix for other backends, move to unittest, & distill test to core example using existing models.

  • django/contrib/gis/db/backends/adapter.py

    diff --git django/contrib/gis/db/backends/adapter.py django/contrib/gis/db/backends/adapter.py
    index 9766ef0..ca77124 100644
    class WKTAdapter(object):  
    88        self.srid = geom.srid
    99
    1010    def __eq__(self, other):
     11        if not isinstance(other, WKTAdapter):
     12            return False
    1113        return self.wkt == other.wkt and self.srid == other.srid
    1214
    1315    def __str__(self):
  • django/contrib/gis/db/backends/postgis/adapter.py

    diff --git django/contrib/gis/db/backends/postgis/adapter.py django/contrib/gis/db/backends/postgis/adapter.py
    index 3f8603e..c9b9841 100644
    class PostGISAdapter(object):  
    2121            raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?')
    2222
    2323    def __eq__(self, other):
     24        if not isinstance(other, PostGISAdapter):
     25            return False
    2426        return (self.ewkb == other.ewkb) and (self.srid == other.srid)
    2527
    2628    def __str__(self):
  • django/contrib/gis/tests/geoapp/test_regress.py

    diff --git django/contrib/gis/tests/geoapp/test_regress.py django/contrib/gis/tests/geoapp/test_regress.py
    index 6b914da..454596e 100644
     
    11import unittest
    22from django.contrib.gis.tests.utils import no_mysql, no_spatialite
    33from django.contrib.gis.shortcuts import render_to_kmz
    4 from models import City
     4from models import City, State
    55
    66class GeoRegressionTests(unittest.TestCase):
    77
    class GeoRegressionTests(unittest.TestCase):  
    3535        extent = City.objects.filter(name='Pueblo').extent()
    3636        for ref_val, val in zip(ref_ext, extent):
    3737            self.assertAlmostEqual(ref_val, val, 4)
     38
     39    def test04_empty_count(self):
     40        "Testing that PostGISAdapter.__eq__ does check empty strings, see #13670"
     41        # contrived example, but need a geo lookup paired with an id__in lookup
     42        pueblo = City.objects.get(name='Pueblo')
     43        state = State.objects.filter(poly__contains=pueblo.point)
     44        cities_within_state = City.objects.filter(id__in=state)
     45
     46        # .count() should not throw TypeError in __eq__
     47        self.assertEqual(cities_within_state.count(), 1)
Back to Top