summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2011-06-19 18:00:09 +0000
committerRamiro Morales <cramm0@gmail.com>2011-06-19 18:00:09 +0000
commitf2dca72afd89160580454abe5a90e0b4c6be196e (patch)
treec97ea3617af2165c6d7b93050a831dbf7335a928 /tests
parent656360c24044e06c881baa648f2aad9d671c3bd8 (diff)
Fixed #11065, #11285 -- Streamlined PostgreSQL version detection, fixing incompatibility with multi-db. Thanks findepi for the report.
Changed our internal representation of the PostgreSQL version from tuples to integers as used by libpq and psycopg2. This simplifies version comparison operations. Also, using the associated libpq/psycopg2 API allows to remove the need for manually issuing in-band ``SELECT version()`` SQL queries to obtain the server version (or at least reduce its number if version of psycopg2 in use is older than 2.0.12). Refs #10509. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16439 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/backends/tests.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index 33c8763037..29db6a705a 100644
--- a/tests/regressiontests/backends/tests.py
+++ b/tests/regressiontests/backends/tests.py
@@ -196,12 +196,34 @@ class PostgresVersionTest(TestCase):
self.assertEqual(pg_version._parse_version(version_string), version)
def test_parsing(self):
- self.assert_parses("PostgreSQL 8.3 beta4", (8, 3, None))
- self.assert_parses("PostgreSQL 8.3", (8, 3, None))
- self.assert_parses("EnterpriseDB 8.3", (8, 3, None))
- self.assert_parses("PostgreSQL 8.3.6", (8, 3, 6))
- self.assert_parses("PostgreSQL 8.4beta1", (8, 4, None))
- self.assert_parses("PostgreSQL 8.3.1 on i386-apple-darwin9.2.2, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)", (8, 3, 1))
+ """Test PostgreSQL version parsing from `SELECT version()` output"""
+ self.assert_parses("PostgreSQL 8.3 beta4", 80300)
+ self.assert_parses("PostgreSQL 8.3", 80300)
+ self.assert_parses("EnterpriseDB 8.3", 80300)
+ self.assert_parses("PostgreSQL 8.3.6", 80306)
+ self.assert_parses("PostgreSQL 8.4beta1", 80400)
+ self.assert_parses("PostgreSQL 8.3.1 on i386-apple-darwin9.2.2, compiled by GCC i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)", 80301)
+
+ def test_version_detection(self):
+ """Test PostgreSQL version detection"""
+
+ # Helper mocks
+ class CursorMock(object):
+ "Very simple mock of DB-API cursor"
+ def execute(self, arg):
+ pass
+
+ def fetchone(self):
+ return ["PostgreSQL 8.3"]
+
+ class OlderConnectionMock(object):
+ "Mock of psycopg2 (< 2.0.12) connection"
+ def cursor(self):
+ return CursorMock()
+
+ # psycopg2 < 2.0.12 code path
+ conn = OlderConnectionMock()
+ self.assertEqual(pg_version.get_version(conn), 80300)
# Unfortunately with sqlite3 the in-memory test database cannot be
# closed, and so it cannot be re-opened during testing, and so we