Fixed contrib.gis tests breaking in some edge cases.

The tests would error out with an ImproperlyConfigured error
if the user had psycopg installed but not geos.
Thanks to mcgohier for the report.
This commit is contained in:
Baptiste Mispelon 2014-05-17 14:59:06 +02:00
parent 5b185ecc68
commit a0d5970d44
1 changed files with 12 additions and 0 deletions

View File

@ -1,13 +1,25 @@
import sys
import unittest
from django.core.exceptions import ImproperlyConfigured
from django.db import ProgrammingError
from django.utils import six
try:
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
HAS_POSTGRES = True
except ImportError:
HAS_POSTGRES = False
except ImproperlyConfigured as e:
# If psycopg is installed but not geos, the import path hits
# django.contrib.gis.geometry.backend which will "helpfully" convert
# an ImportError into an ImproperlyConfigured.
# Here, we make sure we're only catching this specific case and not another
# ImproperlyConfigured one.
if e.args and e.args[0].startswith('Could not import user-defined GEOMETRY_BACKEND'):
HAS_POSTGRES = False
else:
six.reraise(*sys.exc_info())
if HAS_POSTGRES: