summaryrefslogtreecommitdiff
path: root/test/dialect
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-02-01 19:00:07 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2015-02-01 19:03:08 -0500
commitb2189da65019ed2f44e77933a122619489319c5a (patch)
tree1e3bcd44586eccfeebd9bd56b4da9606edd07769 /test/dialect
parent02dbcfa88a8390ee2af4f76e47bca8f205ddeee5 (diff)
downloadsqlalchemy-b2189da65019ed2f44e77933a122619489319c5a.tar.gz
- Repaired support for Postgresql UUID types in conjunction with
the ARRAY type when using psycopg2. The psycopg2 dialect now employs use of the psycopg2.extras.register_uuid() hook so that UUID values are always passed to/from the DBAPI as UUID() objects. The :paramref:`.UUID.as_uuid` flag is still honored, except with psycopg2 we need to convert returned UUID objects back into strings when this is disabled. fixes #2940
Diffstat (limited to 'test/dialect')
-rw-r--r--test/dialect/postgresql/test_types.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py
index 866bc7d54..36f4fdc3f 100644
--- a/test/dialect/postgresql/test_types.py
+++ b/test/dialect/postgresql/test_types.py
@@ -1035,7 +1035,7 @@ class UUIDTest(fixtures.TestBase):
import uuid
self._test_round_trip(
Table('utable', MetaData(),
- Column('data', postgresql.UUID())
+ Column('data', postgresql.UUID(as_uuid=False))
),
str(uuid.uuid4()),
str(uuid.uuid4())
@@ -1057,13 +1057,32 @@ class UUIDTest(fixtures.TestBase):
)
@testing.fails_on('postgresql+zxjdbc',
- 'column "data" is of type uuid[] but expression is of type character varying')
+ 'column "data" is of type uuid[] but '
+ 'expression is of type character varying')
@testing.fails_on('postgresql+pg8000', 'No support for UUID type')
def test_uuid_array(self):
import uuid
self._test_round_trip(
- Table('utable', MetaData(),
- Column('data', postgresql.ARRAY(postgresql.UUID()))
+ Table(
+ 'utable', MetaData(),
+ Column('data', postgresql.ARRAY(postgresql.UUID(as_uuid=True)))
+ ),
+ [uuid.uuid4(), uuid.uuid4()],
+ [uuid.uuid4(), uuid.uuid4()],
+ )
+
+ @testing.fails_on('postgresql+zxjdbc',
+ 'column "data" is of type uuid[] but '
+ 'expression is of type character varying')
+ @testing.fails_on('postgresql+pg8000', 'No support for UUID type')
+ def test_uuid_string_array(self):
+ import uuid
+ self._test_round_trip(
+ Table(
+ 'utable', MetaData(),
+ Column(
+ 'data',
+ postgresql.ARRAY(postgresql.UUID(as_uuid=False)))
),
[str(uuid.uuid4()), str(uuid.uuid4())],
[str(uuid.uuid4()), str(uuid.uuid4())],
@@ -1088,7 +1107,7 @@ class UUIDTest(fixtures.TestBase):
def teardown(self):
self.conn.close()
- def _test_round_trip(self, utable, value1, value2):
+ def _test_round_trip(self, utable, value1, value2, exp_value2=None):
utable.create(self.conn)
self.conn.execute(utable.insert(), {'data': value1})
self.conn.execute(utable.insert(), {'data': value2})
@@ -1096,7 +1115,10 @@ class UUIDTest(fixtures.TestBase):
select([utable.c.data]).
where(utable.c.data != value1)
)
- eq_(r.fetchone()[0], value2)
+ if exp_value2:
+ eq_(r.fetchone()[0], exp_value2)
+ else:
+ eq_(r.fetchone()[0], value2)
eq_(r.fetchone(), None)