test/unittest_rqlrewrite.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 03 Jun 2014 14:43:07 +0200
changeset 9845 9c3ec404534f
parent 9674 96549de9dd70
child 9953 643b19d79e4a
permissions -rw-r--r--
[testlib] deprecate .remote_call and provide new connection api friendly .remote_calling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9593
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
     1
# copyright 2003-2014 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
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
    26
from cubicweb.devtools import repotest, TestServerConfiguration, BaseApptestConfiguration
0
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',
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
    49
            2: 'Card',
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
    50
            3: 'Affaire'}[eid]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
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
    52
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
    53
    class FakeVReg:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        schema = schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        def solutions(sqlcursor, mainrqlst, kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
            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
    58
        class rqlhelper:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
            @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
            def annotate(rqlst):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
                rqlhelper.annotate(rqlst)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
            @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
            def simplify(mainrqlst, needcopy=False):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
                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
    65
    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
    66
        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
    67
    snippets = []
7850
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    68
    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
    69
        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
    70
                    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
    71
                                    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
    72
                    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
    73
                    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
    74
        snippets.append((dict([v]), rqlexprs))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs)
9188
0677e03077fb [rqlrewrite] rewrite doesn't need a solutions argument, always use the Select'ones
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9170
diff changeset
    76
    rewriter.rewrite(rqlst.children[0], snippets, kwargs, existingvars)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
    test_vrefs(rqlst.children[0])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    return rewriter.rewritten
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
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
    81
    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
    82
    selects = []
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    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
    84
        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
    85
        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
    86
            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
    87
        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
    88
            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
    89
            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
    90
    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
    91
    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
    92
        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
    93
            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
    94
            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
    95
            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
    96
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
class RQLRewriteTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
    """a faire:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
    * optimisation: detecter les relations utilisees dans les rqlexpressions qui
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
      sont presentes dans la requete de depart pour les reutiliser si possible
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   103
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    * "has_<ACTION>_permission" ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    """
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   106
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
    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
   108
        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
   109
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        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
   111
        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
   112
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   113
                         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
   114
                         "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
   115
                         "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
   116
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
    def test_multiple_var(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        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
   119
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
        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
   121
        kwargs = {'u':2}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        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
   123
        rewrite(rqlst, {('C', 'X'): (card_constraint,), ('S', 'X'): affaire_constraints},
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
                kwargs)
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   125
        self.assertMultiLineEqual(
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   126
            rqlst.as_string(),
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   127
            "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
   128
            "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
   129
            "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
   130
            "(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
   131
            "S is Affaire")
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9655
diff changeset
   132
        self.assertIn('D', kwargs)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   133
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
    def test_or(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        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
   136
        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
   137
        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
   138
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   139
                         "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
   140
                         "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
   141
                         "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
   142
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
    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
   144
        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
   145
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
        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
   147
        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
   148
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   149
                         u"Any 2 WHERE B eid %(C)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   150
                         "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
   151
                         "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
   152
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
   153
    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
   154
        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
   155
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        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
   157
        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
   158
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   159
                         "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
   160
                         "WITH C BEING "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   161
                         "(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
   162
                         "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
   163
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
   164
    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
   165
        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
   166
                           'P name "read", P require_group G')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   167
        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
   168
        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
   169
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   170
                         "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
   171
                         "WITH C,T BEING "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   172
                         "(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
   173
                         "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
   174
                         "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
   175
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
   176
    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
   177
        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
   178
                       '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
   179
        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
   180
        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
   181
        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
   182
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   183
                         "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
   184
                         "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
   185
                         "(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
   186
                         "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
   187
                         "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
   188
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
   189
    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
   190
        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
   191
        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
   192
        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
   193
        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
   194
        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
   195
                        ('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
   196
                        ('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
   197
        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
   198
                             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
   199
                             '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
   200
                             '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
   201
                             '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
   202
                             '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
   203
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   204
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   205
    def test_ambiguous_optional_same_exprs(self):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   206
        """See #3013535"""
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   207
        # see test of the same name in RewriteFullTC: original problem is
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   208
        # unreproducible here because it actually lies in
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   209
        # RQLRewriter.insert_local_checks
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   210
        rqlst = parse('Any A,AR,X,CD WHERE A concerne X?, A ref AR, A eid %(a)s, X creation_date CD')
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   211
        rewrite(rqlst, {('X', 'X'): ('X created_by U',),}, {'a': 3})
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   212
        self.assertEqual(rqlst.as_string(),
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   213
                         u'Any A,AR,X,CD WHERE A concerne X?, A ref AR, A eid %(a)s WITH X,CD BEING (Any X,CD WHERE X creation_date CD, EXISTS(X created_by B), B eid %(A)s, X is IN(Division, Note, Societe))')
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   214
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
   215
    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
   216
        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
   217
        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
   218
        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
   219
        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
   220
                        ('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
   221
                        }, {})
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
        # XXX suboptimal
7790
7e16e056eecb [test] fix test subsquently to localperms introduction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   223
        self.assertEqual(rqlst.as_string(),
7868
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   224
                         "Any C,A,R WITH A,C,R BEING "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   225
                         "(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
   226
                         "(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
   227
                         "B is Card, D is CWPermission)), "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   228
                         "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
   229
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
   230
    # 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
   231
    #     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
   232
    #     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
   233
    #     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
   234
    #     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
   235
    #                     ('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
   236
    #                     }, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   237
    #     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
   238
    #                          "")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   239
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
   240
    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
   241
        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
   242
        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
   243
        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
   244
        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
   245
                          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
   246
                                           ('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
   247
                                           ('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
   248
                                           }, {})
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
   249
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
   250
    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
   251
        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
   252
        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
   253
        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
   254
                      '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
   255
        rewrite(rqlst, {('C', 'X'): (c1,)}, {})
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   256
        self.assertEqual(rqlst.as_string(),
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   257
                         '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
   258
                         '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
   259
                         'N inlined_affaire W, EXISTS(C require_permission B), '
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   260
                         '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
   261
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
   262
    def test_relation_optimization_1_lhs(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        # since Card in_state State as monovalued cardinality, the in_state
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
        # 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
   265
        # 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
   266
        snippet = ('X in_state S, S name "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
        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
   268
        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
   269
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   270
                         "Any C WHERE C in_state STATE, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   271
                         "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
   272
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
   273
    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
   274
        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
   275
        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
   276
        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
   277
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   278
                         "Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   279
                         "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
   280
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
    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
   282
        # 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
   283
        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
   284
        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
   285
        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
   286
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   287
                         "Any C WHERE C in_state STATE?, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   288
                         "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
   289
    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
   290
        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
   291
        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
   292
        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
   293
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   294
                         "Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   295
                         "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
   296
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
    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
   298
        # 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
   299
        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
   300
        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
   301
        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
   302
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   303
                         "Any C WHERE C in_state STATE, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   304
                         "EXISTS(STATE name 'hop'), STATE is State")
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   305
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
   306
    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
   307
        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
   308
        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
   309
        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
   310
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   311
                         "Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   312
                         "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
   313
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
    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
   315
        # 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
   316
        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
   317
        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
   318
        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
   319
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   320
                         "Any C WHERE C in_state STATE?, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   321
                         "EXISTS(C in_state A, A name 'hop', A is State), STATE is State")
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   322
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
   323
    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
   324
        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
   325
        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
   326
        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
   327
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   328
                         "Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   329
                         "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
   330
                         "C is WorkflowTransition")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   331
9170
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   332
    def test_relation_non_optimization_2(self):
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   333
        """See #3024730"""
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   334
        # 'X inlined_note N' must not be shared with 'C inlined_note N'
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   335
        # previously inserted, else this may introduce duplicated results, as N
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   336
        # will then be shared by multiple EXISTS and so at SQL generation time,
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   337
        # the table will be in the FROM clause of the outermost query
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   338
        rqlst = parse('Any A,C WHERE A inlined_card C')
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   339
        rewrite(rqlst, {('A', 'X'): ('X inlined_card C, C inlined_note N, N owned_by U',),
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   340
                        ('C', 'X'): ('X inlined_note N, N owned_by U',)}, {})
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   341
        self.assertEqual(rqlst.as_string(),
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   342
                         'Any A,C WHERE A inlined_card C, D eid %(E)s, '
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   343
                         'EXISTS(C inlined_note B, B owned_by D, B is Note), '
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   344
                         'EXISTS(C inlined_note F, F owned_by D, F is Note), '
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   345
                         'A is Affaire, C is Card')
e6fe77dbcfdf [rql rewrite] may_be_shared_with should consider relation's scope (closes #3024730)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9168
diff changeset
   346
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   347
    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
   348
        # CWUser doesn't have require_permission
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
        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
   350
        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
   351
        self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   352
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   353
    def test_unsupported_constraint_2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
        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
   355
        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
   356
        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
   357
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   358
                         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
   359
                         "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
   360
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   361
    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
   362
        self.skipTest('raise unauthorized for now')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
        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
   364
        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
   365
        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
   366
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   367
                         u'XXX dunno what should be generated')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   368
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   369
    def test_add_ambiguity_exists(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
        constraint = ('X concerne Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
        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
   372
        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
   373
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   374
                         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
   375
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   376
    def test_add_ambiguity_outerjoin(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
        constraint = ('X concerne Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
        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
   379
        rewrite(rqlst, {('X', 'X'): (constraint,)}, {})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   380
        # 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
   381
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   382
                         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
   383
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   384
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
   385
    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
   386
        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
   387
        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
   388
        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
   389
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   390
                         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
   391
        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
   392
        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
   393
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   394
                         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
   395
        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
   396
        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
   397
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   398
                         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
   399
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
   400
    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
   401
        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
   402
        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
   403
        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
   404
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   405
                         '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
   406
        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
   407
        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
   408
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   409
                         '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
   410
        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
   411
        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
   412
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   413
                         '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
   414
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
   415
    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
   416
        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
   417
        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
   418
        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
   419
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   420
                         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
   421
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
   422
    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
   423
        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
   424
        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
   425
        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
   426
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   427
                         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
   428
        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
   429
        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
   430
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   431
                         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
   432
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
   433
    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
   434
        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
   435
        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
   436
        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
   437
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   438
                         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
   439
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
   440
    def test_rqlexpr_not_relation_1_1(self):
9262
7fc54e02291f [security] fix dumb attribute error when inserting read security. Closes #3196891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9189
diff changeset
   441
        constraint = ERQLExpression('X owned_by Z, Z login "hop"', 'X')
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
   442
        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
   443
        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
   444
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   445
                         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
   446
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
   447
    def test_rqlexpr_not_relation_1_2(self):
9262
7fc54e02291f [security] fix dumb attribute error when inserting read security. Closes #3196891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9189
diff changeset
   448
        constraint = ERQLExpression('X owned_by Z, Z login "hop"', 'X')
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
   449
        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
   450
        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
   451
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   452
                         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
   453
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
   454
    def test_rqlexpr_not_relation_2(self):
9262
7fc54e02291f [security] fix dumb attribute error when inserting read security. Closes #3196891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9189
diff changeset
   455
        constraint = ERQLExpression('X owned_by Z, Z login "hop"', 'X')
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
   456
        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
   457
        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
   458
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   459
                         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
   460
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
   461
    def test_rqlexpr_multiexpr_outerjoin(self):
9262
7fc54e02291f [security] fix dumb attribute error when inserting read security. Closes #3196891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9189
diff changeset
   462
        c1 = ERQLExpression('X owned_by Z, Z login "hop"', 'X')
7fc54e02291f [security] fix dumb attribute error when inserting read security. Closes #3196891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9189
diff changeset
   463
        c2 = ERQLExpression('X owned_by Z, Z login "hip"', 'X')
7fc54e02291f [security] fix dumb attribute error when inserting read security. Closes #3196891
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9189
diff changeset
   464
        c3 = ERQLExpression('X owned_by Z, Z login "momo"', 'X')
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
   465
        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
   466
        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
   467
        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
   468
                         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
   469
                         '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
   470
                         '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
   471
                         '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
   472
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
   473
    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
   474
        #: 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
   475
        #: (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
   476
        #:
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
   477
        #: 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
   478
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
   479
        # 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
   480
        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
   481
        # 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
   482
        # 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
   483
        # 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
   484
        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
   485
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
   486
        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
   487
        rewrite(rqlst, {('A', 'X'): (c_ok, c_bad)}, {})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   488
9358
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   489
    def test_nonregr_is_instance_of(self):
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   490
        user_expr = ERQLExpression('NOT X in_group AF, AF name "guests"')
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   491
        rqlst = parse('Any O WHERE S use_email O, S is CWUser, O is_instance_of EmailAddress')
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   492
        rewrite(rqlst, {('S', 'X'): (user_expr,)}, {})
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   493
        self.assertEqual(rqlst.as_string(),
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   494
                         'Any O WHERE S use_email O, S is CWUser, O is EmailAddress, '
1e0235478403 [rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9327
diff changeset
   495
                         'EXISTS(NOT S in_group A, A name "guests", A is CWGroup)')
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   496
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   497
from cubicweb.devtools.testlib import CubicWebTC
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   498
from logilab.common.decorators import classproperty
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   499
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   500
class RewriteFullTC(CubicWebTC):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   501
    @classproperty
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   502
    def config(cls):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   503
        return BaseApptestConfiguration(apphome=cls.datapath('rewrite'))
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   504
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   505
    def process(self, rql, args=None):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   506
        if args is None:
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   507
            args = {}
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   508
        querier = self.repo.querier
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   509
        union = querier.parse(rql)
9655
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   510
        with self.admin_access.repo_cnx() as cnx:
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   511
            querier.solutions(cnx, union, args)
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   512
            querier._annotate(union)
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   513
            plan = querier.plan_factory(union, args, cnx)
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   514
            plan.preprocess(union)
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   515
            return union
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   516
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   517
    def test_ambiguous_optional_same_exprs(self):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   518
        """See #3013535"""
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   519
        edef1 = self.schema['Societe']
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   520
        edef2 = self.schema['Division']
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   521
        edef3 = self.schema['Note']
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   522
        with self.temporary_permissions((edef1, {'read': (ERQLExpression('X owned_by U'),)}),
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   523
                                        (edef2, {'read': (ERQLExpression('X owned_by U'),)}),
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   524
                                        (edef3, {'read': (ERQLExpression('X owned_by U'),)})):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   525
            union = self.process('Any A,AR,X,CD WHERE A concerne X?, A ref AR, X creation_date CD')
9189
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   526
            self.assertEqual('Any A,AR,X,CD WHERE A concerne X?, A ref AR, A is Affaire '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   527
                             'WITH X,CD BEING (Any X,CD WHERE X creation_date CD, '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   528
                             'EXISTS(X owned_by %(A)s), X is IN(Division, Note, Societe))',
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   529
                             union.as_string())
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   530
9327
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   531
    def test_ambiguous_optional_diff_exprs(self):
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   532
        """See #3013554"""
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   533
        self.skipTest('bad request generated (may generate duplicated results)')
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   534
        edef1 = self.schema['Societe']
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   535
        edef2 = self.schema['Division']
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   536
        edef3 = self.schema['Note']
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   537
        with self.temporary_permissions((edef1, {'read': (ERQLExpression('X created_by U'),)}),
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   538
                                        (edef2, {'read': ('users',)}),
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   539
                                        (edef3, {'read': (ERQLExpression('X owned_by U'),)})):
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   540
            union = self.process('Any A,AR,X,CD WHERE A concerne X?, A ref AR, X creation_date CD')
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   541
            self.assertEqual(union.as_string(), 'not generated today')
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   542
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   543
9189
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   544
    def test_xxxx(self):
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   545
        edef1 = self.schema['Societe']
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   546
        edef2 = self.schema['Division']
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   547
        read_expr = ERQLExpression('X responsable E, U has_read_permission E')
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   548
        with self.temporary_permissions((edef1, {'read': (read_expr,)}),
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   549
                                        (edef2, {'read': (read_expr,)})):
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   550
            union = self.process('Any X,AA,AC,AD ORDERBY AD DESC '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   551
                                 'WHERE X responsable E, X nom AA, '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   552
                                 'X responsable AC?, AC modification_date AD')
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   553
            self.assertEqual('Any X,AA,AC,AD ORDERBY AD DESC '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   554
                             'WHERE X responsable E, X nom AA, '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   555
                             'X responsable AC?, AC modification_date AD, '
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   556
                             'AC is CWUser, E is CWUser, X is IN(Division, Societe)',
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   557
                             union.as_string())
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   558
9593
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   559
    def test_question_mark_attribute_snippet(self):
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   560
        # see #3661918
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   561
        from cubicweb.rqlrewrite import RQLRewriter
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   562
        from logilab.common.decorators import monkeypatch
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   563
        repotest.undo_monkey_patch()
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   564
        orig_insert_snippets = RQLRewriter.insert_snippets
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   565
        # patch insert_snippets and not rewrite, insert_snippets is already
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   566
        # monkey patches (see above setupModule/repotest)
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   567
        @monkeypatch(RQLRewriter)
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   568
        def insert_snippets(self, snippets, varexistsmap=None):
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   569
            # crash occurs if snippets are processed in a specific order, force
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   570
            # destiny
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   571
            if snippets[0][0] != {u'N': 'X'}:
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   572
                snippets = list(reversed(snippets))
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   573
            return orig_insert_snippets(self, snippets, varexistsmap)
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   574
        try:
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   575
            with self.temporary_permissions(
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   576
                    (self.schema['Affaire'],
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   577
                     {'read': (ERQLExpression('X ref "blah"'), )}),
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   578
                    (self.schema['Note'],
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   579
                     {'read': (ERQLExpression(
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   580
                         'EXISTS(X inlined_affaire Z), EXISTS(Z owned_by U)'), )}),
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   581
            ):
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   582
                union = self.process(
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   583
                    'Any A,COUNT(N) GROUPBY A '
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   584
                    'WHERE A is Affaire, N? inlined_affaire A')
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   585
                self.assertEqual('Any A,COUNT(N) GROUPBY A WHERE A is Affaire '
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   586
                                 'WITH N,A BEING (Any N,A WHERE N? inlined_affaire A, '
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   587
                                 '(N is NULL) OR (EXISTS(EXISTS(N inlined_affaire B), '
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   588
                                 'EXISTS(B owned_by %(E)s), B is Affaire)), '
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   589
                                 'A is Affaire, N is Note, EXISTS(A ref "blah"))',
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   590
                                 union.as_string())
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   591
        finally:
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   592
            RQLRewriter.insert_snippets = orig_insert_snippets
48a84fb4f301 [rewrite] Fix crash when the main variable doesn't appear in the snippet's vargraph
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9358
diff changeset
   593
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   594
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   595
    unittest_main()