summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-03-29 19:24:14 +0100
committerClaude Paroz <claude@2xlibre.net>2014-03-29 19:25:57 +0100
commite819a3cd622fe9404b1f5ea7891906c4cdabbb12 (patch)
treee961f1ff26e76a7b318ba177865d817b490b9f7b
parent88f1e3d93d8f48a302ff75b1936e471c4a52fff9 (diff)
Skipped PostGIS version tests when psycopg2 not installed
Refs #22334. Thanks Tim Graham for spotting the issue.
-rw-r--r--django/contrib/gis/tests/tests.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/django/contrib/gis/tests/tests.py b/django/contrib/gis/tests/tests.py
index 2caf7878c3..1148aa68e2 100644
--- a/django/contrib/gis/tests/tests.py
+++ b/django/contrib/gis/tests/tests.py
@@ -1,32 +1,39 @@
import unittest
-from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
from django.core.exceptions import ImproperlyConfigured
from django.db import ProgrammingError
+try:
+ from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
+ HAS_POSTGRES = True
+except ImportError:
+ HAS_POSTGRES = False
-class FakeConnection(object):
- def __init__(self):
- self.settings_dict = {
- 'NAME': 'test',
- }
+if HAS_POSTGRES:
+ class FakeConnection(object):
+ def __init__(self):
+ self.settings_dict = {
+ 'NAME': 'test',
+ }
-class FakePostGISOperations(PostGISOperations):
- def __init__(self, version=None):
- self.version = version
- self.connection = FakeConnection()
- def _get_postgis_func(self, func):
- if func == 'postgis_lib_version':
- if self.version is None:
- raise ProgrammingError
+ class FakePostGISOperations(PostGISOperations):
+ def __init__(self, version=None):
+ self.version = version
+ self.connection = FakeConnection()
+
+ def _get_postgis_func(self, func):
+ if func == 'postgis_lib_version':
+ if self.version is None:
+ raise ProgrammingError
+ else:
+ return self.version
else:
- return self.version
- else:
- raise NotImplementedError('This function was not expected to be called')
+ raise NotImplementedError('This function was not expected to be called')
+@unittest.skipUnless(HAS_POSTGRES, "The psycopg2 driver is needed for these tests")
class TestPostgisVersionCheck(unittest.TestCase):
"""
Tests that the postgis version check parses correctly the version numbers