File: test_case_insensitive_comparator.py

package info (click to toggle)
python-sqlalchemy-utils 0.30.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,056 kB
  • sloc: python: 10,350; makefile: 160
file content (50 lines) | stat: -rw-r--r-- 1,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sqlalchemy as sa

from sqlalchemy_utils import EmailType
from tests import TestCase


class TestCaseInsensitiveComparator(TestCase):
    def create_models(self):
        class User(self.Base):
            __tablename__ = 'user'
            id = sa.Column(sa.Integer, primary_key=True)
            email = sa.Column(EmailType)

            def __repr__(self):
                return 'Building(%r)' % self.id

        self.User = User

    def test_supports_equals(self):
        query = (
            self.session.query(self.User)
            .filter(self.User.email == u'email@example.com')
        )

        assert '"user".email = lower(:lower_1)' in str(query)

    def test_supports_in_(self):
        query = (
            self.session.query(self.User)
            .filter(self.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):
        query = (
            self.session.query(self.User)
            .filter(self.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):
        assert str(self.User.email == self.User.email) == (
            '"user".email = "user".email'
        )