test/unittest_rqlrewrite.py
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 18 May 2015 16:44:49 +0200
changeset 10439 45e18b4a7466
parent 9955 60a9cd1b3a4b
child 10612 84468b90e9c1
permissions -rw-r--r--
[devtools] change the way we start/stop postgresql Instead of having the test db handler start a cluster on demand, use the test module's setUp/tearDown callbacks to do it. This allows to have one data directory (and thus cluster) per test module, allowing different test modules to run in parallel, each using its own database cluster whose path is based on the test module.
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
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    22
from yams.buildobjs import RelationDefinition
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from rql import parse, nodes, RQLHelper
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
7850
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    25
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
    26
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
    27
from cubicweb.devtools import repotest, TestServerConfiguration, BaseApptestConfiguration
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6640
diff changeset
    30
def setUpModule(*args):
6640
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    31
    global rqlhelper, schema
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    32
    config = TestServerConfiguration(RQLRewriteTC.datapath('rewrite'))
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    33
    config.bootstrap_cubes()
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    34
    schema = config.load_schema()
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
    rqlhelper = RQLHelper(schema, special_relations={'eid': 'uid',
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    38
                                                     'has_text': 'fti'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    repotest.do_monkey_patch()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
6781
5062d86d6ffe [unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6640
diff changeset
    41
def tearDownModule(*args):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    repotest.undo_monkey_patch()
6640
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    43
    global rqlhelper, schema
4c4616c02f69 [test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    44
    del rqlhelper, schema
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    45
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
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
    47
    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
    48
            2: 'Card',
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
    49
            3: 'Affaire'}[eid]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    51
def _prepare_rewriter(rewriter_cls, 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
    52
    class FakeVReg:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        schema = schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        @staticmethod
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    55
        def solutions(sqlcursor, rqlst, kwargs):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
            rqlhelper.compute_solutions(rqlst, {'eid': eid_func_map}, kwargs=kwargs)
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    57
        class rqlhelper:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
            @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
            def annotate(rqlst):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
                rqlhelper.annotate(rqlst)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
            @staticmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
            def simplify(mainrqlst, needcopy=False):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
                rqlhelper.simplify(rqlst, needcopy)
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    64
    return rewriter_cls(mock_object(vreg=FakeVReg, user=(mock_object(eid=1))))
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    65
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    66
def rewrite(rqlst, snippets_map, kwargs, existingvars=None):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    67
    rewriter = _prepare_rewriter(rqlrewrite.RQLRewriter, kwargs)
7139
20807d3d7cf6 [rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6781
diff changeset
    68
    snippets = []
7850
d14b77c42b06 [test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7843
diff changeset
    69
    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
    70
        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
    71
                    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
    72
                                    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
    73
                    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
    74
                    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
    75
        snippets.append((dict([v]), rqlexprs))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
    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
    77
    rewriter.rewrite(rqlst.children[0], snippets, kwargs, existingvars)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    test_vrefs(rqlst.children[0])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
    return rewriter.rewritten
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
def test_vrefs(node):
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    82
    vrefmaps = {}
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    83
    selects = []
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    for vref in node.iget_nodes(nodes.VariableRef):
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    85
        stmt = vref.stmt
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    86
        try:
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    87
            vrefmaps[stmt].setdefault(vref.name, set()).add(vref)
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    88
        except KeyError:
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    89
            vrefmaps[stmt] = {vref.name: set( (vref,) )}
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    90
            selects.append(stmt)
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
    91
    assert node in selects, (node, selects)
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
    92
    for stmt in selects:
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    93
        for var in stmt.defined_vars.itervalues():
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    94
            assert var.stinfo['references']
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    95
            vrefmap = vrefmaps[stmt]
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
    96
            assert not (var.stinfo['references'] ^ vrefmap[var.name]), (node.as_string(), var, var.stinfo['references'], vrefmap[var.name])
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
    97
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
class RQLRewriteTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
    """a faire:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    * optimisation: detecter les relations utilisees dans les rqlexpressions qui
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
      sont presentes dans la requete de depart pour les reutiliser si possible
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   104
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    * "has_<ACTION>_permission" ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    """
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   107
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
    def test_base_var(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   109
        constraint = ('X in_state S, U in_group G, P require_state S,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        rqlst = parse('Card C')
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   112
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   113
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   114
                         u"Any C WHERE C is Card, B eid %(D)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   115
                         "EXISTS(C in_state A, B in_group E, F require_state A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   116
                         "F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission)")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   117
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    def test_multiple_var(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
        card_constraint = ('X in_state S, U in_group G, P require_state S,'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
        affaire_constraints = ('X ref LIKE "PUBLIC%"', 'U in_group G, G name "public"')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        kwargs = {'u':2}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
        rqlst = parse('Any S WHERE S documented_by C, C eid %(u)s')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   124
        rewrite(rqlst, {('C', 'X'): (card_constraint,), ('S', 'X'): affaire_constraints},
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                kwargs)
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   126
        self.assertMultiLineEqual(
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   127
            rqlst.as_string(),
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   128
            "Any S WHERE S documented_by C, C eid %(u)s, B eid %(D)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   129
            "EXISTS(C in_state A, B in_group E, F require_state A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   130
            "F name 'read', F require_group E, A is State, E is CWGroup, F is CWPermission), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   131
            "(EXISTS(S ref LIKE 'PUBLIC%')) OR (EXISTS(B in_group G, G name 'public', G is CWGroup)), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   132
            "S is Affaire")
9674
96549de9dd70 [test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents: 9655
diff changeset
   133
        self.assertIn('D', kwargs)
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   134
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
    def test_or(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
        constraint = '(X identity U) OR (X in_state ST, CL identity U, CL in_state ST, ST name "subscribed")'
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2608
diff changeset
   137
        rqlst = parse('Any S WHERE S owned_by C, C eid %(u)s, S is in (CWUser, CWGroup)')
3240
8604a15995d1 refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
   138
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {'u':1})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   139
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   140
                         "Any S WHERE S owned_by C, C eid %(u)s, S is IN(CWUser, CWGroup), A eid %(B)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   141
                         "EXISTS((C identity A) OR (C in_state D, E identity A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   142
                         "E in_state D, D name 'subscribed'), D is State, E is CWUser)")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
    def test_simplified_rqlst(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   145
        constraint = ('X in_state S, U in_group G, P require_state S,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        rqlst = parse('Any 2') # this is the simplified rql st for Any X WHERE X eid 12
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   148
        rewrite(rqlst, {('2', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   149
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   150
                         u"Any 2 WHERE B eid %(C)s, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   151
                         "EXISTS(2 in_state A, B in_group D, E require_state A, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   152
                         "E name 'read', E require_group D, A is State, D is CWGroup, E is CWPermission)")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   154
    def test_optional_var_1(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   155
        constraint = ('X in_state S, U in_group G, P require_state S,'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
                           'P name "read", P require_group G')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        rqlst = parse('Any A,C WHERE A documented_by C?')
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   158
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   159
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   160
                         "Any A,C WHERE A documented_by C?, A is Affaire "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   161
                         "WITH C BEING "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   162
                         "(Any C WHERE EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   163
                         "G require_group F), D eid %(A)s, C is Card)")
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   164
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   165
    def test_optional_var_2(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   166
        constraint = ('X in_state S, U in_group G, P require_state S,'
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   167
                           'P name "read", P require_group G')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        rqlst = parse('Any A,C,T WHERE A documented_by C?, C title T')
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   169
        rewrite(rqlst, {('C', 'X'): (constraint,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   170
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   171
                         "Any A,C,T WHERE A documented_by C?, A is Affaire "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   172
                         "WITH C,T BEING "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   173
                         "(Any C,T WHERE C title T, EXISTS(C in_state B, D in_group F, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   174
                         "G require_state B, G name 'read', G require_group F), "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   175
                         "D eid %(A)s, C is Card)")
4907
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   176
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   177
    def test_optional_var_3(self):
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   178
        constraint1 = ('X in_state S, U in_group G, P require_state S,'
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   179
                       'P name "read", P require_group G')
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   180
        constraint2 = 'X in_state S, S name "public"'
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   181
        rqlst = parse('Any A,C,T WHERE A documented_by C?, C title T')
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   182
        rewrite(rqlst, {('C', 'X'): (constraint1, constraint2)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   183
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   184
                         "Any A,C,T WHERE A documented_by C?, A is Affaire "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   185
                         "WITH C,T BEING (Any C,T WHERE C title T, "
8264
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   186
                         "(EXISTS(C in_state B, D in_group F, G require_state B, G name 'read', G require_group F)) "
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   187
                         "OR (EXISTS(C in_state E, E name 'public')), "
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   188
                         "D eid %(A)s, C is Card)")
7535
d5725a89dac9 [rqlrewrite] test and fix rql snippets insertion when several snippets match an optional variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7251
diff changeset
   189
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   190
    def test_optional_var_4(self):
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   191
        constraint1 = 'A created_by U, X documented_by A'
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   192
        constraint2 = 'A created_by U, X concerne A'
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   193
        constraint3 = 'X created_by U'
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   194
        rqlst = parse('Any X,LA,Y WHERE LA? documented_by X, LA concerne Y')
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   195
        rewrite(rqlst, {('LA', 'X'): (constraint1, constraint2),
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   196
                        ('X', 'X'): (constraint3,),
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   197
                        ('Y', 'X'): (constraint3,)}, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   198
        self.assertEqual(rqlst.as_string(),
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   199
                             u'Any X,LA,Y WHERE LA? documented_by X, LA concerne Y, B eid %(C)s, '
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   200
                             'EXISTS(X created_by B), EXISTS(Y created_by B), '
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   201
                             'X is Card, Y is IN(Division, Note, Societe) '
8264
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   202
                             'WITH LA BEING (Any LA WHERE (EXISTS(A created_by B, LA documented_by A)) OR (EXISTS(E created_by B, LA concerne E)), '
a4b009ba92ce [rql rewrite] when a subquery has to be introduced, properly return the snippet expression so that further expressions are properly ored. Closes #2207180
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8113
diff changeset
   203
                             'B eid %(D)s, LA is Affaire)')
7555
c3bf459268d7 [rqlrewrite] closes #1772135: 1. don't try to reuse a relation from another statement (eg because a subquery has been introduced) 2. _use_orig_term should consider the current statement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7535
diff changeset
   204
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   205
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   206
    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
   207
        """See #3013535"""
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   208
        # 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
   209
        # 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
   210
        # 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
   211
        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
   212
        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
   213
        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
   214
                         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
   215
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
   216
    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
   217
        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
   218
        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
   219
        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
   220
        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
   221
                        ('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
   222
                        }, {})
e623afd49356 [rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   223
        # XXX suboptimal
7790
7e16e056eecb [test] fix test subsquently to localperms introduction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   224
        self.assertEqual(rqlst.as_string(),
7868
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   225
                         "Any C,A,R WITH A,C,R BEING "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   226
                         "(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
   227
                         "(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
   228
                         "B is Card, D is CWPermission)), "
39a54b88906d backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7845 7850
diff changeset
   229
                         "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
   230
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
    # 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
   232
    #     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
   233
    #     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
   234
    #     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
   235
    #     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
   236
    #                     ('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
   237
    #                     }, {})
7791
31bb51ea5485 [deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7790
diff changeset
   238
    #     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
   239
    #                          "")
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   240
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
   241
    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
   242
        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
   243
        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
   244
        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
   245
        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
   246
                          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
   247
                                           ('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
   248
                                           ('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
   249
                                           }, {})
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
   250
7843
3b51806da60b [rqlrewrite] if inlined relation has to be moved to a subquery, take care of the object of the relation (closes #1945725)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7555
diff changeset
   251
    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
   252
        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
   253
        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
   254
        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
   255
                      '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
   256
        rewrite(rqlst, {('C', 'X'): (c1,)}, {})
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   257
        self.assertEqual(rqlst.as_string(),
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   258
                         '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
   259
                         '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
   260
                         'N inlined_affaire W, EXISTS(C require_permission B), '
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   261
                         '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
   262
3443
34e451da9b5d [security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   263
    def test_relation_optimization_1_lhs(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
        # since Card in_state State as monovalued cardinality, the in_state
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
        # 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
   266
        # 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
   267
        snippet = ('X in_state S, S name "hop"')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
        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
   269
        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
   270
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   271
                         "Any C WHERE C in_state STATE, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   272
                         "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
   273
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
   274
    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
   275
        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
   276
        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
   277
        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
   278
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   279
                         "Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   280
                         "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
   281
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
    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
   283
        # 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
   284
        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
   285
        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
   286
        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
   287
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   288
                         "Any C WHERE C in_state STATE?, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   289
                         "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
   290
    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
   291
        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
   292
        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
   293
        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
   294
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   295
                         "Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   296
                         "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
   297
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
    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
   299
        # 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
   300
        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
   301
        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
   302
        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
   303
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   304
                         "Any C WHERE C in_state STATE, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   305
                         "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
   306
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
   307
    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
   308
        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
   309
        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
   310
        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
   311
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   312
                         "Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   313
                         "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
   314
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
    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
   316
        # 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
   317
        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
   318
        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
   319
        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
   320
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   321
                         "Any C WHERE C in_state STATE?, C is Card, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   322
                         "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
   323
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
   324
    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
   325
        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
   326
        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
   327
        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
   328
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   329
                         "Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, "
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   330
                         "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
   331
                         "C is WorkflowTransition")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   332
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
   333
    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
   334
        """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
   335
        # '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
   336
        # 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
   337
        # 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
   338
        # 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
   339
        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
   340
        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
   341
                        ('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
   342
        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
   343
                         '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
   344
                         '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
   345
                         '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
   346
                         '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
   347
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   348
    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
   349
        # CWUser doesn't have require_permission
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   350
        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
   351
        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
   352
        self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   353
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   354
    def test_unsupported_constraint_2(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   355
        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
   356
        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
   357
        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
   358
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   359
                         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
   360
                         "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
   361
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   362
    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
   363
        self.skipTest('raise unauthorized for now')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
        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
   365
        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
   366
        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
   367
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   368
                         u'XXX dunno what should be generated')
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   369
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   370
    def test_add_ambiguity_exists(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   371
        constraint = ('X concerne Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   372
        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
   373
        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
   374
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   375
                         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
   376
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   377
    def test_add_ambiguity_outerjoin(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   378
        constraint = ('X concerne Y')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   379
        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
   380
        rewrite(rqlst, {('X', 'X'): (constraint,)}, {})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   381
        # 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
   382
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   383
                         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
   384
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   385
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
   386
    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
   387
        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
   388
        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
   389
        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
   390
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   391
                         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
   392
        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
   393
        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
   394
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   395
                         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
   396
        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
   397
        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
   398
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   399
                         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
   400
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
    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
   402
        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
   403
        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
   404
        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
   405
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   406
                         '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
   407
        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
   408
        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
   409
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   410
                         '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
   411
        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
   412
        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
   413
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   414
                         '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
   415
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
    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
   417
        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
   418
        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
   419
        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
   420
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   421
                         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
   422
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
    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
   424
        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
   425
        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
   426
        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
   427
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   428
                         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
   429
        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
   430
        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
   431
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   432
                         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
   433
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
    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
   435
        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
   436
        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
   437
        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
   438
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   439
                         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
   440
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
   441
    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
   442
        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
   443
        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
   444
        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
   445
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   446
                         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
   447
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
   448
    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
   449
        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
   450
        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
   451
        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
   452
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   453
                         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
   454
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
   455
    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
   456
        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
   457
        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
   458
        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
   459
        self.assertEqual(rqlst.as_string(),
8113
1e8c92202f44 [test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7868
diff changeset
   460
                         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
   461
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
   462
    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
   463
        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
   464
        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
   465
        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
   466
        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
   467
        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
   468
        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
   469
                         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
   470
                         '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
   471
                         '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
   472
                         '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
   473
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
   474
    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
   475
        #: 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
   476
        #: (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
   477
        #:
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
        #: 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
   479
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
        # 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
   481
        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
   482
        # 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
   483
        # 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
   484
        # 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
   485
        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
   486
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
        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
   488
        rewrite(rqlst, {('A', 'X'): (c_ok, c_bad)}, {})
1787
71c143c0ada3 fix test
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   489
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
   490
    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
   491
        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
   492
        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
   493
        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
   494
        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
   495
                         '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
   496
                         '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
   497
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   498
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
   499
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
   500
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   501
class RewriteFullTC(CubicWebTC):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   502
    @classproperty
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   503
    def config(cls):
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   504
        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
   505
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   506
    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
   507
        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
   508
            args = {}
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   509
        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
   510
        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
   511
        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
   512
            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
   513
            querier._annotate(union)
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   514
            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
   515
            plan.preprocess(union)
2219bd9f35db [test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9593
diff changeset
   516
            return union
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   517
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   518
    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
   519
        """See #3013535"""
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   520
        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
   521
        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
   522
        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
   523
        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
   524
                                        (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
   525
                                        (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
   526
            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
   527
            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
   528
                             '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
   529
                             '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
   530
                             union.as_string())
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   531
9327
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   532
    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
   533
        """See #3013554"""
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   534
        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
   535
        edef1 = self.schema['Societe']
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   536
        edef2 = self.schema['Division']
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   537
        edef3 = self.schema['Note']
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   538
        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
   539
                                        (edef2, {'read': ('users',)}),
dbabdc323e7d add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9262
diff changeset
   540
                                        (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
   541
            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
   542
            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
   543
9168
0fb4b67bde58 [schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8342
diff changeset
   544
9189
9448215c73c4 [rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9188
diff changeset
   545
    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
   546
        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
   547
        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
   548
        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
   549
        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
   550
                                        (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
   551
            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
   552
                                 '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
   553
                                 '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
   554
            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
   555
                             '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
   556
                             '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
   557
                             '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
   558
                             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
   559
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
   560
    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
   561
        # 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
   562
        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
   563
        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
   564
        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
   565
        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
   566
        # 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
   567
        # 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
   568
        @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
   569
        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
   570
            # 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
   571
            # 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
   572
            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
   573
                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
   574
            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
   575
        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
   576
            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
   577
                    (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
   578
                     {'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
   579
                    (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
   580
                     {'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
   581
                         '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
   582
            ):
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
                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
   584
                    '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
   585
                    '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
   586
                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
   587
                                 '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
   588
                                 '(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
   589
                                 '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
   590
                                 '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
   591
                                 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
   592
        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
   593
            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
   594
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   595
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   596
class RQLRelationRewriterTC(TestCase):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   597
    # XXX valid rules: S and O specified, not in a SET, INSERT, DELETE scope
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   598
    #     valid uses: no outer join
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   599
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   600
    # Basic tests
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   601
    def test_base_rule(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   602
        rules = {'participated_in': 'S contributor O'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   603
        rqlst = rqlhelper.parse('Any X WHERE X participated_in S')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   604
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   605
        self.assertEqual('Any X WHERE X contributor S',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   606
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   607
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   608
    def test_complex_rule_1(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   609
        rules = {'illustrator_of': ('C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   610
                                    'C manifestation O, C role R, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   611
                                    'R name "illustrator"')}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   612
        rqlst = rqlhelper.parse('Any A,B WHERE A illustrator_of B')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   613
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   614
        self.assertEqual('Any A,B WHERE C is Contribution, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   615
                         'C contributor A, C manifestation B, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   616
                         'C role D, D name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   617
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   618
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   619
    def test_complex_rule_2(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   620
        rules = {'illustrator_of': ('C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   621
                                    'C manifestation O, C role R, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   622
                                    'R name "illustrator"')}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   623
        rqlst = rqlhelper.parse('Any A WHERE EXISTS(A illustrator_of B)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   624
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   625
        self.assertEqual('Any A WHERE EXISTS(C is Contribution, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   626
                         'C contributor A, C manifestation B, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   627
                         'C role D, D name "illustrator")',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   628
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   629
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   630
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   631
    def test_rewrite2(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   632
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   633
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   634
        rqlst = rqlhelper.parse('Any A,B WHERE A illustrator_of B, C require_permission R, S'
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   635
                                'require_state O')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   636
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   637
        self.assertEqual('Any A,B WHERE C require_permission R, S require_state O, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   638
                         'D is Contribution, D contributor A, D manifestation B, D role E, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   639
                         'E name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   640
                          rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   641
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   642
    def test_rewrite3(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   643
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   644
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   645
        rqlst = rqlhelper.parse('Any A,B WHERE E require_permission T, A illustrator_of B')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   646
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   647
        self.assertEqual('Any A,B WHERE E require_permission T, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   648
                         'C is Contribution, C contributor A, C manifestation B, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   649
                         'C role D, D name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   650
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   651
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   652
    def test_rewrite4(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   653
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   654
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   655
        rqlst = rqlhelper.parse('Any A,B WHERE C require_permission R, A illustrator_of B')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   656
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   657
        self.assertEqual('Any A,B WHERE C require_permission R, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   658
                         'D is Contribution, D contributor A, D manifestation B, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   659
                         'D role E, E name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   660
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   661
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   662
    def test_rewrite5(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   663
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   664
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   665
        rqlst = rqlhelper.parse('Any A,B WHERE C require_permission R, A illustrator_of B, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   666
                                'S require_state O')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   667
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   668
        self.assertEqual('Any A,B WHERE C require_permission R, S require_state O, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   669
                         'D is Contribution, D contributor A, D manifestation B, D role E, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   670
                         'E name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   671
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   672
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   673
    # Tests for the with clause
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   674
    def test_rewrite_with(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   675
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   676
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   677
        rqlst = rqlhelper.parse('Any A,B WITH A, B BEING(Any X, Y WHERE X illustrator_of Y)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   678
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   679
        self.assertEqual('Any A,B WITH A,B BEING '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   680
                         '(Any X,Y WHERE A is Contribution, A contributor X, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   681
                         'A manifestation Y, A role B, B name "illustrator")',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   682
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   683
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   684
    def test_rewrite_with2(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   685
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   686
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   687
        rqlst = rqlhelper.parse('Any A,B WHERE T require_permission C WITH A, B BEING(Any X, Y WHERE X illustrator_of Y)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   688
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   689
        self.assertEqual('Any A,B WHERE T require_permission C '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   690
                         'WITH A,B BEING (Any X,Y WHERE A is Contribution, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   691
                         'A contributor X, A manifestation Y, A role B, B name "illustrator")',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   692
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   693
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   694
    def test_rewrite_with3(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   695
        rules = {'participated_in': 'S contributor O'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   696
        rqlst = rqlhelper.parse('Any A,B WHERE A participated_in B '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   697
                                'WITH A, B BEING(Any X,Y WHERE X contributor Y)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   698
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   699
        self.assertEqual('Any A,B WHERE A contributor B WITH A,B BEING '
9955
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   700
                         '(Any X,Y WHERE X contributor Y)',
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   701
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   702
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   703
    def test_rewrite_with4(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   704
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   705
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   706
        rqlst = rqlhelper.parse('Any A,B WHERE A illustrator_of B '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   707
                               'WITH A, B BEING(Any X, Y WHERE X illustrator_of Y)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   708
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   709
        self.assertEqual('Any A,B WHERE C is Contribution, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   710
                         'C contributor A, C manifestation B, C role D, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   711
                         'D name "illustrator" WITH A,B BEING '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   712
                         '(Any X,Y WHERE A is Contribution, A contributor X, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   713
                         'A manifestation Y, A role B, B name "illustrator")',
9955
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   714
                          rqlst.as_string())
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   715
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   716
    # Tests for the union
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   717
    def test_rewrite_union(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   718
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   719
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   720
        rqlst = rqlhelper.parse('(Any A,B WHERE A illustrator_of B) UNION'
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   721
                                '(Any X,Y WHERE X is CWUser, Z manifestation Y)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   722
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   723
        self.assertEqual('(Any A,B WHERE C is Contribution, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   724
                         'C contributor A, C manifestation B, C role D, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   725
                         'D name "illustrator") UNION (Any X,Y WHERE X is CWUser, Z manifestation Y)',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   726
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   727
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   728
    def test_rewrite_union2(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   729
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   730
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   731
        rqlst = rqlhelper.parse('(Any Y WHERE Y match W) UNION '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   732
                                '(Any A WHERE A illustrator_of B) UNION '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   733
                                '(Any Y WHERE Y is ArtWork)')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   734
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   735
        self.assertEqual('(Any Y WHERE Y match W) '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   736
                         'UNION (Any A WHERE C is Contribution, C contributor A, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   737
                         'C manifestation B, C role D, D name "illustrator") '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   738
                         'UNION (Any Y WHERE Y is ArtWork)',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   739
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   740
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   741
    # Tests for the exists clause
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   742
    def test_rewrite_exists(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   743
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   744
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   745
        rqlst = rqlhelper.parse('(Any A,B WHERE A illustrator_of B, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   746
                     'EXISTS(B is ArtWork))')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   747
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   748
        self.assertEqual('Any A,B WHERE EXISTS(B is ArtWork), '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   749
                         'C is Contribution, C contributor A, C manifestation B, C role D, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   750
                         'D name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   751
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   752
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   753
    def test_rewrite_exists2(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   754
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   755
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   756
        rqlst = rqlhelper.parse('(Any A,B WHERE B contributor A, EXISTS(A illustrator_of W))')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   757
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   758
        self.assertEqual('Any A,B WHERE B contributor A, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   759
                         'EXISTS(C is Contribution, C contributor A, C manifestation W, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   760
                         'C role D, D name "illustrator")',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   761
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   762
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   763
    def test_rewrite_exists3(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   764
        rules = {'illustrator_of': 'C is Contribution, C contributor S, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   765
                'C manifestation O, C role R, R name "illustrator"'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   766
        rqlst = rqlhelper.parse('(Any A,B WHERE A illustrator_of B, EXISTS(A illustrator_of W))')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   767
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   768
        self.assertEqual('Any A,B WHERE EXISTS(C is Contribution, C contributor A, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   769
                         'C manifestation W, C role D, D name "illustrator"), '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   770
                         'E is Contribution, E contributor A, E manifestation B, E role F, '
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   771
                         'F name "illustrator"',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   772
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   773
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   774
    # Test for GROUPBY
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   775
    def test_rewrite_groupby(self):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   776
        rules = {'participated_in': 'S contributor O'}
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   777
        rqlst = rqlhelper.parse('Any SUM(SA) GROUPBY S WHERE P participated_in S, P manifestation SA')
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   778
        rule_rewrite(rqlst, rules)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   779
        self.assertEqual('Any SUM(SA) GROUPBY S WHERE P manifestation SA, P contributor S',
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   780
                         rqlst.as_string())
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   781
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   782
9955
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   783
class RQLRelationRewriterTC(CubicWebTC):
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   784
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   785
    appid = 'data/rewrite'
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   786
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   787
    def test_base_rule(self):
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   788
        with self.admin_access.client_cnx() as cnx:
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   789
            art = cnx.create_entity('ArtWork', name=u'Les travailleurs de la Mer')
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   790
            role = cnx.create_entity('Role', name=u'illustrator')
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   791
            vic = cnx.create_entity('Person', name=u'Victor Hugo')
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   792
            contrib = cnx.create_entity('Contribution', code=96, contributor=vic,
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   793
                                        manifestation=art, role=role)
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   794
            rset = cnx.execute('Any X WHERE X illustrator_of S')
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   795
            self.assertEqual([u'Victor Hugo'],
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   796
                             [result.name for result in rset.entities()])
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   797
            rset = cnx.execute('Any S WHERE X illustrator_of S, X eid %(x)s',
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   798
                               {'x': vic.eid})
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   799
            self.assertEqual([u'Les travailleurs de la Mer'],
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   800
                             [result.name for result in rset.entities()])
60a9cd1b3a4b [CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 9953
diff changeset
   801
9953
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   802
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   803
def rule_rewrite(rqlst, kwargs=None):
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   804
    rewriter = _prepare_rewriter(rqlrewrite.RQLRelationRewriter, kwargs)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   805
    rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map},
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   806
                                kwargs=kwargs)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   807
    rewriter.rewrite(rqlst)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   808
    for select in rqlst.children:
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   809
        test_vrefs(select)
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   810
    return rewriter.rewritten
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   811
643b19d79e4a [CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9674
diff changeset
   812
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   813
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   814
    unittest_main()