mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
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
This commit is contained in:
parent
656360c240
commit
f2dca72afd
4 changed files with 59 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue