test/unittest_rqlrewrite.py
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 10 Sep 2012 15:17:10 +0200
branchstable
changeset 8546 3d2038d6f20d
parent 8342 7a5271182ef0
child 9168 0fb4b67bde58
permissions -rw-r--r--
[sources/native] automatically update passwords using deprecated hashes on login Closes #2465904
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8342
7a5271182ef0 [rql annotation] fix has_text_query detection (if coming from sub-query and if has_text on a column aliases. Closes #2275322
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8296
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4908
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1787
diff changeset
    18
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
from logilab.common.testlib import unittest_main, TestCase
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
from logilab.common.testlib import mock_object
4908
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
    21
from yams import BadSchemaDefinition
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
from rql import parse, nodes, RQLHelper
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
7850
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    24
from cubicweb import Unauthorized, rqlrewrite
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    25
from cubicweb.schema import RRQLExpression, ERQLExpression
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
from cubicweb.devtools import repotest, TestServerConfiguration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6640
diff changeset
    29
def setUpModule(*args):
6640
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    30
    global rqlhelper, schema
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    31
    config = TestServerConfiguration(RQLRewriteTC.datapath('rewrite'))
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    32
    config.bootstrap_cubes()
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    33
    schema = config.load_schema()
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    34
    from yams.buildobjs import RelationDefinition
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    35
    schema.add_relation_def(RelationDefinition(subject='Card', name='in_state',
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    36
                                               object='State', cardinality='1*'))
6640
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    37
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    38
    rqlhelper = RQLHelper(schema, special_relations={'eid': 'uid',
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    39
                                                     'has_text': 'fti'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    repotest.do_monkey_patch()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6640
diff changeset
    42
def tearDownModule(*args):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    repotest.undo_monkey_patch()
6640
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    44
    global rqlhelper, schema
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    45
    del rqlhelper, schema
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    46
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
def eid_func_map(eid):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 47
diff changeset
    48
    return {1: 'CWUser',
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
            2: 'Card'}[eid]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
    51
def rewrite(rqlst, snippets_map, kwargs, existingvars=None):
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    52
    class FakeVReg:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        schema = schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        def solutions(sqlcursor, mainrqlst, kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
            rqlhelper.compute_solutions(rqlst, {'eid': eid_func_map}, kwargs=kwargs)
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    57
        class rqlhelper:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
            @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
            def annotate(rqlst):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
                rqlhelper.annotate(rqlst)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
            @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
            def simplify(mainrqlst, needcopy=False):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
                rqlhelper.simplify(rqlst, needcopy)
7850
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    64
    rewriter = rqlrewrite.RQLRewriter(
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    65
        mock_object(vreg=FakeVReg, user=(mock_object(eid=1))))
7139
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    66
    snippets = []
7850
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    67
    for v, exprs in sorted(snippets_map.items()):
7139
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    68
        rqlexprs = [isinstance(snippet, basestring)
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    69
                    and mock_object(snippet_rqlst=parse('Any X WHERE '+snippet).children[0],
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    70
                                    expression='Any X WHERE '+snippet)
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    71
                    or snippet
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    72
                    for snippet in exprs]
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    73
        snippets.append((dict([v]), rqlexprs))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    solutions = rqlst.children[0].solutions
7139
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    76
    rewriter.rewrite(rqlst.children[0], snippets, solutions, kwargs,
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
    77
                     existingvars)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    test_vrefs(rqlst.children[0])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    return rewriter.rewritten
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
def test_vrefs(node):
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    82
    vrefmaps = {}
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    83
    selects = []
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    for vref in node.iget_nodes(nodes.VariableRef):
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    85
        stmt = vref.stmt
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    86
        try:
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    87
            vrefmaps[stmt].setdefault(vref.name, set()).add(vref)
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    88
        except KeyError:
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    89
            vrefmaps[stmt] = {vref.name: set( (vref,) )}
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    90
            selects.append(stmt)
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    91
    assert node in selects
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    92
    for stmt in selects:
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    93
        for var in stmt.defined_vars.itervalues():
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    94
            assert var.stinfo['references']
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    95
            vrefmap = vrefmaps[stmt]
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    96
            assert not (var.stinfo['references'] ^ vrefmap[var.name]), (node.as_string(), var, var.stinfo['references'], vrefmap[var.name])
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
    97
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
class RQLRewriteTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
    """a faire:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    * optimisation: detecter les relations utilisees dans les rqlexpressions qui
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
      sont presentes dans la requete de depart pour les reutiliser si possible
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   104
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    * "has_<ACTION>_permission" ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    """
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   107
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
    def test_base_var(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   109
        constraint = ('X in_state S, U in_group G, P require_state S,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        rqlst = parse('Card C')
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   112
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   113
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   114
                         u"Any C WHERE C is Card, B eid %(D)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   115
                         "EXISTS(C in_state A, B in_group E, F require_state A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   116
                         "F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission)")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   117
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    def test_multiple_var(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
        card_constraint = ('X in_state S, U in_group G, P require_state S,'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
        affaire_constraints = ('X ref LIKE "PUBLIC%"', 'U in_group G, G name "public"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        kwargs = {'u':2}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        rqlst = parse('Any S WHERE S documented_by C, C eid %(u)s')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   124
        rewrite(rqlst, {('C', 'X'): (card_constraint,), ('S', 'X'): affaire_constraints},
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                kwargs)
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   126
        self.assertMultiLineEqual(
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   127
            rqlst.as_string(),
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   128
            "Any S WHERE S documented_by C, C eid %(u)s, B eid %(D)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   129
            "EXISTS(C in_state A, B in_group E, F require_state A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   130
            "F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   131
            "(EXISTS(S ref LIKE 'PUBLIC%')) OR (EXISTS(B in_group G, G name 'public', G is CWGroup)), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   132
            "S is Affaire")
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   133
        self.assertTrue('D' in kwargs)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   134
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
    def test_or(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        constraint = '(X identity U) OR (X in_state ST, CL identity U, CL in_state ST, ST name "subscribed")'
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   137
        rqlst = parse('Any S WHERE S owned_by C, C eid %(u)s, S is in (CWUser, CWGroup)')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   138
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {'u':1})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   139
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   140
                         "Any S WHERE S owned_by C, C eid %(u)s, S is IN(CWUser, CWGroup), A eid %(B)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   141
                         "EXISTS((C identity A) OR (C in_state D, E identity A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   142
                         "E in_state D, D name 'subscribed'), D is State, E is CWUser)")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
    def test_simplified_rqlst(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   145
        constraint = ('X in_state S, U in_group G, P require_state S,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        rqlst = parse('Any 2') # this is the simplified rql st for Any X WHERE X eid 12
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   148
        rewrite(rqlst, {('2', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   149
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   150
                         u"Any 2 WHERE B eid %(C)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   151
                         "EXISTS(2 in_state A, B in_group D, E require_state A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   152
                         "E name 'read', E require_group D, A is State, D is CWGroup, E is CWPermission)")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   154
    def test_optional_var_1(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   155
        constraint = ('X in_state S, U in_group G, P require_state S,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        rqlst = parse('Any A,C WHERE A documented_by C?')
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   158
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   159
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   160
                         "Any A,C WHERE A documented_by C?, A is Affaire "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   161
                         "WITH C BEING "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   162
                         "(Any C WHERE EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   163
                         "G require_group F), D eid %(A)s, C is Card)")
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   164
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   165
    def test_optional_var_2(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   166
        constraint = ('X in_state S, U in_group G, P require_state S,'
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   167
                           'P name "read", P require_group G')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        rqlst = parse('Any A,C,T WHERE A documented_by C?, C title T')
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   169
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   170
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   171
                         "Any A,C,T WHERE A documented_by C?, A is Affaire "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   172
                         "WITH C,T BEING "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   173
                         "(Any C,T WHERE C title T, EXISTS(C in_state B, D in_group F, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   174
                         "G require_state B, G name 'read', G require_group F), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   175
                         "D eid %(A)s, C is Card)")
4907
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   176
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   177
    def test_optional_var_3(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   178
        constraint1 = ('X in_state S, U in_group G, P require_state S,'
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   179
                       'P name "read", P require_group G')
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   180
        constraint2 = 'X in_state S, S name "public"'
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   181
        rqlst = parse('Any A,C,T WHERE A documented_by C?, C title T')
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   182
        rewrite(rqlst, {('C', 'X'): (constraint1, constraint2)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   183
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   184
                         "Any A,C,T WHERE A documented_by C?, A is Affaire "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   185
                         "WITH C,T BEING (Any C,T WHERE C title T, "
8264
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   186
                         "(EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', G require_group F)) "
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   187
                         "OR (EXISTS(C in_state E, E name 'public')), "
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   188
                         "D eid %(A)s, C is Card)")
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   189
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   190
    def test_optional_var_4(self):
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   191
        constraint1 = 'A created_by U, X documented_by A'
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   192
        constraint2 = 'A created_by U, X concerne A'
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   193
        constraint3 = 'X created_by U'
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   194
        rqlst = parse('Any X,LA,Y WHERE LA? documented_by X, LA concerne Y')
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   195
        rewrite(rqlst, {('LA', 'X'): (constraint1, constraint2),
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   196
                        ('X', 'X'): (constraint3,),
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   197
                        ('Y', 'X'): (constraint3,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   198
        self.assertEqual(rqlst.as_string(),
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   199
                             u'Any X,LA,Y WHERE LA? documented_by X, LA concerne Y, B eid %(C)s, '
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   200
                             'EXISTS(X created_by B), EXISTS(Y created_by B), '
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   201
                             'X is Card, Y is IN(Division, Note, Societe) '
8264
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   202
                             'WITH LA BEING (Any LA WHERE (EXISTS(A created_by B, LA documented_by A)) OR (EXISTS(E created_by B, LA concerne E)), '
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   203
                             'B eid %(D)s, LA is Affaire)')
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   204
4907
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   205
    def test_optional_var_inlined(self):
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   206
        c1 = ('X require_permission P')
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   207
        c2 = ('X inlined_card O, O require_permission P')
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   208
        rqlst = parse('Any C,A,R WHERE A? inlined_card C, A ref R')
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   209
        rewrite(rqlst, {('C', 'X'): (c1,),
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   210
                        ('A', 'X'): (c2,),
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   211
                        }, {})
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   212
        # XXX suboptimal
7790
7e16e056eecb [test] fix test subsquently to localperms introduction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   213
        self.assertEqual(rqlst.as_string(),
7868
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   214
                         "Any C,A,R WITH A,C,R BEING "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   215
                         "(Any A,C,R WHERE A? inlined_card C, A ref R, "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   216
                         "(A is NULL) OR (EXISTS(A inlined_card B, B require_permission D, "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   217
                         "B is Card, D is CWPermission)), "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   218
                         "A is Affaire, C is Card, EXISTS(C require_permission E, E is CWPermission))")
4907
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   219
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   220
    # def test_optional_var_inlined_has_perm(self):
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   221
    #     c1 = ('X require_permission P')
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   222
    #     c2 = ('X inlined_card O, U has_read_permission O')
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   223
    #     rqlst = parse('Any C,A,R WHERE A? inlined_card C, A ref R')
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   224
    #     rewrite(rqlst, {('C', 'X'): (c1,),
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   225
    #                     ('A', 'X'): (c2,),
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   226
    #                     }, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   227
    #     self.assertEqual(rqlst.as_string(),
4907
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   228
    #                          "")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   229
4908
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   230
    def test_optional_var_inlined_imbricated_error(self):
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   231
        c1 = ('X require_permission P')
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   232
        c2 = ('X inlined_card O, O require_permission P')
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   233
        rqlst = parse('Any C,A,R,A2,R2 WHERE A? inlined_card C, A ref R,A2? inlined_card C, A2 ref R2')
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   234
        self.assertRaises(BadSchemaDefinition,
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   235
                          rewrite, rqlst, {('C', 'X'): (c1,),
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   236
                                           ('A', 'X'): (c2,),
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   237
                                           ('A2', 'X'): (c2,),
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   238
                                           }, {})
b3ad329cbe17 [rql rewrite] until a better solution is found raise BadSchemaDefinition when two inlined relations with security on an optional variable is used, explaining how to bypass it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4907
diff changeset
   239
7843
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   240
    def test_optional_var_inlined_linked(self):
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   241
        c1 = ('X require_permission P')
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   242
        c2 = ('X inlined_card O, O require_permission P')
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   243
        rqlst = parse('Any A,W WHERE A inlined_card C?, C inlined_note N, '
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   244
                      'N inlined_affaire W')
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   245
        rewrite(rqlst, {('C', 'X'): (c1,)}, {})
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   246
        self.assertEqual(rqlst.as_string(),
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   247
                         'Any A,W WHERE A inlined_card C?, A is Affaire '
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   248
                         'WITH C,N,W BEING (Any C,N,W WHERE C inlined_note N, '
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   249
                         'N inlined_affaire W, EXISTS(C require_permission B), '
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   250
                         'C is Card, N is Note, W is Affaire)')
7843
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   251
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   252
    def test_relation_optimization_1_lhs(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
        # since Card in_state State as monovalued cardinality, the in_state
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   254
        # relation used in the rql expression can be ignored and S replaced by
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   255
        # the variable from the incoming query
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   256
        snippet = ('X in_state S, S name "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   257
        rqlst = parse('Card C WHERE C in_state STATE')
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   258
        rewrite(rqlst, {('C', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   259
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   260
                         "Any C WHERE C in_state STATE, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   261
                         "EXISTS(STATE name 'hop'), STATE is State")
7843
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   262
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   263
    def test_relation_optimization_1_rhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   264
        snippet = ('TW subworkflow_exit X, TW name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   265
        rqlst = parse('WorkflowTransition C WHERE C subworkflow_exit EXIT')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   266
        rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   267
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   268
                         "Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   269
                         "EXISTS(C name 'hop'), EXIT is SubWorkflowExitPoint")
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   270
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   271
    def test_relation_optimization_2_lhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   272
        # optional relation can be shared if also optional in the snippet
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   273
        snippet = ('X in_state S?, S name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   274
        rqlst = parse('Card C WHERE C in_state STATE?')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   275
        rewrite(rqlst, {('C', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   276
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   277
                         "Any C WHERE C in_state STATE?, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   278
                         "EXISTS(STATE name 'hop'), STATE is State")
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   279
    def test_relation_optimization_2_rhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   280
        snippet = ('TW? subworkflow_exit X, TW name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   281
        rqlst = parse('SubWorkflowExitPoint EXIT WHERE C? subworkflow_exit EXIT')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   282
        rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   283
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   284
                         "Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   285
                         "EXISTS(C name 'hop'), C is WorkflowTransition")
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   286
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   287
    def test_relation_optimization_3_lhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   288
        # optional relation in the snippet but not in the orig tree can be shared
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   289
        snippet = ('X in_state S?, S name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   290
        rqlst = parse('Card C WHERE C in_state STATE')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   291
        rewrite(rqlst, {('C', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   292
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   293
                         "Any C WHERE C in_state STATE, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   294
                         "EXISTS(STATE name 'hop'), STATE is State")
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   295
    def test_relation_optimization_3_rhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   296
        snippet = ('TW? subworkflow_exit X, TW name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   297
        rqlst = parse('WorkflowTransition C WHERE C subworkflow_exit EXIT')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   298
        rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   299
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   300
                         "Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   301
                         "EXISTS(C name 'hop'), EXIT is SubWorkflowExitPoint")
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   302
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   303
    def test_relation_non_optimization_1_lhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   304
        # but optional relation in the orig tree but not in the snippet can't be shared
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   305
        snippet = ('X in_state S, S name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   306
        rqlst = parse('Card C WHERE C in_state STATE?')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   307
        rewrite(rqlst, {('C', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   308
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   309
                         "Any C WHERE C in_state STATE?, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   310
                         "EXISTS(C in_state A, A name 'hop', A is State), STATE is State")
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   311
    def test_relation_non_optimization_1_rhs(self):
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   312
        snippet = ('TW subworkflow_exit X, TW name "hop"')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   313
        rqlst = parse('SubWorkflowExitPoint EXIT WHERE C? subworkflow_exit EXIT')
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   314
        rewrite(rqlst, {('EXIT', 'X'): (snippet,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   315
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   316
                         "Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   317
                         "EXISTS(A subworkflow_exit EXIT, A name 'hop', A is WorkflowTransition), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   318
                         "C is WorkflowTransition")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   319
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   320
    def test_unsupported_constraint_1(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 47
diff changeset
   321
        # CWUser doesn't have require_permission
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   322
        trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 47
diff changeset
   323
        rqlst = parse('Any U,T WHERE U is CWUser, T wf_info_for U')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   324
        self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   325
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   326
    def test_unsupported_constraint_2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   327
        trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"')
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 47
diff changeset
   328
        rqlst = parse('Any U,T WHERE U is CWUser, T wf_info_for U')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   329
        rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X wf_info_for Y, Y in_group G, G name "managers"')}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   330
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   331
                         u"Any U,T WHERE U is CWUser, T wf_info_for U, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   332
                         "EXISTS(U in_group B, B name 'managers', B is CWGroup), T is TrInfo")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   333
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   334
    def test_unsupported_constraint_3(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6337
diff changeset
   335
        self.skipTest('raise unauthorized for now')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   336
        trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   337
        rqlst = parse('Any T WHERE T wf_info_for X')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   338
        rewrite(rqlst, {('T', 'X'): (trinfo_constraint, 'X in_group G, G name "managers"')}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   339
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   340
                         u'XXX dunno what should be generated')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   341
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   342
    def test_add_ambiguity_exists(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   343
        constraint = ('X concerne Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   344
        rqlst = parse('Affaire X')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   345
        rewrite(rqlst, {('X', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   346
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   347
                         u"Any X WHERE X is Affaire, ((EXISTS(X concerne A, A is Division)) OR (EXISTS(X concerne C, C is Societe))) OR (EXISTS(X concerne B, B is Note))")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   348
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
    def test_add_ambiguity_outerjoin(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
        constraint = ('X concerne Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   351
        rqlst = parse('Any X,C WHERE X? documented_by C')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   352
        rewrite(rqlst, {('X', 'X'): (constraint,)}, {})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
        # ambiguity are kept in the sub-query, no need to be resolved using OR
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   354
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   355
                         u"Any X,C WHERE X? documented_by C, C is Card WITH X BEING (Any X WHERE EXISTS(X concerne A), X is Affaire)")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   356
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   357
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   358
    def test_rrqlexpr_nonexistant_subject_1(self):
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   359
        constraint = RRQLExpression('S owned_by U')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   360
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   361
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   362
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   363
                         u"Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)")
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   364
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   365
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'OU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   366
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   367
                         u"Any C WHERE C is Card")
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   368
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   369
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SOU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   370
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   371
                         u"Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)")
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   372
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   373
    def test_rrqlexpr_nonexistant_subject_2(self):
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   374
        constraint = RRQLExpression('S owned_by U, O owned_by U, O is Card')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   375
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   376
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   377
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   378
                         'Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)')
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   379
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   380
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'OU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   381
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   382
                         'Any C WHERE C is Card, B eid %(D)s, EXISTS(A owned_by B, A is Card)')
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   383
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   384
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SOU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   385
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   386
                         'Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A, D owned_by A, D is Card)')
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   387
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   388
    def test_rrqlexpr_nonexistant_subject_3(self):
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   389
        constraint = RRQLExpression('U in_group G, G name "users"')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   390
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   391
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   392
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   393
                         u'Any C WHERE C is Card, A eid %(B)s, EXISTS(A in_group D, D name "users", D is CWGroup)')
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   394
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   395
    def test_rrqlexpr_nonexistant_subject_4(self):
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   396
        constraint = RRQLExpression('U in_group G, G name "users", S owned_by U')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   397
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   398
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   399
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   400
                         u'Any C WHERE C is Card, A eid %(B)s, EXISTS(A in_group D, D name "users", C owned_by A, D is CWGroup)')
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   401
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   402
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'OU')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   403
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   404
                         u'Any C WHERE C is Card, A eid %(B)s, EXISTS(A in_group D, D name "users", D is CWGroup)')
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   405
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   406
    def test_rrqlexpr_nonexistant_subject_5(self):
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   407
        constraint = RRQLExpression('S owned_by Z, O owned_by Z, O is Card')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   408
        rqlst = parse('Card C')
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   409
        rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'S')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   410
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   411
                         u"Any C WHERE C is Card, EXISTS(C owned_by A, A is CWUser)")
3826
0c0c051863cb close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3443
diff changeset
   412
7251
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   413
    def test_rqlexpr_not_relation_1_1(self):
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   414
        constraint = RRQLExpression('X owned_by Z, Z login "hop"', 'X')
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   415
        rqlst = parse('Affaire A WHERE NOT EXISTS(A documented_by C)')
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   416
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {}, 'X')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   417
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   418
                         u'Any A WHERE NOT EXISTS(A documented_by C, EXISTS(C owned_by B, B login "hop", B is CWUser), C is Card), A is Affaire')
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   419
7251
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   420
    def test_rqlexpr_not_relation_1_2(self):
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   421
        constraint = RRQLExpression('X owned_by Z, Z login "hop"', 'X')
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   422
        rqlst = parse('Affaire A WHERE NOT EXISTS(A documented_by C)')
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   423
        rewrite(rqlst, {('A', 'X'): (constraint,)}, {}, 'X')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   424
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   425
                         u'Any A WHERE NOT EXISTS(A documented_by C, C is Card), A is Affaire, EXISTS(A owned_by B, B login "hop", B is CWUser)')
7251
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   426
163a2eab0e55 [rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7139
diff changeset
   427
    def test_rqlexpr_not_relation_2(self):
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   428
        constraint = RRQLExpression('X owned_by Z, Z login "hop"', 'X')
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   429
        rqlst = rqlhelper.parse('Affaire A WHERE NOT A documented_by C', annotate=False)
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   430
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {}, 'X')
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   431
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   432
                         u'Any A WHERE NOT EXISTS(A documented_by C, EXISTS(C owned_by B, B login "hop", B is CWUser), C is Card), A is Affaire')
5582
3e133b29a1a4 [rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   433
8264
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   434
    def test_rqlexpr_multiexpr_outerjoin(self):
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   435
        c1 = RRQLExpression('X owned_by Z, Z login "hop"', 'X')
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   436
        c2 = RRQLExpression('X owned_by Z, Z login "hip"', 'X')
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   437
        c3 = RRQLExpression('X owned_by Z, Z login "momo"', 'X')
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   438
        rqlst = rqlhelper.parse('Any A WHERE A documented_by C?', annotate=False)
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   439
        rewrite(rqlst, {('C', 'X'): (c1, c2, c3)}, {}, 'X')
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   440
        self.assertEqual(rqlst.as_string(),
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   441
                         u'Any A WHERE A documented_by C?, A is Affaire '
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   442
                         'WITH C BEING (Any C WHERE ((EXISTS(C owned_by B, B login "hop")) '
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   443
                         'OR (EXISTS(C owned_by D, D login "momo"))) '
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   444
                         'OR (EXISTS(C owned_by A, A login "hip")), C is Card)')
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   445
8296
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   446
    def test_multiple_erql_one_bad(self):
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   447
        #: reproduce bug #2236985
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   448
        #: (rqlrewrite fails to remove rewritten entry for unsupported constraint and then crash)
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   449
        #:
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   450
        #: This check a very rare code path triggered by the four condition below
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   451
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   452
        # 1. c_ok introduce an ambiguity
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   453
        c_ok = ERQLExpression('X concerne R')
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   454
        # 2. c_bad is just plain wrong and won't be kept
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   455
        # 3. but it declare a new variable
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   456
        # 4. this variable require a rewrite
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   457
        c_bad = ERQLExpression('X documented_by R, A in_state R')
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   458
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   459
        rqlst = parse('Any A, R WHERE A ref R, S is Affaire')
f23782a2cdee rqlrewrite: remove element in rewritten when we remove them from the select (closes #2236985)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8264
diff changeset
   460
        rewrite(rqlst, {('A', 'X'): (c_ok, c_bad)}, {})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   461
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   462
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   463
    unittest_main()