Add docs and tests for get_hybrid_properties

This commit is contained in:
Konsta Vesterinen
2014-07-29 14:03:20 +03:00
parent ca3257b1cc
commit 06579c323d
3 changed files with 45 additions and 0 deletions

View File

@@ -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)

View File

@@ -34,6 +34,12 @@ get_declarative_base
.. autofunction:: get_declarative_base
get_hybrid_properties
^^^^^^^^^^^^^^^^^^^^^
.. autofunction:: get_hybrid_properties
get_mapper
^^^^^^^^^^

View File

@@ -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']
)