summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-04-18 16:18:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-04-18 16:20:20 -0400
commit6f6e2c48ba0be827ee434891f54eb2173edf9bfc (patch)
tree49e1271767c5ae3980e768c573f9cba4d7634049 /test
parent243b222a232da0da0ac42386f3f38364750b1fcc (diff)
downloadsqlalchemy-6f6e2c48ba0be827ee434891f54eb2173edf9bfc.tar.gz
Propagate hybrid properties / info
Keystone and others depend on the .property attribute being "mirrored" when a @hybrid_property is linked directly to a mapped attribute. Restore this linkage and also create a defined behavior for the .info dictionary; it is that of the hybrid itself. Add this behavioral change to the migration notes. Change-Id: I8ac34ef52039387230c648866c5ca15d381f7fee References: #3653
Diffstat (limited to 'test')
-rw-r--r--test/ext/test_hybrid.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py
index dac65dbab..c67b66051 100644
--- a/test/ext/test_hybrid.py
+++ b/test/ext/test_hybrid.py
@@ -266,6 +266,59 @@ class PropertyValueTest(fixtures.TestBase, AssertsCompiledSQL):
eq_(a1._value, 10)
+class PropertyMirrorTest(fixtures.TestBase, AssertsCompiledSQL):
+ __dialect__ = 'default'
+
+ def _fixture(self):
+ Base = declarative_base()
+
+ class A(Base):
+ __tablename__ = 'a'
+ id = Column(Integer, primary_key=True)
+ _value = Column("value", String)
+
+ @hybrid.hybrid_property
+ def value(self):
+ "This is an instance-level docstring"
+ return self._value
+ return A
+
+ def test_property(self):
+ A = self._fixture()
+
+ is_(A.value.property, A._value.property)
+
+ def test_key(self):
+ A = self._fixture()
+ eq_(A.value.key, "value")
+ eq_(A._value.key, "_value")
+
+ def test_class(self):
+ A = self._fixture()
+ is_(A.value.class_, A._value.class_)
+
+ def test_get_history(self):
+ A = self._fixture()
+ inst = A(_value=5)
+ eq_(A.value.get_history(inst), A._value.get_history(inst))
+
+ def test_info_not_mirrored(self):
+ A = self._fixture()
+ A._value.info['foo'] = 'bar'
+ A.value.info['bar'] = 'hoho'
+
+ eq_(A._value.info, {'foo': 'bar'})
+ eq_(A.value.info, {'bar': 'hoho'})
+
+ def test_info_from_hybrid(self):
+ A = self._fixture()
+ A._value.info['foo'] = 'bar'
+ A.value.info['bar'] = 'hoho'
+
+ insp = inspect(A)
+ is_(insp.all_orm_descriptors['value'].info, A.value.info)
+
+
class MethodExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = 'default'