
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.
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
import pytest
|
|
import sqlalchemy as sa
|
|
|
|
from sqlalchemy_utils import EmailType
|
|
|
|
|
|
@pytest.fixture
|
|
def User(Base):
|
|
class User(Base):
|
|
__tablename__ = 'user'
|
|
id = sa.Column(sa.Integer, primary_key=True)
|
|
email = sa.Column(EmailType)
|
|
|
|
def __repr__(self):
|
|
return 'Building(%r)' % self.id
|
|
return User
|
|
|
|
|
|
@pytest.fixture
|
|
def init_models(User):
|
|
pass
|
|
|
|
|
|
class TestCaseInsensitiveComparator(object):
|
|
|
|
def test_supports_equals(self, session, User):
|
|
query = (
|
|
session.query(User)
|
|
.filter(User.email == u'email@example.com')
|
|
)
|
|
|
|
assert '"user".email = lower(:lower_1)' in str(query)
|
|
|
|
def test_supports_in_(self, session, User):
|
|
query = (
|
|
session.query(User)
|
|
.filter(User.email.in_([u'email@example.com', u'a']))
|
|
)
|
|
assert (
|
|
'"user".email IN (lower(:lower_1), lower(:lower_2))'
|
|
in str(query)
|
|
)
|
|
|
|
def test_supports_notin_(self, session, User):
|
|
query = (
|
|
session.query(User)
|
|
.filter(User.email.notin_([u'email@example.com', u'a']))
|
|
)
|
|
assert (
|
|
'"user".email NOT IN (lower(:lower_1), lower(:lower_2))'
|
|
in str(query)
|
|
)
|
|
|
|
def test_does_not_apply_lower_to_types_that_are_already_lowercased(
|
|
self,
|
|
User
|
|
):
|
|
assert str(User.email == User.email) == (
|
|
'"user".email = "user".email'
|
|
)
|