diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2018-11-30 18:12:02 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@bbpush.zzzcomputing.com> | 2018-11-30 18:12:02 +0000 |
commit | 7940e7dc9c40b80b103400bad6e9aac2ce8824bd (patch) | |
tree | 3cd5f617d4720323464f1c2bb43b5bf682b422bc /test/ext/declarative/test_basic.py | |
parent | f916fa3b316c79df928277bdaf5070a77e056d30 (diff) | |
parent | 835444be72bb595b1ed3ee5458a86202813412a6 (diff) | |
download | sqlalchemy-7940e7dc9c40b80b103400bad6e9aac2ce8824bd.tar.gz |
Merge "Add __clause_element__ to ColumnProperty"
Diffstat (limited to 'test/ext/declarative/test_basic.py')
-rw-r--r-- | test/ext/declarative/test_basic.py | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index e8a9a140c..611598413 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -8,11 +8,11 @@ from sqlalchemy import exc import sqlalchemy as sa from sqlalchemy import testing, util from sqlalchemy import MetaData, Integer, String, ForeignKey, \ - ForeignKeyConstraint, Index + ForeignKeyConstraint, Index, UniqueConstraint, CheckConstraint from sqlalchemy.testing.schema import Table, Column from sqlalchemy.orm import relationship, create_session, class_mapper, \ joinedload, configure_mappers, backref, clear_mappers, \ - column_property, composite, Session, properties + column_property, composite, Session, properties, deferred from sqlalchemy.util import with_metaclass from sqlalchemy.ext.declarative import declared_attr, synonym_for from sqlalchemy.testing import fixtures, mock @@ -264,6 +264,53 @@ class DeclarativeTest(DeclarativeTestBase): go ) + def test_using_explicit_prop_in_schema_objects(self): + class Foo(Base): + __tablename__ = 'foo' + + id = Column(Integer, primary_key=True) + cprop = column_property(Column(Integer)) + + __table_args__ = ( + UniqueConstraint(cprop), + ) + uq = [ + c for c in Foo.__table__.constraints + if isinstance(c, UniqueConstraint)][0] + is_(uq.columns.cprop, Foo.__table__.c.cprop) + + class Bar(Base): + __tablename__ = 'bar' + + id = Column(Integer, primary_key=True) + cprop = deferred(Column(Integer)) + + __table_args__ = ( + CheckConstraint(cprop > sa.func.foo()), + ) + ck = [ + c for c in Bar.__table__.constraints + if isinstance(c, CheckConstraint)][0] + is_(ck.columns.cprop, Bar.__table__.c.cprop) + + if testing.requires.python3.enabled: + # test the existing failure case in case something changes + def go(): + class Bat(Base): + __tablename__ = 'bat' + + id = Column(Integer, primary_key=True) + cprop = deferred(Column(Integer)) + + # we still can't do an expression like + # "cprop > 5" because the column property isn't + # a full blown column + + __table_args__ = ( + CheckConstraint(cprop > 5), + ) + assert_raises(TypeError, go) + def test_relationship_level_msg_for_invalid_callable(self): class A(Base): __tablename__ = 'a' |