Commit a0d5970d authored by Baptiste Mispelon's avatar Baptiste Mispelon
Browse files

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.
parent 5b185ecc
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
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: