Ejemplo n.º 1
0
    def test_3_like(self):
        and_node = AndNode()
        like_node = LikeNode('name', '%son_%')
        and_node.childs.append(like_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Person)
        results = tree.filter(query).all()
        assert len(results) == 3
Ejemplo n.º 2
0
    def test_2_not_eq(self):
        and_node = AndNode()
        not_eq_node = NotEqNode('name', 'Toto')
        and_node.childs.append(not_eq_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 3
Ejemplo n.º 3
0
    def test_2_not_null(self):
        and_node = AndNode()
        not_null_node = NotNullNode('average')
        and_node.childs.append(not_null_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 3
Ejemplo n.º 4
0
    def test_2_lte(self):
        and_node = AndNode()
        lte_node = LteNode('age', 23)
        and_node.childs.append(lte_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 4
Ejemplo n.º 5
0
    def test_1_gt(self):
        and_node = AndNode()
        gt_node = GtNode('age', 21)
        and_node.childs.append(gt_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 2
Ejemplo n.º 6
0
    def test_3_eq_relation(self):
        and_node = AndNode()
        eq_node = EqNode('author.person.name', 'Person_1')
        and_node.childs.append(eq_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Post)
        results = tree.filter(query).first()
        assert results.title == 'post_1'
        assert results.content == 'content_1'
Ejemplo n.º 7
0
    def test_2_datetime_relation(self):
        and_node = AndNode()
        gt_node = GtNode('posts.pub_date', '2018-05-01 10:45:23')
        and_node.childs.append(gt_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Author)
        results = tree.filter(query).all()
        assert len(results) == 1
        assert results[0].author_name == 'author_3'
Ejemplo n.º 8
0
    def test_3_gt_relation(self):
        and_node = AndNode()
        gt_node = GtNode('author.posts.pages', 7)
        and_node.childs.append(gt_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Person)
        results = tree.filter(query).all()
        assert len(results) == 1
        assert results[0].name == 'Person_3'
Ejemplo n.º 9
0
    def test_1_eq(self):
        and_node = AndNode()
        eq_node = EqNode('name', 'Toto')
        and_node.childs.append(eq_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        result = tree.filter(query).first()
        assert result.name == 'Toto'
        assert result.age == 20
        assert result.average == 10
Ejemplo n.º 10
0
    def test_1_datetime(self):
        and_node = AndNode()
        gt_node = GtNode('pub_date', '2018-04-01 10:45:23')
        and_node.childs.append(gt_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Post)
        results = tree.filter(query).all()
        assert len(results) == 2
        assert results[0].title == 'post_5'
        assert results[1].title == 'post_6'
Ejemplo n.º 11
0
    def test_1_null(self):
        and_node = AndNode()
        null_node = NullNode('average')
        and_node.childs.append(null_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        result = tree.filter(query).first()
        assert result.name == 'Tata'
        assert result.age == 23
        assert result.average == None
Ejemplo n.º 12
0
    def test_1_contains(self):
        and_node = AndNode()
        contains_node = ContainsNode('name', 'to')
        and_node.childs.append(contains_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 1
        assert results[0].name == 'Toto'
        assert results[0].age == 20
        assert results[0].average == 10
Ejemplo n.º 13
0
    def test_4_lte_relation(self):
        and_node = AndNode()
        lte_node = LteNode('author.posts.pages', 4)
        and_node.childs.append(lte_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Person)
        results = tree.filter(query).all()
        assert len(results) == 3
        assert results[0].name == 'Person_1'
        assert results[1].name == 'Person_3'
        assert results[2].name == 'Person_2'
Ejemplo n.º 14
0
    def test_4_not_in_relation(self):
        and_node = AndNode()
        not_in_node = NotInNode('author.person.name', ['Person_1', 'Person_3'])
        and_node.childs.append(not_in_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Post)
        results = tree.filter(query).all()
        assert len(results) == 2
        assert results[0].title == 'post_2'
        assert results[0].content == 'content_2'
        assert results[1].title == 'post_5'
        assert results[1].content == 'content_5'
Ejemplo n.º 15
0
    def test_2_not_in(self):
        and_node = AndNode()
        not_in_node = NotInNode('name', ['Toto', 'Titi'])
        and_node.childs.append(not_in_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 2
        assert results[0].name == 'Tutu'
        assert results[0].age == 22
        assert results[0].average == 9.6
        assert results[1].name == 'Tata'
        assert results[1].age == 23
        assert results[1].average == None
Ejemplo n.º 16
0
    def test_1_in(self):
        and_node = AndNode()
        in_node = InNode('name', ['Toto', 'Titi'])
        and_node.childs.append(in_node)
        tree = SqlaFilterTree(and_node)

        query = self._session \
            .query(Simple)
        results = tree.filter(query).all()
        assert len(results) == 2
        assert results[0].name == 'Toto'
        assert results[0].age == 20
        assert results[0].average == 10
        assert results[1].name == 'Titi'
        assert results[1].age == 21
        assert results[1].average == 12.3