Files
deb-python-sqlalchemy-utils/tests/functions/test_get_hybrid_properties.py
Jacob Magnusson 815f07d6c1 Use pytest fixtures to reduce complexity and repetition
Also:

Allow override of database name and user in tests (important for me as I would have to mess with my PSQL and MySQL database users otherwise)
Use dict.items instead of six.iteritems as it sporadically caused RuntimeError: dictionary changed size during iteration in Python 2.6 tests.
Fix typo DNS to DSN
Adds Python 3.5 to tox.ini
Added an .editorconfig
Import babel.dates in sqlalchemy_utils.i18n as an exception would be raised when using the latest versions of babel.
2016-01-19 10:52:30 +01:00

42 lines
1.1 KiB
Python

import pytest
import sqlalchemy as sa
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy_utils import get_hybrid_properties
@pytest.fixture
def Category(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)
return Category
class TestGetHybridProperties(object):
def test_declarative_model(self, Category):
assert (
list(get_hybrid_properties(Category).keys()) ==
['lowercase_name']
)
def test_mapper(self, Category):
assert (
list(get_hybrid_properties(sa.inspect(Category)).keys()) ==
['lowercase_name']
)
def test_aliased_class(self, Category):
props = get_hybrid_properties(sa.orm.aliased(Category))
assert list(props.keys()) == ['lowercase_name']