diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-18 18:44:35 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-18 18:44:35 -0500 |
commit | 2336b1cebfcb2f304e09cbc2a0e8bb3fb3a9ceeb (patch) | |
tree | 1879b3e9b3582278a0ef17a3700420d4998fb31e /test/dialect/test_postgresql.py | |
parent | 34cb747f647747fc1685156d28166ab33da81ae8 (diff) | |
download | sqlalchemy-2336b1cebfcb2f304e09cbc2a0e8bb3fb3a9ceeb.tar.gz |
- Added as_uuid=True flag to the UUID type, will receive
and return values as Python UUID() objects rather than
strings. Currently, the UUID type is only known to
work with psycopg2. [ticket:1956]
Diffstat (limited to 'test/dialect/test_postgresql.py')
-rw-r--r-- | test/dialect/test_postgresql.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 54127cd98..f3eb91ef2 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1884,6 +1884,64 @@ class SpecialTypesTest(TestBase, ComparesTables): assert t.c.plain_interval.type.precision is None assert t.c.precision_interval.type.precision == 3 +class UUIDTest(TestBase): + """Test the bind/return values of the UUID type.""" + + __only_on__ = 'postgresql' + + @testing.fails_on('postgresql+pg8000', 'No support for UUID type') + def test_uuid_string(self): + import uuid + self._test_round_trip( + Table('utable', MetaData(), + Column('data', postgresql.UUID()) + ), + str(uuid.uuid4()), + str(uuid.uuid4()) + ) + + @testing.fails_on('postgresql+pg8000', 'No support for UUID type') + def test_uuid_uuid(self): + import uuid + self._test_round_trip( + Table('utable', MetaData(), + Column('data', postgresql.UUID(as_uuid=True)) + ), + uuid.uuid4(), + uuid.uuid4() + ) + + def test_no_uuid_available(self): + from sqlalchemy.dialects.postgresql import base + uuid_type = base._python_UUID + base._python_UUID = None + try: + assert_raises( + NotImplementedError, + postgresql.UUID, as_uuid=True + ) + finally: + base._python_UUID = uuid_type + + def setup(self): + self.conn = testing.db.connect() + trans = self.conn.begin() + + def teardown(self): + self.conn.close() + + def _test_round_trip(self, utable, value1, value2): + utable.create(self.conn) + self.conn.execute(utable.insert(), {'data':value1}) + self.conn.execute(utable.insert(), {'data':value2}) + r = self.conn.execute( + select([utable.c.data]). + where(utable.c.data != value1) + ) + eq_(r.fetchone()[0], value2) + eq_(r.fetchone(), None) + + class MatchTest(TestBase, AssertsCompiledSQL): __only_on__ = 'postgresql' |