author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 22 Sep 2015 15:24:58 +0200 | |
changeset 10730 | 874ac29b515d |
parent 10712 | f7227cbf1d18 |
permissions | -rw-r--r-- |
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 |
|
10612
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9955
diff
changeset
|
19 |
from six import string_types |
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9955
diff
changeset
|
20 |
|
0 | 21 |
from logilab.common.testlib import unittest_main, TestCase |
22 |
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
|
23 |
from yams import BadSchemaDefinition |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
24 |
from yams.buildobjs import RelationDefinition |
0 | 25 |
from rql import parse, nodes, RQLHelper |
26 |
||
7850
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7843
diff
changeset
|
27 |
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
|
28 |
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
|
29 |
from cubicweb.devtools import repotest, TestServerConfiguration, BaseApptestConfiguration |
0 | 30 |
|
31 |
||
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6640
diff
changeset
|
32 |
def setUpModule(*args): |
6640
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
33 |
global rqlhelper, schema |
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
34 |
config = TestServerConfiguration(RQLRewriteTC.datapath('rewrite')) |
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
35 |
config.bootstrap_cubes() |
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
object='State', cardinality='1*')) |
6640
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
39 |
rqlhelper = RQLHelper(schema, special_relations={'eid': 'uid', |
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
40 |
'has_text': 'fti'}) |
0 | 41 |
repotest.do_monkey_patch() |
42 |
||
6781
5062d86d6ffe
[unittest2] use unittest2 module fixture api
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6640
diff
changeset
|
43 |
def tearDownModule(*args): |
0 | 44 |
repotest.undo_monkey_patch() |
6640
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
45 |
global rqlhelper, schema |
4c4616c02f69
[test] more cwd independant tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
46 |
del rqlhelper, schema |
1787 | 47 |
|
0 | 48 |
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
|
49 |
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
|
50 |
2: 'Card', |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
51 |
3: 'Affaire'}[eid] |
0 | 52 |
|
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
53 |
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
|
54 |
class FakeVReg: |
0 | 55 |
schema = schema |
56 |
@staticmethod |
|
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
57 |
def solutions(sqlcursor, rqlst, kwargs): |
0 | 58 |
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
|
59 |
class rqlhelper: |
0 | 60 |
@staticmethod |
61 |
def annotate(rqlst): |
|
62 |
rqlhelper.annotate(rqlst) |
|
63 |
@staticmethod |
|
64 |
def simplify(mainrqlst, needcopy=False): |
|
65 |
rqlhelper.simplify(rqlst, needcopy) |
|
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
66 |
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
|
67 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
68 |
def rewrite(rqlst, snippets_map, kwargs, existingvars=None): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
69 |
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
|
70 |
snippets = [] |
7850
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7843
diff
changeset
|
71 |
for v, exprs in sorted(snippets_map.items()): |
10612
84468b90e9c1
[py3k] basestring → six.string_types
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9955
diff
changeset
|
72 |
rqlexprs = [isinstance(snippet, string_types) |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
73 |
and mock_object(snippet_rqlst=parse(u'Any X WHERE '+snippet).children[0], |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
74 |
expression=u'Any X WHERE '+snippet) |
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
|
75 |
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
|
76 |
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
|
77 |
snippets.append((dict([v]), rqlexprs)) |
0 | 78 |
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
|
79 |
rewriter.rewrite(rqlst.children[0], snippets, kwargs, existingvars) |
0 | 80 |
test_vrefs(rqlst.children[0]) |
81 |
return rewriter.rewritten |
|
82 |
||
83 |
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
|
84 |
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
|
85 |
selects = [] |
0 | 86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
selects.append(stmt) |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
93 |
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
|
94 |
for stmt in selects: |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10654
diff
changeset
|
95 |
for var in stmt.defined_vars.values(): |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
|
0 | 100 |
|
101 |
class RQLRewriteTC(TestCase): |
|
102 |
"""a faire: |
|
103 |
||
104 |
* optimisation: detecter les relations utilisees dans les rqlexpressions qui |
|
105 |
sont presentes dans la requete de depart pour les reutiliser si possible |
|
1787 | 106 |
|
0 | 107 |
* "has_<ACTION>_permission" ? |
108 |
""" |
|
1787 | 109 |
|
0 | 110 |
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
|
111 |
constraint = ('X in_state S, U in_group G, P require_state S,' |
0 | 112 |
'P name "read", P require_group G') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
113 |
rqlst = parse(u'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
|
114 |
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
|
115 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
116 |
u'Any C WHERE C is Card, B eid %(D)s, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
117 |
'EXISTS(C in_state A, B in_group E, F require_state A, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
118 |
'F name "read", F require_group E, A is State, E is CWGroup, F is CWPermission)') |
1787 | 119 |
|
0 | 120 |
def test_multiple_var(self): |
121 |
card_constraint = ('X in_state S, U in_group G, P require_state S,' |
|
122 |
'P name "read", P require_group G') |
|
123 |
affaire_constraints = ('X ref LIKE "PUBLIC%"', 'U in_group G, G name "public"') |
|
124 |
kwargs = {'u':2} |
|
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
125 |
rqlst = parse(u'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
|
126 |
rewrite(rqlst, {('C', 'X'): (card_constraint,), ('S', 'X'): affaire_constraints}, |
0 | 127 |
kwargs) |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
128 |
self.assertMultiLineEqual( |
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
129 |
rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
130 |
u'Any S WHERE S documented_by C, C eid %(u)s, B eid %(D)s, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
131 |
'EXISTS(C in_state A, B in_group E, F require_state A, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
132 |
'F name "read", F require_group E, A is State, E is CWGroup, F is CWPermission), ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
133 |
'(EXISTS(S ref LIKE "PUBLIC%")) OR (EXISTS(B in_group G, G name "public", G is CWGroup)), ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
134 |
'S is Affaire') |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
9655
diff
changeset
|
135 |
self.assertIn('D', kwargs) |
1787 | 136 |
|
0 | 137 |
def test_or(self): |
138 |
constraint = '(X identity U) OR (X in_state ST, CL identity U, CL in_state ST, ST name "subscribed")' |
|
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
139 |
rqlst = parse(u'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
|
140 |
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
|
141 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
142 |
'Any S WHERE S owned_by C, C eid %(u)s, S is IN(CWUser, CWGroup), A eid %(B)s, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
143 |
'EXISTS((C identity A) OR (C in_state D, E identity A, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
144 |
'E in_state D, D name "subscribed"), D is State, E is CWUser)') |
0 | 145 |
|
146 |
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
|
147 |
constraint = ('X in_state S, U in_group G, P require_state S,' |
0 | 148 |
'P name "read", P require_group G') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
149 |
rqlst = parse(u'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
|
150 |
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
|
151 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
152 |
u'Any 2 WHERE B eid %(C)s, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
153 |
'EXISTS(2 in_state A, B in_group D, E require_state A, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
154 |
'E name "read", E require_group D, A is State, D is CWGroup, E is CWPermission)') |
0 | 155 |
|
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
|
156 |
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
|
157 |
constraint = ('X in_state S, U in_group G, P require_state S,' |
0 | 158 |
'P name "read", P require_group G') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
159 |
rqlst = parse(u'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
|
160 |
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
|
161 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
162 |
u'Any A,C WHERE A documented_by C?, A is Affaire ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
163 |
'WITH C BEING ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
164 |
'(Any C WHERE EXISTS(C in_state B, D in_group F, G require_state B, G name "read", ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
165 |
'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
|
166 |
|
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
|
167 |
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
|
168 |
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
|
169 |
'P name "read", P require_group G') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
170 |
rqlst = parse(u'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
|
171 |
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
|
172 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
173 |
u'Any A,C,T WHERE A documented_by C?, A is Affaire ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
174 |
'WITH C,T BEING ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
175 |
'(Any C,T WHERE C title T, EXISTS(C in_state B, D in_group F, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
176 |
'G require_state B, G name "read", G require_group F), ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
177 |
'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
|
178 |
|
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
|
179 |
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
|
180 |
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
|
181 |
'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
|
182 |
constraint2 = 'X in_state S, S name "public"' |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
183 |
rqlst = parse(u'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
|
184 |
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
|
185 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
186 |
u'Any A,C,T WHERE A documented_by C?, A is Affaire ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
187 |
'WITH C,T BEING (Any C,T WHERE C title T, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
188 |
'(EXISTS(C in_state B, D in_group F, G require_state B, G name "read", G require_group F)) ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
189 |
'OR (EXISTS(C in_state E, E name "public")), ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
190 |
'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
|
191 |
|
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
|
192 |
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
|
193 |
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
|
194 |
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
|
195 |
constraint3 = 'X created_by U' |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
196 |
rqlst = parse(u'Any X,LA,Y WHERE LA? documented_by X, LA concerne Y') |
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
|
197 |
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
|
198 |
('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
|
199 |
('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
|
200 |
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
|
201 |
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
|
202 |
'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
|
203 |
'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
|
204 |
'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
|
205 |
'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
|
206 |
|
9168
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
207 |
|
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
208 |
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
|
209 |
"""See #3013535""" |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
210 |
# 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
|
211 |
# 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
|
212 |
# RQLRewriter.insert_local_checks |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
213 |
rqlst = parse(u'Any A,AR,X,CD WHERE A concerne X?, A ref AR, A eid %(a)s, X creation_date CD') |
9168
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
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
|
217 |
|
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
|
218 |
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
|
219 |
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
|
220 |
c2 = ('X inlined_card O, O require_permission P') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
221 |
rqlst = parse(u'Any C,A,R WHERE A? inlined_card C, A ref R') |
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
|
222 |
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
|
223 |
('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
|
224 |
}, {}) |
e623afd49356
[rql rewriting] handle case where we've and optional inlined relation in the original query. Also, we should append EXISTS even in subquery to avoid inserting duplicates in results
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
225 |
# XXX suboptimal |
7790
7e16e056eecb
[test] fix test subsquently to localperms introduction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7555
diff
changeset
|
226 |
self.assertEqual(rqlst.as_string(), |
7868 | 227 |
"Any C,A,R WITH A,C,R BEING " |
228 |
"(Any A,C,R WHERE A? inlined_card C, A ref R, " |
|
229 |
"(A is NULL) OR (EXISTS(A inlined_card B, B require_permission D, " |
|
230 |
"B is Card, D is CWPermission)), " |
|
231 |
"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
|
232 |
|
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 |
# 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
|
234 |
# 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
|
235 |
# c2 = ('X inlined_card O, U has_read_permission O') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
236 |
# rqlst = parse(u'Any C,A,R WHERE A? inlined_card C, A ref R') |
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
|
237 |
# 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
|
238 |
# ('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
|
239 |
# }, {}) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7790
diff
changeset
|
240 |
# 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
|
241 |
# "") |
1787 | 242 |
|
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
|
243 |
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
|
244 |
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
|
245 |
c2 = ('X inlined_card O, O require_permission P') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
246 |
rqlst = parse(u'Any C,A,R,A2,R2 WHERE A? inlined_card C, A ref R,A2? inlined_card C, A2 ref R2') |
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
|
247 |
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
|
248 |
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
|
249 |
('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
|
250 |
('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
|
251 |
}, {}) |
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
|
252 |
|
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
|
253 |
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
|
254 |
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
|
255 |
c2 = ('X inlined_card O, O require_permission P') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
256 |
rqlst = parse(u'Any A,W WHERE A inlined_card C?, C inlined_note N, ' |
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
|
257 |
'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
|
258 |
rewrite(rqlst, {('C', 'X'): (c1,)}, {}) |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
259 |
self.assertEqual(rqlst.as_string(), |
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
260 |
'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
|
261 |
'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
|
262 |
'N inlined_affaire W, EXISTS(C require_permission B), ' |
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
263 |
'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
|
264 |
|
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
|
265 |
def test_relation_optimization_1_lhs(self): |
0 | 266 |
# since Card in_state State as monovalued cardinality, the in_state |
267 |
# relation used in the rql expression can be ignored and S replaced by |
|
268 |
# 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
|
269 |
snippet = ('X in_state S, S name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
270 |
rqlst = parse(u'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
|
271 |
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
|
272 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
273 |
'Any C WHERE C in_state STATE, C is Card, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
274 |
'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
|
275 |
|
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
|
276 |
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
|
277 |
snippet = ('TW subworkflow_exit X, TW name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
278 |
rqlst = parse(u'WorkflowTransition C WHERE C subworkflow_exit EXIT') |
3443
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
279 |
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
|
280 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
281 |
'Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
282 |
'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
|
283 |
|
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 |
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
|
285 |
# 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
|
286 |
snippet = ('X in_state S?, S name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
287 |
rqlst = parse(u'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
|
288 |
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
|
289 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
290 |
'Any C WHERE C in_state STATE?, C is Card, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
291 |
'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
|
292 |
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
|
293 |
snippet = ('TW? subworkflow_exit X, TW name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
294 |
rqlst = parse(u'SubWorkflowExitPoint EXIT WHERE C? subworkflow_exit EXIT') |
3443
34e451da9b5d
[security] test and fix/refactor optimization of optional varialbe when rewriting rql
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
295 |
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
|
296 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
297 |
'Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
298 |
'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
|
299 |
|
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 |
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
|
301 |
# 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
|
302 |
snippet = ('X in_state S?, S name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
303 |
rqlst = parse(u'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
|
304 |
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
|
305 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
306 |
'Any C WHERE C in_state STATE, C is Card, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
307 |
'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
|
308 |
|
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
|
309 |
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
|
310 |
snippet = ('TW? subworkflow_exit X, TW name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
311 |
rqlst = parse(u'WorkflowTransition C WHERE C subworkflow_exit EXIT') |
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
|
312 |
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
|
313 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
314 |
'Any C WHERE C subworkflow_exit EXIT, C is WorkflowTransition, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
315 |
'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
|
316 |
|
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 |
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
|
318 |
# 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
|
319 |
snippet = ('X in_state S, S name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
320 |
rqlst = parse(u'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
|
321 |
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
|
322 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
323 |
'Any C WHERE C in_state STATE?, C is Card, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
324 |
'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
|
325 |
|
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
|
326 |
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
|
327 |
snippet = ('TW subworkflow_exit X, TW name "hop"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
328 |
rqlst = parse(u'SubWorkflowExitPoint EXIT WHERE C? subworkflow_exit EXIT') |
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
|
329 |
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
|
330 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
331 |
'Any EXIT WHERE C? subworkflow_exit EXIT, EXIT is SubWorkflowExitPoint, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
332 |
'EXISTS(A subworkflow_exit EXIT, A name "hop", A is WorkflowTransition), ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
333 |
'C is WorkflowTransition') |
0 | 334 |
|
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
|
335 |
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
|
336 |
"""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
|
337 |
# '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
|
338 |
# 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
|
339 |
# 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
|
340 |
# the table will be in the FROM clause of the outermost query |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
341 |
rqlst = parse(u'Any A,C WHERE A inlined_card C') |
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
|
342 |
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
|
343 |
('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
|
344 |
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
|
345 |
'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
|
346 |
'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
|
347 |
'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
|
348 |
'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
|
349 |
|
0 | 350 |
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
|
351 |
# CWUser doesn't have require_permission |
0 | 352 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
353 |
rqlst = parse(u'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
|
354 |
self.assertRaises(Unauthorized, rewrite, rqlst, {('T', 'X'): (trinfo_constraint,)}, {}) |
1787 | 355 |
|
0 | 356 |
def test_unsupported_constraint_2(self): |
357 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
|
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
358 |
rqlst = parse(u'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
|
359 |
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
|
360 |
self.assertEqual(rqlst.as_string(), |
10654
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
361 |
u'Any U,T WHERE U is CWUser, T wf_info_for U, ' |
d6d9913753d2
[test] use unicode for rql queries (1/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10612
diff
changeset
|
362 |
'EXISTS(U in_group B, B name "managers", B is CWGroup), T is TrInfo') |
0 | 363 |
|
364 |
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
|
365 |
self.skipTest('raise unauthorized for now') |
0 | 366 |
trinfo_constraint = ('X wf_info_for Y, Y require_permission P, P name "read"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
367 |
rqlst = parse(u'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
|
368 |
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
|
369 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
370 |
u'XXX dunno what should be generated') |
1787 | 371 |
|
0 | 372 |
def test_add_ambiguity_exists(self): |
373 |
constraint = ('X concerne Y') |
|
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
374 |
rqlst = parse(u'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
|
375 |
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
|
376 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
377 |
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 | 378 |
|
0 | 379 |
def test_add_ambiguity_outerjoin(self): |
380 |
constraint = ('X concerne Y') |
|
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
381 |
rqlst = parse(u'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
|
382 |
rewrite(rqlst, {('X', 'X'): (constraint,)}, {}) |
0 | 383 |
# 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
|
384 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
385 |
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 | 386 |
|
387 |
||
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
|
388 |
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
|
389 |
constraint = RRQLExpression('S owned_by U') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
390 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
391 |
rewrite(rqlst, {('C', 'S'): (constraint,)}, {}, 'SU') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7790
diff
changeset
|
392 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
393 |
u"Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)") |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
394 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
395 |
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
|
396 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
397 |
u"Any C WHERE C is Card") |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
398 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
399 |
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
|
400 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
401 |
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
|
402 |
|
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 |
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
|
404 |
constraint = RRQLExpression('S owned_by U, O owned_by U, O is Card') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
405 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
406 |
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
|
407 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
408 |
'Any C WHERE C is Card, A eid %(B)s, EXISTS(C owned_by A)') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
409 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
410 |
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
|
411 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
412 |
'Any C WHERE C is Card, B eid %(D)s, EXISTS(A owned_by B, A is Card)') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
413 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
414 |
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
|
415 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
416 |
'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
|
417 |
|
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 |
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
|
419 |
constraint = RRQLExpression('U in_group G, G name "users"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
420 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
421 |
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
|
422 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
423 |
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
|
424 |
|
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 |
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
|
426 |
constraint = RRQLExpression('U in_group G, G name "users", S owned_by U') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
427 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
428 |
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
|
429 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
430 |
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)') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
431 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
432 |
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
|
433 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
434 |
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
|
435 |
|
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 |
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
|
437 |
constraint = RRQLExpression('S owned_by Z, O owned_by Z, O is Card') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
438 |
rqlst = parse(u'Card C') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3443
diff
changeset
|
439 |
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
|
440 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
441 |
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
|
442 |
|
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
|
443 |
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
|
444 |
constraint = ERQLExpression('X owned_by Z, Z login "hop"', 'X') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
445 |
rqlst = parse(u'Affaire A WHERE NOT EXISTS(A documented_by C)') |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
446 |
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
|
447 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
448 |
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
|
449 |
|
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 |
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
|
451 |
constraint = ERQLExpression('X owned_by Z, Z login "hop"', 'X') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
452 |
rqlst = parse(u'Affaire A WHERE NOT EXISTS(A documented_by C)') |
7251
163a2eab0e55
[rql rewrite] backout 7177:f2a976cf7dac : since EXISTS is the variable scope, we want to insert snippets here anyway (other solution would be to NOT insert snippets at all in such case). Closes #1625464
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
453 |
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
|
454 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
455 |
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
|
456 |
|
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
|
457 |
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
|
458 |
constraint = ERQLExpression('X owned_by Z, Z login "hop"', 'X') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
459 |
rqlst = rqlhelper.parse(u'Affaire A WHERE NOT A documented_by C', annotate=False) |
5582
3e133b29a1a4
[rql2sql] follow rql 0.26.1 changes: NOT nodes normalization, allowing simplification of sql generation, and fix #XXX
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
460 |
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
|
461 |
self.assertEqual(rqlst.as_string(), |
8113
1e8c92202f44
[test] reindent
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7868
diff
changeset
|
462 |
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
|
463 |
|
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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
c3 = ERQLExpression('X owned_by Z, Z login "momo"', 'X') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
468 |
rqlst = rqlhelper.parse(u'Any A WHERE A documented_by C?', annotate=False) |
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
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
'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
|
473 |
'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
|
474 |
'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
|
475 |
|
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
|
476 |
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
|
477 |
#: 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
|
478 |
#: (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
|
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 |
#: 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
|
481 |
|
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 |
# 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
|
483 |
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
|
484 |
# 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
|
485 |
# 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
|
486 |
# 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
|
487 |
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
|
488 |
|
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
489 |
rqlst = parse(u'Any A, R WHERE A ref R, S is Affaire') |
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
|
490 |
rewrite(rqlst, {('A', 'X'): (c_ok, c_bad)}, {}) |
1787 | 491 |
|
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
|
492 |
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
|
493 |
user_expr = ERQLExpression('NOT X in_group AF, AF name "guests"') |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
494 |
rqlst = parse(u'Any O WHERE S use_email O, S is CWUser, O is_instance_of EmailAddress') |
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
|
495 |
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
|
496 |
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
|
497 |
'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
|
498 |
'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
|
499 |
|
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
|
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
503 |
class RewriteFullTC(CubicWebTC): |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
504 |
@classproperty |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
505 |
def config(cls): |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
506 |
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
|
507 |
|
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
508 |
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
|
509 |
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
|
510 |
args = {} |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
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
|
515 |
querier._annotate(union) |
2219bd9f35db
[test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9593
diff
changeset
|
516 |
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
|
517 |
plan.preprocess(union) |
2219bd9f35db
[test] update unittest_rqlrewrite to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9593
diff
changeset
|
518 |
return union |
9168
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
519 |
|
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
520 |
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
|
521 |
"""See #3013535""" |
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
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
|
525 |
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
|
526 |
(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
|
527 |
(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
|
528 |
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
|
529 |
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
|
530 |
'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
|
531 |
'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
|
532 |
union.as_string()) |
9448215c73c4
[rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9188
diff
changeset
|
533 |
|
9327
dbabdc323e7d
add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9262
diff
changeset
|
534 |
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
|
535 |
"""See #3013554""" |
dbabdc323e7d
add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9262
diff
changeset
|
536 |
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
|
537 |
edef1 = self.schema['Societe'] |
dbabdc323e7d
add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9262
diff
changeset
|
538 |
edef2 = self.schema['Division'] |
dbabdc323e7d
add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9262
diff
changeset
|
539 |
edef3 = self.schema['Note'] |
dbabdc323e7d
add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9262
diff
changeset
|
540 |
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
|
541 |
(edef2, {'read': ('users',)}), |
dbabdc323e7d
add failing test case related to #3013554
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9262
diff
changeset
|
542 |
(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
|
543 |
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
|
544 |
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
|
545 |
|
9168
0fb4b67bde58
[schema/security] add __hash__ to rql expression. Closes #3013535
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8342
diff
changeset
|
546 |
|
9189
9448215c73c4
[rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9188
diff
changeset
|
547 |
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
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
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
|
552 |
(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
|
553 |
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
|
554 |
'WHERE X responsable E, X nom AA, ' |
9448215c73c4
[rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9188
diff
changeset
|
555 |
'X responsable AC?, AC modification_date AD') |
9448215c73c4
[rqlrewrite] fix rqlrewrite unpredictability vs relation sharing. Closes #3036144
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9188
diff
changeset
|
556 |
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
|
557 |
'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
|
558 |
'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
|
559 |
'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
|
560 |
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
|
561 |
|
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
|
562 |
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
|
563 |
# 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
|
564 |
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
|
565 |
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
|
566 |
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
|
567 |
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
|
568 |
# 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
|
569 |
# 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
|
570 |
@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
|
571 |
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
|
572 |
# 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
|
573 |
# 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
|
574 |
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
|
575 |
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
|
576 |
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
|
577 |
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
|
578 |
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
|
579 |
(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
|
580 |
{'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
|
581 |
(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
|
582 |
{'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
|
583 |
'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
|
584 |
): |
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 |
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
|
586 |
'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
|
587 |
'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
|
588 |
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
|
589 |
'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
|
590 |
'(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
|
591 |
'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
|
592 |
'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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
|
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
597 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
598 |
class RQLRelationRewriterTC(TestCase): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
599 |
# 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
|
600 |
# valid uses: no outer join |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
601 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
602 |
# Basic tests |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
603 |
def test_base_rule(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
604 |
rules = {'participated_in': 'S contributor O'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
605 |
rqlst = rqlhelper.parse(u'Any X WHERE X participated_in S') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
606 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
607 |
self.assertEqual('Any X WHERE X contributor S', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
608 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
609 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
610 |
def test_complex_rule_1(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
611 |
rules = {'illustrator_of': ('C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
612 |
'C manifestation O, C role R, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
613 |
'R name "illustrator"')} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
614 |
rqlst = rqlhelper.parse(u'Any A,B WHERE A illustrator_of B') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
615 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
616 |
self.assertEqual('Any A,B WHERE C is Contribution, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
617 |
'C contributor A, C manifestation B, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
618 |
'C role D, D name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
619 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
620 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
621 |
def test_complex_rule_2(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
622 |
rules = {'illustrator_of': ('C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
623 |
'C manifestation O, C role R, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
624 |
'R name "illustrator"')} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
625 |
rqlst = rqlhelper.parse(u'Any A WHERE EXISTS(A illustrator_of B)') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
626 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
627 |
self.assertEqual('Any A WHERE EXISTS(C is Contribution, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
628 |
'C contributor A, C manifestation B, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
629 |
'C role D, D name "illustrator")', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
630 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
631 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
632 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
633 |
def test_rewrite2(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
634 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
635 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
636 |
rqlst = rqlhelper.parse(u'Any A,B WHERE A illustrator_of B, C require_permission R, S' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
637 |
'require_state O') |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
638 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
639 |
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
|
640 |
'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
|
641 |
'E name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
642 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
643 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
644 |
def test_rewrite3(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
645 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
646 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
647 |
rqlst = rqlhelper.parse(u'Any A,B WHERE E require_permission T, A illustrator_of B') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
648 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
649 |
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
|
650 |
'C is Contribution, C contributor A, C manifestation B, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
651 |
'C role D, D name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
652 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
653 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
654 |
def test_rewrite4(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
655 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
656 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
657 |
rqlst = rqlhelper.parse(u'Any A,B WHERE C require_permission R, A illustrator_of B') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
658 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
659 |
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
|
660 |
'D is Contribution, D contributor A, D manifestation B, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
661 |
'D role E, E name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
662 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
663 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
664 |
def test_rewrite5(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
665 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
666 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
667 |
rqlst = rqlhelper.parse(u'Any A,B WHERE C require_permission R, A illustrator_of B, ' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
668 |
'S require_state O') |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
669 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
670 |
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
|
671 |
'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
|
672 |
'E name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
673 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
674 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
675 |
# Tests for the with clause |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
676 |
def test_rewrite_with(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
677 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
678 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
679 |
rqlst = rqlhelper.parse(u'Any A,B WITH A, B BEING(Any X, Y WHERE X illustrator_of Y)') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
680 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
681 |
self.assertEqual('Any A,B WITH A,B BEING ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
682 |
'(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
|
683 |
'A manifestation Y, A role B, B name "illustrator")', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
684 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
685 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
686 |
def test_rewrite_with2(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
687 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
688 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
689 |
rqlst = rqlhelper.parse(u'Any A,B WHERE T require_permission C WITH A, B BEING(Any X, Y WHERE X illustrator_of Y)') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
690 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
691 |
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
|
692 |
'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
|
693 |
'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
|
694 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
695 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
696 |
def test_rewrite_with3(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
697 |
rules = {'participated_in': 'S contributor O'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
698 |
rqlst = rqlhelper.parse(u'Any A,B WHERE A participated_in B ' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
699 |
'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
|
700 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
701 |
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
|
702 |
'(Any X,Y WHERE X contributor Y)', |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
703 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
704 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
705 |
def test_rewrite_with4(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
706 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
707 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
708 |
rqlst = rqlhelper.parse(u'Any A,B WHERE A illustrator_of B ' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
709 |
'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
|
710 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
711 |
self.assertEqual('Any A,B WHERE C is Contribution, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
712 |
'C contributor A, C manifestation B, C role D, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
713 |
'D name "illustrator" WITH A,B BEING ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
714 |
'(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
|
715 |
'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
|
716 |
rqlst.as_string()) |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
717 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
718 |
# Tests for the union |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
719 |
def test_rewrite_union(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
720 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
721 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
722 |
rqlst = rqlhelper.parse(u'(Any A,B WHERE A illustrator_of B) UNION' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
723 |
'(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
|
724 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
725 |
self.assertEqual('(Any A,B WHERE C is Contribution, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
726 |
'C contributor A, C manifestation B, C role D, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
727 |
'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
|
728 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
729 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
730 |
def test_rewrite_union2(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
731 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
732 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
733 |
rqlst = rqlhelper.parse(u'(Any Y WHERE Y match W) UNION ' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
734 |
'(Any A WHERE A illustrator_of B) UNION ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
735 |
'(Any Y WHERE Y is ArtWork)') |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
736 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
737 |
self.assertEqual('(Any Y WHERE Y match W) ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
738 |
'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
|
739 |
'C manifestation B, C role D, D name "illustrator") ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
740 |
'UNION (Any Y WHERE Y is ArtWork)', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
741 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
742 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
743 |
# Tests for the exists clause |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
744 |
def test_rewrite_exists(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
745 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
746 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
747 |
rqlst = rqlhelper.parse(u'(Any A,B WHERE A illustrator_of B, ' |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
748 |
'EXISTS(B is ArtWork))') |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
749 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
750 |
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
|
751 |
'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
|
752 |
'D name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
753 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
754 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
755 |
def test_rewrite_exists2(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
756 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
757 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
758 |
rqlst = rqlhelper.parse(u'(Any A,B WHERE B contributor A, EXISTS(A illustrator_of W))') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
759 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
760 |
self.assertEqual('Any A,B WHERE B contributor A, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
761 |
'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
|
762 |
'C role D, D name "illustrator")', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
763 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
764 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
765 |
def test_rewrite_exists3(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
766 |
rules = {'illustrator_of': 'C is Contribution, C contributor S, ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
767 |
'C manifestation O, C role R, R name "illustrator"'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
768 |
rqlst = rqlhelper.parse(u'(Any A,B WHERE A illustrator_of B, EXISTS(A illustrator_of W))') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
769 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
770 |
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
|
771 |
'C manifestation W, C role D, D name "illustrator"), ' |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
772 |
'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
|
773 |
'F name "illustrator"', |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
774 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
775 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
776 |
# Test for GROUPBY |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
777 |
def test_rewrite_groupby(self): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
778 |
rules = {'participated_in': 'S contributor O'} |
10712
f7227cbf1d18
[test] call rql.parse with unicode objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10663
diff
changeset
|
779 |
rqlst = rqlhelper.parse(u'Any SUM(SA) GROUPBY S WHERE P participated_in S, P manifestation SA') |
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
780 |
rule_rewrite(rqlst, rules) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
781 |
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
|
782 |
rqlst.as_string()) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
783 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
784 |
|
9955
60a9cd1b3a4b
[CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9953
diff
changeset
|
785 |
class RQLRelationRewriterTC(CubicWebTC): |
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 |
appid = 'data/rewrite' |
60a9cd1b3a4b
[CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9953
diff
changeset
|
788 |
|
60a9cd1b3a4b
[CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9953
diff
changeset
|
789 |
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
|
790 |
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
|
791 |
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
|
792 |
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
|
793 |
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
|
794 |
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
|
795 |
manifestation=art, role=role) |
60a9cd1b3a4b
[CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9953
diff
changeset
|
796 |
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
|
797 |
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
|
798 |
[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
|
799 |
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
|
800 |
{'x': vic.eid}) |
60a9cd1b3a4b
[CWEP002] Plug the computed relation rewriter in the querier
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9953
diff
changeset
|
801 |
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
|
802 |
[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
|
803 |
|
9953
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
804 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
805 |
def rule_rewrite(rqlst, kwargs=None): |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
806 |
rewriter = _prepare_rewriter(rqlrewrite.RQLRelationRewriter, kwargs) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
807 |
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
|
808 |
kwargs=kwargs) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
809 |
rewriter.rewrite(rqlst) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
810 |
for select in rqlst.children: |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
811 |
test_vrefs(select) |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
812 |
return rewriter.rewritten |
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
813 |
|
643b19d79e4a
[CWEP002] introduce RQLRelationRewriter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9674
diff
changeset
|
814 |
|
0 | 815 |
if __name__ == '__main__': |
816 |
unittest_main() |