diff options
author | Alex Grönholm <alex.gronholm@nextday.fi> | 2016-04-11 17:01:42 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-01 12:57:36 -0400 |
commit | a8e7bb8782ca8fd858ac036082104b4ac2991cfc (patch) | |
tree | c3b2a3c1e68b364e33feacd91221b405c6ad737f /test/dialect/postgresql/test_reflection.py | |
parent | 3f55039e7f15efafacc3e8e0fbf0ba38fa612b09 (diff) | |
download | sqlalchemy-a8e7bb8782ca8fd858ac036082104b4ac2991cfc.tar.gz |
Implemented CHECK constraint reflection for SQLite and PostgreSQL
Co-Authored-By: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: Ie6cf2d2958d1c567324db9e08fef2d3186e97350
Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/80
Diffstat (limited to 'test/dialect/postgresql/test_reflection.py')
-rw-r--r-- | test/dialect/postgresql/test_reflection.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 4897c4a7e..a0f9dcd49 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -1,6 +1,7 @@ # coding: utf-8 from sqlalchemy.engine import reflection +from sqlalchemy.sql.schema import CheckConstraint from sqlalchemy.testing.assertions import eq_, assert_raises, \ AssertsExecutionResults from sqlalchemy.testing import fixtures @@ -965,6 +966,29 @@ class ReflectionTest(fixtures.TestBase): assert indexes['ix_a'].unique self.assert_('ix_a' not in constraints) + @testing.provide_metadata + def test_reflect_check_constraint(self): + meta = self.metadata + + cc_table = Table( + 'pgsql_cc', meta, + Column('a', Integer()), + CheckConstraint('a > 1 AND a < 5', name='cc1'), + CheckConstraint('a = 1 OR (a > 2 AND a < 5)', name='cc2')) + + cc_table.create() + + reflected = Table('pgsql_cc', MetaData(testing.db), autoload=True) + + check_constraints = dict((uc.name, uc.sqltext.text) + for uc in reflected.constraints + if isinstance(uc, CheckConstraint)) + + eq_(check_constraints, { + u'cc1': u'(a > 1) AND (a < 5)', + u'cc2': u'(a = 1) OR ((a > 2) AND (a < 5))' + }) + class CustomTypeReflectionTest(fixtures.TestBase): |