From de786a4208e621229769a8fb1f876f358dc4e70e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 27 Dec 2013 17:10:55 -0500 Subject: - Declarative does an extra check to detect if the same :class:`.Column` is mapped multiple times under different properties (which typically should be a :func:`.synonym` instead) or if two or more :class:`.Column` objects are given the same name, raising a warning if this condition is detected. [ticket:2828] --- test/ext/declarative/test_basic.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test') diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py index b119e356f..0d213fce3 100644 --- a/test/ext/declarative/test_basic.py +++ b/test/ext/declarative/test_basic.py @@ -143,6 +143,39 @@ class DeclarativeTest(DeclarativeTestBase): assert class_mapper(Bar).get_property('some_data').columns[0] \ is t.c.data + def test_column_named_twice(self): + def go(): + class Foo(Base): + __tablename__ = 'foo' + + id = Column(Integer, primary_key=True) + x = Column('x', Integer) + y = Column('x', Integer) + assert_raises_message( + sa.exc.SAWarning, + "On class 'Foo', Column object 'x' named directly multiple times, " + "only one will be used: x, y", + go + ) + + + def test_column_repeated_under_prop(self): + def go(): + class Foo(Base): + __tablename__ = 'foo' + + id = Column(Integer, primary_key=True) + x = Column('x', Integer) + y = column_property(x) + z = Column('x', Integer) + + assert_raises_message( + sa.exc.SAWarning, + "On class 'Foo', Column object 'x' named directly multiple times, " + "only one will be used: x, y, z", + go + ) + def test_relationship_level_msg_for_invalid_callable(self): class A(Base): __tablename__ = 'a' -- cgit v1.2.1