From 06579c323d49307c5c3c18f487c0ba15764fdbdd Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Tue, 29 Jul 2014 14:03:20 +0300 Subject: [PATCH] Add docs and tests for get_hybrid_properties --- CHANGES.rst | 2 + docs/orm_helpers.rst | 6 +++ tests/functions/test_get_hybrid_properties.py | 37 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 tests/functions/test_get_hybrid_properties.py diff --git a/CHANGES.rst b/CHANGES.rst index 2da3d69..0ff608e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,8 @@ Here you can see the full list of changes between each SQLAlchemy-Utils release. ^^^^^^^^^^^^^^^^^^^ - Made sort_query support hybrid properties where function name != property name +- Made get_hybrid_properties return a dictionary of property keys and hybrid properties +- Added documentation for get_hybrid_properties 0.26.6 (2014-07-22) diff --git a/docs/orm_helpers.rst b/docs/orm_helpers.rst index dac9f4e..09cc984 100644 --- a/docs/orm_helpers.rst +++ b/docs/orm_helpers.rst @@ -34,6 +34,12 @@ get_declarative_base .. autofunction:: get_declarative_base +get_hybrid_properties +^^^^^^^^^^^^^^^^^^^^^ + +.. autofunction:: get_hybrid_properties + + get_mapper ^^^^^^^^^^ diff --git a/tests/functions/test_get_hybrid_properties.py b/tests/functions/test_get_hybrid_properties.py new file mode 100644 index 0000000..68b2dd6 --- /dev/null +++ b/tests/functions/test_get_hybrid_properties.py @@ -0,0 +1,37 @@ +import sqlalchemy as sa +from sqlalchemy.ext.hybrid import hybrid_property +from sqlalchemy.ext.declarative import declarative_base + +from sqlalchemy_utils import get_hybrid_properties + + +class TestGetHybridProperties(object): + def setup_method(self, method): + Base = declarative_base() + + class Category(Base): + __tablename__ = 'category' + id = sa.Column(sa.Integer, primary_key=True) + name = sa.Column(sa.Unicode(255)) + + @hybrid_property + def lowercase_name(self): + return self.name.lower() + + @lowercase_name.expression + def lowercase_name(cls): + return sa.func.lower(cls.name) + + self.Category = Category + + def test_declarative_model(self): + assert ( + list(get_hybrid_properties(self.Category).keys()) == + ['lowercase_name'] + ) + + def test_mapper(self): + assert ( + list(get_hybrid_properties(sa.inspect(self.Category)).keys()) == + ['lowercase_name'] + )