server/test/unittest_msplanner.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 25 Aug 2010 09:43:12 +0200
changeset 6139 f76599a96238
parent 6081 ede33e6400ab
parent 6131 087c5a168010
child 6225 a176e68b7d0d
permissions -rw-r--r--
backport stable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5420
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
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: 5420
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
    18
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
    19
from logilab.common.decorators import clear_cache
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
    20
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from cubicweb.devtools import init_test_database
2076
65cbe891edac cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2075
diff changeset
    22
from cubicweb.devtools.repotest import BasePlannerTC, test_plan
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
class _SetGenerator(object):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
    """singleton to easily create set using "s[0]" or "s[0,1,2]" for instance
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
    """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
    def __getitem__(self, key):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
        try:
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
            it = iter(key)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
        except TypeError:
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
            it = (key,)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
        return set(it)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
s = _SetGenerator()
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
from cubicweb.schema import ERQLExpression
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
from cubicweb.server.sources import AbstractSource
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
from cubicweb.server.msplanner import MSPlanner, PartPlanInformation
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
class FakeUserROSource(AbstractSource):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
    uri = 'zzz'
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
    41
    support_entities = {'CWUser': False}
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
    support_relations = {}
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
    def syntax_tree_search(self, *args, **kwargs):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
        return []
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    46
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
class FakeCardSource(AbstractSource):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
    uri = 'ccc'
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
    support_entities = {'Card': True, 'Note': True, 'State': True}
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
    50
    support_relations = {'in_state': True, 'multisource_rel': True, 'multisource_inlined_rel': True,
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
    51
                         'multisource_crossed_rel': True,}
3633
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
    52
    dont_cross_relations = set(('fiche', 'state_of'))
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
    53
    cross_relations = set(('multisource_crossed_rel',))
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    54
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
    def syntax_tree_search(self, *args, **kwargs):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
        return []
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    58
X_ALL_SOLS = sorted([{'X': 'Affaire'}, {'X': 'BaseTransition'}, {'X': 'Basket'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    59
                     {'X': 'Bookmark'}, {'X': 'CWAttribute'}, {'X': 'CWCache'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    60
                     {'X': 'CWConstraint'}, {'X': 'CWConstraintType'}, {'X': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    61
                     {'X': 'CWGroup'}, {'X': 'CWPermission'}, {'X': 'CWProperty'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    62
                     {'X': 'CWRType'}, {'X': 'CWRelation'}, {'X': 'CWUser'},
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
                     {'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    64
                     {'X': 'Email'}, {'X': 'EmailAddress'}, {'X': 'EmailPart'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    65
                     {'X': 'EmailThread'}, {'X': 'ExternalUri'}, {'X': 'File'},
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    66
                     {'X': 'Folder'}, {'X': 'Note'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    67
                     {'X': 'Personne'}, {'X': 'RQLExpression'}, {'X': 'Societe'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    68
                     {'X': 'State'}, {'X': 'SubDivision'}, {'X': 'SubWorkflowExitPoint'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    69
                     {'X': 'Tag'}, {'X': 'TrInfo'}, {'X': 'Transition'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    70
                     {'X': 'Workflow'}, {'X': 'WorkflowTransition'}])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    72
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
# keep cnx so it's not garbage collected and the associated session is closed
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
    74
repo, cnx = init_test_database()
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
4766
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4764
diff changeset
    76
def teardown_module(*args):
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4764
diff changeset
    77
    global repo, cnx
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4764
diff changeset
    78
    del repo, cnx
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4764
diff changeset
    79
162b2b127b15 [test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4764
diff changeset
    80
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
class BaseMSPlannerTC(BasePlannerTC):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
    """test planner related feature on a 3-sources repository:
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    83
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
    * system source supporting everything
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
    85
    * ldap source supporting CWUser
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    86
    * rql source supporting Card
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    87
    """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    88
    repo = repo
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    89
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    90
    def setUp(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
        #_QuerierTC.setUp(self)
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    92
        self.setup()
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
        # hijack Affaire security
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
    94
        affreadperms = list(self.schema['Affaire'].permissions['read'])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    95
        self.prevrqlexpr_affaire = affreadperms[-1]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
        # add access to type attribute so S can't be invariant
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    97
        affreadperms[-1] = ERQLExpression('X concerne S?, S owned_by U, S type "X"')
4685
8a2d3a7f62d1 use set_action_permissions is clearer and avoid @cached issue across tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4674
diff changeset
    98
        self.schema['Affaire'].set_action_permissions('read', affreadperms)
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
    99
        # hijack CWUser security
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   100
        userreadperms = list(self.schema['CWUser'].permissions['read'])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
        self.prevrqlexpr_user = userreadperms[-1]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
        userreadperms[-1] = ERQLExpression('X owned_by U')
4685
8a2d3a7f62d1 use set_action_permissions is clearer and avoid @cached issue across tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4674
diff changeset
   103
        self.schema['CWUser'].set_action_permissions('read', userreadperms)
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   104
        self.add_source(FakeUserROSource, 'ldap')
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   105
        self.add_source(FakeCardSource, 'cards')
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   106
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
    def tearDown(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
        # restore hijacked security
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
        self.restore_orig_affaire_security()
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   110
        self.restore_orig_cwuser_security()
4775
3a37f0ce7527 [test] call super class teardown after perms restoration
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4766
diff changeset
   111
        super(BaseMSPlannerTC, self).tearDown()
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   112
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   113
    def restore_orig_affaire_security(self):
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   114
        affreadperms = list(self.schema['Affaire'].permissions['read'])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
        affreadperms[-1] = self.prevrqlexpr_affaire
4685
8a2d3a7f62d1 use set_action_permissions is clearer and avoid @cached issue across tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4674
diff changeset
   116
        self.schema['Affaire'].set_action_permissions('read', affreadperms)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   117
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   118
    def restore_orig_cwuser_security(self):
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   119
        if hasattr(self, '_orig_cwuser_security_restored'):
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   120
            return
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   121
        self._orig_cwuser_security_restored = True
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
   122
        userreadperms = list(self.schema['CWUser'].permissions['read'])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   123
        userreadperms[-1] = self.prevrqlexpr_user
4685
8a2d3a7f62d1 use set_action_permissions is clearer and avoid @cached issue across tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4674
diff changeset
   124
        self.schema['CWUser'].set_action_permissions('read', userreadperms)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   126
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
class PartPlanInformationTC(BaseMSPlannerTC):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   128
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   129
    def _test(self, rql, *args):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   130
        if len(args) == 3:
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   131
            kwargs, sourcesterms, needsplit = args
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
        else:
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   133
            sourcesterms, needsplit = args
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
            kwargs = None
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
        plan = self._prepare_plan(rql, kwargs)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
        union = plan.rqlst
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
        plan.preprocess(union)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
        ppi = PartPlanInformation(plan, union.children[0])
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   139
        for sourcevars in ppi._sourcesterms.itervalues():
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   140
            for var in sourcevars.keys():
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
                solindices = sourcevars.pop(var)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
                sourcevars[var._ms_table_key()] = solindices
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   143
        self.assertEquals(ppi._sourcesterms, sourcesterms)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
        self.assertEquals(ppi.needsplit, needsplit)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   146
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
    def test_simple_system_only(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
        """retrieve entities only supported by the system source"""
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   149
        self._test('CWGroup X',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
                   {self.system: {'X': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   151
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
    def test_simple_system_ldap(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   153
        """retrieve CWUser X from both sources and return concatenation of results
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   154
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   155
        self._test('CWUser X',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   156
                   {self.system: {'X': s[0]}, self.ldap: {'X': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   157
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   158
    def test_simple_system_rql(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   159
        """retrieve Card X from both sources and return concatenation of results
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   160
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   161
        self._test('Any X, XT WHERE X is Card, X title XT',
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   162
                   {self.system: {'X': s[0]}, self.cards: {'X': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   163
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
    def test_simple_eid_specified(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   165
        """retrieve CWUser X from system source (eid is specified, can locate the entity)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   166
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   167
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   168
        self._test('Any X,L WHERE X eid %(x)s, X login L', {'x': ueid},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   169
                   {self.system: {'X': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   170
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   171
    def test_simple_eid_invariant(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   172
        """retrieve CWUser X from system source (eid is specified, can locate the entity)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   173
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   174
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   175
        self._test('Any X WHERE X eid %(x)s', {'x': ueid},
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   176
                   {self.system: {'x': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   177
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   178
    def test_simple_invariant(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   179
        """retrieve CWUser X from system source only (X is invariant and in_group not supported by ldap source)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   180
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   181
        self._test('Any X WHERE X is CWUser, X in_group G, G name "users"',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   182
                   {self.system: {'X': s[0], 'G': s[0], 'in_group': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   183
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   184
    def test_security_has_text(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   185
        """retrieve CWUser X from system source only (has_text not supported by ldap source)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   186
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   187
        # specify CWUser instead of any since the way this test is written we aren't well dealing
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   188
        # with ambigous query (eg only considering the first solution)
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   189
        self._test('CWUser X WHERE X has_text "bla"',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   190
                   {self.system: {'X': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   191
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   192
    def test_complex_base(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   193
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   194
        1. retrieve Any X, L WHERE X is CWUser, X login L from system and ldap sources, store
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   195
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   196
        2. return the result of Any X, L WHERE X is TMP, X login L, X in_group G,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   197
           G name 'users' on the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   198
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   199
        self._test('Any X,L WHERE X is CWUser, X in_group G, X login L, G name "users"',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   200
                   {self.system: {'X': s[0], 'G': s[0], 'in_group': s[0]},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   201
                    self.ldap : {'X': s[0]}}, True)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   202
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   203
    def test_complex_invariant_ordered(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
        1. retrieve Any X,AA WHERE X modification_date AA from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
        2. return the result of Any X,AA ORDERBY AA WHERE %s owned_by X, X modification_date AA
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   208
           on the system source
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
        self._test('Any X,AA ORDERBY AA WHERE E eid %(x)s, E owned_by X, X modification_date AA', {'x': ueid},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   212
                   {self.system: {'x': s[0], 'X': s[0], 'owned_by': s[0]},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   213
                    self.ldap : {'X': s[0]}}, True)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
    def test_complex_invariant(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   216
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   217
        1. retrieve Any X,L,AA WHERE X login L, X modification_date AA from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
        2. return the result of Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   220
           on the system source
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   221
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   222
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
        self._test('Any X,L,AA WHERE E eid %(x)s, E owned_by X, X login L, X modification_date AA', {'x': ueid},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
                   {self.system: {'x': s[0], 'X': s[0], 'owned_by': s[0]},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
                    self.ldap : {'X': s[0]}}, True)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   226
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   227
    def test_complex_ambigous(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   228
        """retrieve CWUser X from system and ldap sources, Person X from system source only
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   229
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   230
        self._test('Any X,F WHERE X firstname F',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   231
                   {self.system: {'X': s[0, 1]},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   232
                    self.ldap: {'X': s[0]}}, True)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   233
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   234
    def test_complex_multiple(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   235
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   236
        1. retrieve Any X,A,Y,B WHERE X login A, Y login B from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   237
           cartesian product of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   238
        2. return the result of Any X,Y WHERE X login 'syt', Y login 'adim'
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   239
           on the system source
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   240
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   241
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   242
        self._test('Any X,Y WHERE X login "syt", Y login "adim"', {'x': ueid},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   243
                   {self.system: {'Y': s[0], 'X': s[0]},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   244
                    self.ldap: {'Y': s[0], 'X': s[0]}}, True)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   245
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   246
    def test_complex_aggregat(self):
3689
deb13e88e037 follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3633
diff changeset
   247
        solindexes = set(range(len([e for e in self.schema.entities() if not e.final])))
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   248
        self._test('Any MAX(X)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   249
                   {self.system: {'X': solindexes}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   250
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   251
    def test_complex_optional(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   252
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   253
        self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS', {'x': ueid},
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   254
                   {self.system: {'WF': s[0], 'FS': s[0], 'U': s[0],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   255
                                  'from_state': s[0], 'owned_by': s[0], 'wf_info_for': s[0],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   256
                                  'x': s[0]}},
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   257
                   False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   258
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   259
    def test_exists4(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   260
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   261
        State S could come from both rql source and system source,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   262
        but since X cannot come from the rql source, the solution
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   263
        {self.cards : 'S'} must be removed
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   264
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   265
        self._test('Any G,L WHERE X in_group G, X login L, G name "managers", '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   266
                   'EXISTS(X copain T, T login L, T login in ("comme", "cochon")) OR '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   267
                   'EXISTS(X in_state S, S name "pascontent", NOT X copain T2, T2 login "billy")',
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   268
                   {self.system: {'X': s[0], 'S': s[0], 'T2': s[0], 'T': s[0], 'G': s[0], 'copain': s[0], 'in_group': s[0]},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   269
                    self.ldap: {'X': s[0], 'T2': s[0], 'T': s[0]}},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   270
                   True)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   271
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   272
    def test_relation_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   273
        self._test('Any X, S WHERE X in_state S',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   274
                   {self.system: {'X': s[0, 1, 2], 'S': s[0, 1, 2]},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   275
                    self.cards: {'X': s[2], 'S': s[2]}},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   276
                   True)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   277
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   278
    def test_not_relation_need_split(self):
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   279
        self._test('Any SN WHERE NOT X in_state S, S name SN',
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   280
                   {self.cards: {'X': s[2], 'S': s[0, 1, 2]},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   281
                    self.system: {'X': s[0, 1, 2], 'S': s[0, 1, 2]}},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   282
                   True)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   283
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   284
    def test_not_relation_no_split_external(self):
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   285
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   286
        # similar to the above test but with an eid coming from the external source.
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   287
        # the same plan may be used, since we won't find any record in the system source
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   288
        # linking 9999999 to a state
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   289
        self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   290
                   {'x': 999999},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   291
                   {self.cards: {'x': s[0], 'S': s[0]},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   292
                    self.system: {'x': s[0], 'S': s[0]}},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   293
                   False)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   294
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   295
    def test_relation_restriction_ambigous_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   296
        self._test('Any X,T WHERE X in_state S, S name "pending", T tags X',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   297
                   {self.system: {'X': s[0, 1, 2], 'S': s[0, 1, 2], 'T': s[0, 1, 2], 'tags': s[0, 1, 2]},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   298
                    self.cards: {'X': s[2], 'S': s[2]}},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   299
                   True)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   300
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   301
    def test_simplified_var(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   302
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   303
        self._test('Any U WHERE U in_group G, (G name IN ("managers", "logilab") OR (X require_permission P?, P name "bla", P require_group G)), X eid %(x)s, U eid %(u)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   304
                   {'x': 999999, 'u': self.session.user.eid},
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   305
                   {self.system: {'P': s[0], 'G': s[0], 'X': s[0],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   306
                                  'require_permission': s[0], 'in_group': s[0], 'P': s[0], 'require_group': s[0],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   307
                                  'u': s[0]}},
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   308
                   False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   309
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   310
    def test_delete_relation1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   311
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   312
        self._test('Any X, Y WHERE X created_by Y, X eid %(x)s, NOT Y eid %(y)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   313
                   {'x': ueid, 'y': ueid},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   314
                   {self.system: {'Y': s[0], 'created_by': s[0], 'x': s[0]}},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   315
                   False)
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   316
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   317
    def test_crossed_relation_eid_1_needattr(self):
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   318
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   319
        ueid = self.session.user.eid
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   320
        self._test('Any Y,T WHERE X eid %(x)s, X multisource_crossed_rel Y, Y type T',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   321
                   {'x': 999999,},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   322
                   {self.cards: {'Y': s[0]}, self.system: {'Y': s[0], 'x': s[0]}},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   323
                   True)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   324
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   325
    def test_crossed_relation_eid_1_invariant(self):
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   326
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   327
        self._test('Any Y WHERE X eid %(x)s, X multisource_crossed_rel Y',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   328
                   {'x': 999999},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   329
                   {self.system: {'Y': s[0], 'x': s[0]}},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   330
                   False)
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   331
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   332
    def test_crossed_relation_eid_2_invariant(self):
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   333
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   334
        self._test('Any Y WHERE X eid %(x)s, X multisource_crossed_rel Y',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   335
                   {'x': 999999,},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   336
                   {self.cards: {'Y': s[0], 'multisource_crossed_rel': s[0], 'x': s[0]},
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   337
                    self.system: {'Y': s[0], 'multisource_crossed_rel': s[0], 'x': s[0]}},
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   338
                   False)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   339
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   340
    def test_version_crossed_depends_on_1(self):
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   341
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   342
        self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   343
                   {'x': 999999},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   344
                   {self.cards: {'X': s[0], 'AD': s[0], 'multisource_crossed_rel': s[0], 'x': s[0]},
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   345
                    self.system: {'X': s[0], 'AD': s[0], 'multisource_crossed_rel': s[0], 'x': s[0]}},
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
   346
                   True)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   347
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   348
    def test_version_crossed_depends_on_2(self):
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   349
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   350
        self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   351
                   {'x': 999999},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   352
                   {self.cards: {'X': s[0], 'AD': s[0]},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   353
                    self.system: {'X': s[0], 'AD': s[0], 'x': s[0]}},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   354
                    True)
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   355
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   356
    def test_simplified_var_3(self):
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   357
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   358
        repo._type_source_cache[999998] = ('State', 'cards', 999998)
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   359
        self._test('Any S,T WHERE S eid %(s)s, N eid %(n)s, N type T, N is Note, S is State',
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
   360
                   {'n': 999999, 's': 999998},
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   361
                   {self.cards: {'s': s[0], 'N': s[0]}}, False)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   362
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   363
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   364
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   365
class MSPlannerTC(BaseMSPlannerTC):
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   366
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   367
    def setUp(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   368
        BaseMSPlannerTC.setUp(self)
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: 3239
diff changeset
   369
        self.planner = MSPlanner(self.o.schema, self.repo.vreg.rqlhelper)
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
   370
        for cached in ('rel_type_sources', 'can_cross_relation', 'is_multi_sources_relation'):
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
   371
            clear_cache(self.repo, cached)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   372
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   373
    _test = test_plan
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   374
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   375
    def test_simple_system_only(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   376
        """retrieve entities only supported by the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   377
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   378
        self._test('CWGroup X',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   379
                   [('OneFetchStep', [('Any X WHERE X is CWGroup', [{'X': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   380
                     None, None, [self.system], {}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   381
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   382
    def test_simple_system_only_limit(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   383
        """retrieve entities only supported by the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   384
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   385
        self._test('CWGroup X LIMIT 10',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   386
                   [('OneFetchStep', [('Any X LIMIT 10 WHERE X is CWGroup', [{'X': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   387
                     10, None, [self.system], {}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   388
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   389
    def test_simple_system_only_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   390
        """retrieve entities only supported by the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   391
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   392
        self._test('CWGroup X LIMIT 10 OFFSET 10',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   393
                   [('OneFetchStep', [('Any X LIMIT 10 OFFSET 10 WHERE X is CWGroup', [{'X': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   394
                     10, 10, [self.system], {}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   395
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   396
    def test_simple_system_ldap(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   397
        """retrieve CWUser X from both sources and return concatenation of results
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   398
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   399
        self._test('CWUser X',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   400
                   [('OneFetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   401
                     None, None, [self.ldap, self.system], {}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   402
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   403
    def test_simple_system_ldap_limit(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   404
        """retrieve CWUser X from both sources and return concatenation of results
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   405
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   406
        self._test('CWUser X LIMIT 10',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   407
                   [('OneFetchStep', [('Any X LIMIT 10 WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   408
                     10, None, [self.ldap, self.system], {}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   409
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   410
    def test_simple_system_ldap_limit_offset(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   411
        """retrieve CWUser X from both sources and return concatenation of results
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   412
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   413
        self._test('CWUser X LIMIT 10 OFFSET 10',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   414
                   [('OneFetchStep', [('Any X LIMIT 10 OFFSET 10 WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   415
                     10, 10, [self.ldap, self.system], {}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   416
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   417
    def test_simple_system_ldap_ordered_limit_offset(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   418
        """retrieve CWUser X from both sources and return concatenation of results
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   419
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   420
        self._test('CWUser X ORDERBY X LIMIT 10 OFFSET 10',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
   421
                   [('AggrStep', 'SELECT table0.C0 FROM table0 ORDER BY table0.C0 LIMIT 10 OFFSET 10', None, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   422
                       ('FetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   423
                        [self.ldap, self.system], {}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   424
                       ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   425
                   ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   426
    def test_simple_system_ldap_aggregat(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   427
        """retrieve CWUser X from both sources and return concatenation of results
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   428
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   429
        # COUNT(X) is kept in sub-step and transformed into SUM(X) in the AggrStep
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   430
        self._test('Any COUNT(X) WHERE X is CWUser',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
   431
                   [('AggrStep', 'SELECT SUM(table0.C0) FROM table0', None, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   432
                       ('FetchStep', [('Any COUNT(X) WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   433
                        [self.ldap, self.system], {}, {'COUNT(X)': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   434
                       ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   435
                   ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   436
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   437
    def test_simple_system_rql(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   438
        """retrieve Card X from both sources and return concatenation of results
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   439
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   440
        self._test('Any X, XT WHERE X is Card, X title XT',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   441
                   [('OneFetchStep', [('Any X,XT WHERE X is Card, X title XT', [{'X': 'Card', 'XT': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   442
                     None, None, [self.cards, self.system], {}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   443
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   444
    def test_simple_eid_specified(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   445
        """retrieve CWUser X from system source (eid is specified, can locate the entity)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   446
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   447
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   448
        self._test('Any X,L WHERE X eid %(x)s, X login L',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   449
                   [('OneFetchStep', [('Any X,L WHERE X eid %s, X login L'%ueid, [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   450
                     None, None, [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   451
                   {'x': ueid})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   452
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   453
    def test_simple_eid_invariant(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   454
        """retrieve CWUser X from system source (eid is specified, can locate the entity)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   455
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   456
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   457
        self._test('Any X WHERE X eid %(x)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   458
                   [('OneFetchStep', [('Any %s'%ueid, [{}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   459
                     None, None, [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   460
                   {'x': ueid})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   461
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   462
    def test_simple_invariant(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   463
        """retrieve CWUser X from system source only (X is invariant and in_group not supported by ldap source)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   464
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   465
        self._test('Any X WHERE X is CWUser, X in_group G, G name "users"',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   466
                   [('OneFetchStep', [('Any X WHERE X is CWUser, X in_group G, G name "users"',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   467
                                       [{'X': 'CWUser', 'G': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   468
                     None, None, [self.system], {}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   469
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   470
    def test_complex_base(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   471
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   472
        1. retrieve Any X, L WHERE X is CWUser, X login L from system and ldap sources, store
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   473
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   474
        2. return the result of Any X, L WHERE X is TMP, X login LX in_group G,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   475
           G name 'users' on the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   476
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   477
        self._test('Any X,L WHERE X is CWUser, X in_group G, X login L, G name "users"',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   478
                   [('FetchStep', [('Any X,L WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   479
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   480
                     {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   481
                    ('OneFetchStep', [('Any X,L WHERE X in_group G, X login L, G name "users", G is CWGroup, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   482
                                       [{'X': 'CWUser', 'L': 'String', 'G': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   483
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   484
                     {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   485
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   486
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   487
    def test_complex_base_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   488
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   489
        1. retrieve Any X, L WHERE X is CWUser, X login L from system and ldap sources, store
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   490
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   491
        2. return the result of Any X, L WHERE X is TMP, X login LX in_group G,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   492
           G name 'users' on the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   493
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   494
        self._test('Any X,L LIMIT 10 OFFSET 10 WHERE X is CWUser, X in_group G, X login L, G name "users"',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   495
                   [('FetchStep', [('Any X,L WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   496
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   497
                     {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   498
                    ('OneFetchStep', [('Any X,L LIMIT 10 OFFSET 10 WHERE X in_group G, X login L, G name "users", G is CWGroup, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   499
                                       [{'X': 'CWUser', 'L': 'String', 'G': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   500
                     10, 10,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   501
                     [self.system], {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   502
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   503
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   504
    def test_complex_ordered(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   505
        self._test('Any L ORDERBY L WHERE X login L',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
   506
                   [('AggrStep', 'SELECT table0.C0 FROM table0 ORDER BY table0.C0', None,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   507
                     [('FetchStep', [('Any L WHERE X login L, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   508
                                      [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   509
                       [self.ldap, self.system], {}, {'X.login': 'table0.C0', 'L': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   510
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   511
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   512
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   513
    def test_complex_ordered_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   514
        self._test('Any L ORDERBY L LIMIT 10 OFFSET 10 WHERE X login L',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
   515
                   [('AggrStep', 'SELECT table0.C0 FROM table0 ORDER BY table0.C0 LIMIT 10 OFFSET 10', None,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   516
                     [('FetchStep', [('Any L WHERE X login L, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   517
                                      [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   518
                       [self.ldap, self.system], {}, {'X.login': 'table0.C0', 'L': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   519
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   520
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   521
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   522
    def test_complex_invariant_ordered(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   523
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   524
        1. retrieve Any X,AA WHERE X modification_date AA from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   525
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   526
        2. return the result of Any X,AA ORDERBY AA WHERE %s owned_by X, X modification_date AA
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   527
           on the system source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   528
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   529
        herrr, this is what is expected by the XXX :(, not the actual result (which is correct anyway)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   530
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   531
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   532
        self._test('Any X,AA ORDERBY AA WHERE E eid %(x)s, E owned_by X, X modification_date AA',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   533
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   534
                     [('Any X,AA WHERE X modification_date AA, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   535
                       [{'AA': 'Datetime', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   536
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   537
                     {'AA': 'table0.C1', 'X': 'table0.C0', 'X.modification_date': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   538
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   539
                     [('Any X,AA ORDERBY AA WHERE 5 owned_by X, X modification_date AA, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   540
                       [{'AA': 'Datetime', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   541
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   542
                     {'AA': 'table0.C1', 'X': 'table0.C0', 'X.modification_date': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   543
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   544
                   {'x': ueid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   545
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   546
    def test_complex_invariant(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   547
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   548
        1. retrieve Any X,L,AA WHERE X login L, X modification_date AA from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   549
           concatenation of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   550
        2. return the result of Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   551
           on the system source
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   552
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   553
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   554
        self._test('Any X,L,AA WHERE E eid %(x)s, E owned_by X, X login L, X modification_date AA',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   555
                   [('FetchStep', [('Any X,L,AA WHERE X login L, X modification_date AA, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   556
                                    [{'AA': 'Datetime', 'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   557
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   558
                     {'AA': 'table0.C2', 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2', 'L': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   559
                    ('OneFetchStep', [('Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA, X is CWUser'%ueid,
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   560
                                       [{'AA': 'Datetime', 'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   561
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   562
                     {'AA': 'table0.C2', 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2', 'L': 'table0.C1'}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   563
                   {'x': ueid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   564
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   565
    def test_complex_ambigous(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   566
        """retrieve CWUser X from system and ldap sources, Person X from system source only
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   567
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   568
        self._test('Any X,F WHERE X firstname F',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   569
                   [('UnionStep', None, None, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   570
                       ('OneFetchStep', [('Any X,F WHERE X firstname F, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   571
                                          [{'X': 'CWUser', 'F': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   572
                        None, None, [self.ldap, self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   573
                       ('OneFetchStep', [('Any X,F WHERE X firstname F, X is Personne',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   574
                                          [{'X': 'Personne', 'F': 'String'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   575
                        None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   576
                       ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   577
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   578
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   579
    def test_complex_ambigous_limit_offset(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   580
        """retrieve CWUser X from system and ldap sources, Person X from system source only
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   581
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   582
        self._test('Any X,F LIMIT 10 OFFSET 10 WHERE X firstname F',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   583
                   [('UnionStep', 10, 10, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   584
                       ('OneFetchStep', [('Any X,F WHERE X firstname F, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   585
                                          [{'X': 'CWUser', 'F': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   586
                        None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   587
                        [self.ldap, self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   588
                       ('OneFetchStep', [('Any X,F WHERE X firstname F, X is Personne',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   589
                                          [{'X': 'Personne', 'F': 'String'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   590
                        None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   591
                       ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   592
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   593
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   594
    def test_complex_ambigous_ordered(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   595
        """
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   596
        1. retrieve CWUser X from system and ldap sources, Person X from system source only, store
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   597
           each result in the same temp table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   598
        2. return content of the table sorted
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   599
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   600
        self._test('Any X,F ORDERBY F WHERE X firstname F',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
   601
                   [('AggrStep', 'SELECT table0.C0, table0.C1 FROM table0 ORDER BY table0.C1', None,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   602
                     [('FetchStep', [('Any X,F WHERE X firstname F, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   603
                                      [{'X': 'CWUser', 'F': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   604
                       [self.ldap, self.system], {},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   605
                       {'X': 'table0.C0', 'X.firstname': 'table0.C1', 'F': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   606
                      ('FetchStep', [('Any X,F WHERE X firstname F, X is Personne',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   607
                                      [{'X': 'Personne', 'F': 'String'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   608
                       [self.system], {},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   609
                       {'X': 'table0.C0', 'X.firstname': 'table0.C1', 'F': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   610
                      ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   611
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   612
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   613
    def test_complex_multiple(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   614
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   615
        1. retrieve Any X,A,Y,B WHERE X login A, Y login B from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   616
           cartesian product of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   617
        2. return the result of Any X,Y WHERE X login 'syt', Y login 'adim'
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   618
           on the system source
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   619
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   620
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   621
        self._test('Any X,Y WHERE X login "syt", Y login "adim"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   622
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   623
                     [('Any X WHERE X login "syt", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   624
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   625
                     {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   626
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   627
                     [('Any Y WHERE Y login "adim", Y is CWUser', [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   628
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   629
                     {'Y': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   630
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   631
                     [('Any X,Y WHERE X is CWUser, Y is CWUser', [{'X': 'CWUser', 'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   632
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   633
                     {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   634
                    ], {'x': ueid})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   635
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   636
    def test_complex_multiple_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   637
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   638
        1. retrieve Any X,A,Y,B WHERE X login A, Y login B from system and ldap sources, store
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   639
           cartesian product of results into a temporary table
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   640
        2. return the result of Any X,Y WHERE X login 'syt', Y login 'adim'
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   641
           on the system source
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   642
        """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   643
        self._test('Any X,Y LIMIT 10 OFFSET 10 WHERE X login "syt", Y login "adim"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   644
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   645
                     [('Any X WHERE X login "syt", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   646
                     [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   647
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   648
                     [('Any Y WHERE Y login "adim", Y is CWUser', [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   649
                     [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   650
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   651
                     [('Any X,Y LIMIT 10 OFFSET 10 WHERE X is CWUser, Y is CWUser', [{'X': 'CWUser', 'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   652
                     10, 10, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   653
                     {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
5420
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
   654
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   655
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   656
    def test_complex_aggregat(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   657
        self._test('Any MAX(X)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   658
                   [('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   659
                     [('Any MAX(X)', X_ALL_SOLS)],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   660
                     None, None, [self.system], {}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   661
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   662
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   663
    def test_complex_typed_aggregat(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   664
        self._test('Any MAX(X) WHERE X is Card',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
   665
                   [('AggrStep', 'SELECT MAX(table0.C0) FROM table0',  None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   666
                     [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   667
                       [('Any MAX(X) WHERE X is Card', [{'X': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   668
                       [self.cards, self.system], {}, {'MAX(X)': 'table0.C0'}, [])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   669
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   670
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   671
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   672
    def test_complex_greater_eid(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   673
        self._test('Any X WHERE X eid > 12',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   674
                   [('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   675
                     [('Any X WHERE X eid > 12', X_ALL_SOLS)],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   676
                     None, None, [self.system], {}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   677
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   678
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   679
    def test_complex_greater_typed_eid(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   680
        self._test('Any X WHERE X eid > 12, X is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   681
                   [('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   682
                     [('Any X WHERE X eid > 12, X is Card', [{'X': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   683
                     None, None, [self.system], {}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   684
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   685
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   686
    def test_complex_optional(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   687
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   688
        self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   689
                   [('OneFetchStep', [('Any U WHERE WF wf_info_for 5, WF owned_by U?, WF from_state FS',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   690
                                       [{'WF': 'TrInfo', 'FS': 'State', 'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   691
                     None, None, [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   692
                   {'x': ueid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   693
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   694
    def test_complex_optional(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   695
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   696
        self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   697
                   [('OneFetchStep', [('Any U WHERE WF wf_info_for 5, WF owned_by U?, WF from_state FS',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   698
                                       [{'WF': 'TrInfo', 'FS': 'State', 'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   699
                     None, None, [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   700
                   {'x': ueid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   701
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   702
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   703
    def test_3sources_ambigous(self):
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
   704
        self._test('Any X,T WHERE X owned_by U, U login "syt", X title T, X is IN(Bookmark, Card, EmailThread)',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   705
                   [('FetchStep', [('Any X,T WHERE X title T, X is Card', [{'X': 'Card', 'T': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   706
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   707
                     {'T': 'table0.C1', 'X': 'table0.C0', 'X.title': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   708
                    ('FetchStep', [('Any U WHERE U login "syt", U is CWUser', [{'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   709
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   710
                     {'U': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   711
                    ('UnionStep', None, None, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   712
                        ('OneFetchStep', [('Any X,T WHERE X owned_by U, X title T, U is CWUser, X is IN(Bookmark, EmailThread)',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   713
                                           [{'T': 'String', 'U': 'CWUser', 'X': 'Bookmark'},
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   714
                                            {'T': 'String', 'U': 'CWUser', 'X': 'EmailThread'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   715
                         None, None, [self.system], {'U': 'table1.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   716
                        ('OneFetchStep', [('Any X,T WHERE X owned_by U, X title T, U is CWUser, X is Card',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   717
                                           [{'X': 'Card', 'U': 'CWUser', 'T': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   718
                         None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   719
                         {'X': 'table0.C0', 'X.title': 'table0.C1', 'T': 'table0.C1', 'U': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   720
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   721
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   722
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   723
    def test_restricted_max(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   724
        # dumb query to emulate the one generated by svnfile.entities.rql_revision_content
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   725
        self._test('Any V, MAX(VR) WHERE V is Card, V creation_date VR, '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   726
                   '(V creation_date TODAY OR (V creation_date < TODAY AND NOT EXISTS('
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   727
                   'X is Card, X creation_date < TODAY, X creation_date >= VR)))',
3815
50b87f759b5d test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
   728
                   [('FetchStep', [('Any VR WHERE X creation_date < TODAY, X creation_date VR, X is Card',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   729
                                    [{'X': 'Card', 'VR': 'Datetime'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   730
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   731
                     {'VR': 'table0.C0', 'X.creation_date': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   732
                    ('FetchStep', [('Any V,VR WHERE V creation_date VR, V is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   733
                                    [{'VR': 'Datetime', 'V': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   734
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   735
                     {'VR': 'table1.C1', 'V': 'table1.C0', 'V.creation_date': 'table1.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   736
                    ('OneFetchStep', [('Any V,MAX(VR) WHERE V creation_date VR, (V creation_date TODAY) OR (V creation_date < TODAY, NOT EXISTS(X creation_date >= VR, X is Card)), V is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   737
                                       [{'X': 'Card', 'VR': 'Datetime', 'V': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   738
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   739
                     {'VR': 'table1.C1', 'V': 'table1.C0', 'V.creation_date': 'table1.C1', 'X.creation_date': 'table0.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   740
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   741
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   742
    def test_outer_supported_rel1(self):
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   743
        # both system and rql support all variables, can be
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   744
        self._test('Any X, R WHERE X is Note, X in_state S, X type R, '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   745
                   'NOT EXISTS(Y is Note, Y in_state S, Y type R, X identity Y)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   746
                   [('OneFetchStep', [('Any X,R WHERE X is Note, X in_state S, X type R, NOT EXISTS(Y is Note, Y in_state S, Y type R, X identity Y), S is State',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   747
                                       [{'Y': 'Note', 'X': 'Note', 'S': 'State', 'R': 'String'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   748
                     None, None,
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   749
                     [self.cards, self.system], {}, [])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   750
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   751
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   752
    def test_not_identity(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   753
        self._test('Any X WHERE NOT X identity U, U eid %s' % self.session.user.eid,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   754
                   [('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   755
                     [('Any X WHERE NOT X identity 5, X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   756
                     None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   757
                     [self.ldap, self.system], {}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   758
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   759
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   760
    def test_outer_supported_rel2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   761
        self._test('Any X, MAX(R) GROUPBY X WHERE X in_state S, X login R, '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   762
                   'NOT EXISTS(Y is Note, Y in_state S, Y type R)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   763
                   [('FetchStep', [('Any A,R WHERE Y in_state A, Y type R, A is State, Y is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   764
                                    [{'Y': 'Note', 'A': 'State', 'R': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   765
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   766
                     {'A': 'table0.C0', 'R': 'table0.C1', 'Y.type': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   767
                    ('FetchStep', [('Any X,R WHERE X login R, X is CWUser', [{'X': 'CWUser', 'R': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   768
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   769
                     {'X': 'table1.C0', 'X.login': 'table1.C1', 'R': 'table1.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   770
                    ('OneFetchStep', [('Any X,MAX(R) GROUPBY X WHERE X in_state S, X login R, NOT EXISTS(Y type R, S identity A, A is State, Y is Note), S is State, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   771
                                       [{'Y': 'Note', 'X': 'CWUser', 'S': 'State', 'R': 'String', 'A': 'State'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   772
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   773
                     {'A': 'table0.C0', 'X': 'table1.C0', 'X.login': 'table1.C1', 'R': 'table1.C1', 'Y.type': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   774
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   775
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   776
    def test_security_has_text(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   777
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   778
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   779
        self._test('Any X WHERE X has_text "bla"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   780
                   [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   781
                     [self.cards, self.system], None, {'E': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   782
                    ('UnionStep', None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   783
                     [('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   784
                       [(u'Any X WHERE X has_text "bla", (EXISTS(X owned_by 5)) OR ((((EXISTS(D concerne C?, C owned_by 5, C type "X", X identity D, C is Division, D is Affaire)) OR (EXISTS(H concerne G?, G owned_by 5, G type "X", X identity H, G is SubDivision, H is Affaire))) OR (EXISTS(I concerne F?, F owned_by 5, F type "X", X identity I, F is Societe, I is Affaire))) OR (EXISTS(J concerne E?, E owned_by 5, X identity J, E is Note, J is Affaire))), X is Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   785
                         [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   786
                       None, None, [self.system], {'E': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   787
                      ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   788
                       [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is Basket',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   789
                         [{'X': 'Basket'}]),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   790
                        ('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   791
                         [{'X': 'CWUser'}]),
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   792
                        ('Any X WHERE X has_text "bla", X is IN(Card, Comment, Division, Email, EmailThread, File, Folder, Note, Personne, Societe, SubDivision, Tag)',
4815
4ee224c4c41d update test broken by fulltextindexed change on workflow entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
   793
                         [{'X': 'Card'}, {'X': 'Comment'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   794
                          {'X': 'Division'}, {'X': 'Email'}, {'X': 'EmailThread'},
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   795
                          {'X': 'File'}, {'X': 'Folder'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   796
                          {'X': 'Note'}, {'X': 'Personne'}, {'X': 'Societe'},
4815
4ee224c4c41d update test broken by fulltextindexed change on workflow entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
   797
                          {'X': 'SubDivision'}, {'X': 'Tag'}]),],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   798
                       None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   799
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   800
                     ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   801
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   802
    def test_security_has_text_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   803
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   804
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   805
        # note: same as the above query but because of the subquery usage, the display differs (not printing solutions for each union)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   806
        self._test('Any X LIMIT 10 OFFSET 10 WHERE X has_text "bla"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   807
                   [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   808
                      [self.cards, self.system], None, {'E': 'table1.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   809
                     ('UnionFetchStep', [
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   810
                         ('FetchStep', [('Any X WHERE X has_text "bla", (EXISTS(X owned_by 5)) OR ((((EXISTS(D concerne C?, C owned_by 5, C type "X", X identity D, C is Division, D is Affaire)) OR (EXISTS(H concerne G?, G owned_by 5, G type "X", X identity H, G is SubDivision, H is Affaire))) OR (EXISTS(I concerne F?, F owned_by 5, F type "X", X identity I, F is Societe, I is Affaire))) OR (EXISTS(J concerne E?, E owned_by 5, X identity J, E is Note, J is Affaire))), X is Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   811
                                            [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   812
                          [self.system], {'E': 'table1.C0'}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   813
                         ('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   814
                          [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is Basket',
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   815
                            [{'X': 'Basket'}]),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   816
                           ('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   817
                            [{'X': 'CWUser'}]),
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   818
                           ('Any X WHERE X has_text "bla", X is IN(Card, Comment, Division, Email, EmailThread, File, Folder, Note, Personne, Societe, SubDivision, Tag)',
4815
4ee224c4c41d update test broken by fulltextindexed change on workflow entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
   819
                            [{'X': 'Card'}, {'X': 'Comment'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   820
                             {'X': 'Division'}, {'X': 'Email'}, {'X': 'EmailThread'},
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   821
                             {'X': 'File'}, {'X': 'Folder'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   822
                             {'X': 'Note'}, {'X': 'Personne'}, {'X': 'Societe'},
4815
4ee224c4c41d update test broken by fulltextindexed change on workflow entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
   823
                             {'X': 'SubDivision'}, {'X': 'Tag'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   824
                          [self.system], {}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   825
                         ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   826
                    ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   827
                     [('Any X LIMIT 10 OFFSET 10',
4815
4ee224c4c41d update test broken by fulltextindexed change on workflow entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
   828
                       [{'X': 'Affaire'}, {'X': 'Basket'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   829
                        {'X': 'CWUser'}, {'X': 'Card'}, {'X': 'Comment'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   830
                        {'X': 'Division'}, {'X': 'Email'}, {'X': 'EmailThread'},
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   831
                        {'X': 'File'}, {'X': 'Folder'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   832
                        {'X': 'Note'}, {'X': 'Personne'}, {'X': 'Societe'},
4815
4ee224c4c41d update test broken by fulltextindexed change on workflow entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
   833
                        {'X': 'SubDivision'}, {'X': 'Tag'}])],
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   834
                     10, 10, [self.system], {'X': 'table0.C0'}, [])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   835
                     ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   836
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   837
    def test_security_user(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   838
        """a guest user trying to see another user: EXISTS(X owned_by U) is automatically inserted"""
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   839
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   840
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   841
        self._test('Any X WHERE X login "bla"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   842
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   843
                     [('Any X WHERE X login "bla", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   844
                     [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   845
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   846
                     [('Any X WHERE EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   847
                     None, None, [self.system], {'X': 'table0.C0'}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   848
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   849
    def test_security_complex_has_text(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   850
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   851
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   852
        self._test('Any X WHERE X has_text "bla", X firstname "bla"',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   853
                   [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   854
                     [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   855
                    ('UnionStep', None, None, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   856
                        ('OneFetchStep', [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   857
                         None, None, [self.system], {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   858
                        ('OneFetchStep', [('Any X WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   859
                         None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   860
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   861
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   862
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   863
    def test_security_complex_has_text_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   864
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   865
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   866
        self._test('Any X LIMIT 10 OFFSET 10 WHERE X has_text "bla", X firstname "bla"',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   867
                   [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   868
                     [self.ldap, self.system], None, {'X': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   869
                    ('UnionFetchStep', [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   870
                        ('FetchStep', [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   871
                         [self.system], {'X': 'table1.C0'}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   872
                        ('FetchStep', [('Any X WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   873
                         [self.system], {}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   874
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   875
                     ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   876
                      [('Any X LIMIT 10 OFFSET 10', [{'X': 'CWUser'}, {'X': 'Personne'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   877
                      10, 10, [self.system], {'X': 'table0.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   878
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   879
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   880
    def test_security_complex_aggregat(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   881
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   882
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   883
        self._test('Any MAX(X)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   884
                   [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   885
                     [self.cards, self.system],  None, {'E': 'table1.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   886
                    ('FetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   887
                     [self.ldap, self.system], None, {'X': 'table2.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   888
                    ('UnionFetchStep', [
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   889
                        ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is Basket', [{'X': 'Basket'}])],
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   890
                          [self.system], {}, {'X': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   891
                        ('UnionFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   892
                         [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   893
                                          [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   894
                           [self.cards, self.system], {}, {'X': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   895
                          ('FetchStep',
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   896
                           [('Any X WHERE X is IN(BaseTransition, Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Personne, RQLExpression, Societe, SubDivision, SubWorkflowExitPoint, Tag, TrInfo, Transition, Workflow, WorkflowTransition)',
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   897
                             [{'X': 'BaseTransition'}, {'X': 'Bookmark'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   898
                              {'X': 'CWAttribute'}, {'X': 'CWCache'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   899
                              {'X': 'CWConstraint'}, {'X': 'CWConstraintType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   900
                              {'X': 'CWEType'}, {'X': 'CWGroup'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   901
                              {'X': 'CWPermission'}, {'X': 'CWProperty'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   902
                              {'X': 'CWRType'}, {'X': 'CWRelation'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   903
                              {'X': 'Comment'}, {'X': 'Division'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   904
                              {'X': 'Email'}, {'X': 'EmailAddress'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   905
                              {'X': 'EmailPart'}, {'X': 'EmailThread'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   906
                              {'X': 'ExternalUri'}, {'X': 'File'},
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   907
                              {'X': 'Folder'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   908
                              {'X': 'Personne'}, {'X': 'RQLExpression'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   909
                              {'X': 'Societe'}, {'X': 'SubDivision'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   910
                              {'X': 'SubWorkflowExitPoint'}, {'X': 'Tag'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   911
                              {'X': 'TrInfo'}, {'X': 'Transition'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   912
                              {'X': 'Workflow'}, {'X': 'WorkflowTransition'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   913
                           [self.system], {}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   914
                          ]),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   915
                        ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   916
                         [self.system], {'X': 'table2.C0'}, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   917
                        ('FetchStep', [('Any X WHERE (EXISTS(X owned_by 5)) OR ((((EXISTS(D concerne C?, C owned_by 5, C type "X", X identity D, C is Division, D is Affaire)) OR (EXISTS(H concerne G?, G owned_by 5, G type "X", X identity H, G is SubDivision, H is Affaire))) OR (EXISTS(I concerne F?, F owned_by 5, F type "X", X identity I, F is Societe, I is Affaire))) OR (EXISTS(J concerne E?, E owned_by 5, X identity J, E is Note, J is Affaire))), X is Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   918
                                        [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   919
                         [self.system], {'E': 'table1.C0'}, {'X': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   920
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   921
                    ('OneFetchStep', [('Any MAX(X)', X_ALL_SOLS)],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   922
                     None, None, [self.system], {'X': 'table0.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   923
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   924
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   925
    def test_security_complex_aggregat2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   926
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   927
        self.session = self.user_groups_session('guests')
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   928
        X_ET_ALL_SOLS = []
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   929
        for s in X_ALL_SOLS:
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   930
            ets = {'ET': 'CWEType'}
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   931
            ets.update(s)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   932
            X_ET_ALL_SOLS.append(ets)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   933
        self._test('Any ET, COUNT(X) GROUPBY ET ORDERBY ET WHERE X is ET',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   934
                   [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   935
                                    [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   936
                     [self.cards, self.system], None, {'X': 'table1.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   937
                    ('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   938
                     [self.cards, self.system],  None, {'E': 'table2.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   939
                    ('FetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   940
                     [self.ldap, self.system], None, {'X': 'table3.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   941
                    ('UnionFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   942
                     [('FetchStep', [('Any ET,X WHERE X is ET, EXISTS(X owned_by 5), ET is CWEType, X is Basket',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   943
                                      [{'ET': 'CWEType', 'X': 'Basket'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   944
                       [self.system], {}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   945
                      ('FetchStep', [('Any ET,X WHERE X is ET, (EXISTS(X owned_by 5)) OR ((((EXISTS(D concerne C?, C owned_by 5, C type "X", X identity D, C is Division, D is Affaire)) OR (EXISTS(H concerne G?, G owned_by 5, G type "X", X identity H, G is SubDivision, H is Affaire))) OR (EXISTS(I concerne F?, F owned_by 5, F type "X", X identity I, F is Societe, I is Affaire))) OR (EXISTS(J concerne E?, E owned_by 5, X identity J, E is Note, J is Affaire))), ET is CWEType, X is Affaire',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   946
                                      [{'C': 'Division', 'E': 'Note', 'D': 'Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   947
                                        'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   948
                                        'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   949
                                        'ET': 'CWEType'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   950
                       [self.system], {'E': 'table2.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   951
                       []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   952
                      ('FetchStep', [('Any ET,X WHERE X is ET, EXISTS(X owned_by 5), ET is CWEType, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   953
                                      [{'ET': 'CWEType', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   954
                       [self.system], {'X': 'table3.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   955
                      # extra UnionFetchStep could be avoided but has no cost, so don't care
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   956
                      ('UnionFetchStep',
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   957
                       [('FetchStep', [('Any ET,X WHERE X is ET, ET is CWEType, X is IN(BaseTransition, Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, Comment, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Personne, RQLExpression, Societe, SubDivision, SubWorkflowExitPoint, Tag, TrInfo, Transition, Workflow, WorkflowTransition)',
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   958
                                        [{'X': 'BaseTransition', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   959
                                         {'X': 'Bookmark', 'ET': 'CWEType'}, {'X': 'CWAttribute', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   960
                                         {'X': 'CWCache', 'ET': 'CWEType'}, {'X': 'CWConstraint', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   961
                                         {'X': 'CWConstraintType', 'ET': 'CWEType'}, {'X': 'CWEType', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   962
                                         {'X': 'CWGroup', 'ET': 'CWEType'}, {'X': 'CWPermission', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   963
                                         {'X': 'CWProperty', 'ET': 'CWEType'}, {'X': 'CWRType', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   964
                                         {'X': 'CWRelation', 'ET': 'CWEType'}, {'X': 'Comment', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   965
                                         {'X': 'Division', 'ET': 'CWEType'}, {'X': 'Email', 'ET': 'CWEType'},
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   966
                                         {'X': 'EmailAddress', 'ET': 'CWEType'}, {'X': 'EmailPart', 'ET': 'CWEType'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   967
                                         {'X': 'EmailThread', 'ET': 'CWEType'}, {'X': 'ExternalUri', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   968
                                         {'X': 'File', 'ET': 'CWEType'}, {'X': 'Folder', 'ET': 'CWEType'},
5575
8a531340c3ef no more Image type w/ cw 3.9
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
   969
                                         {'X': 'Personne', 'ET': 'CWEType'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   970
                                         {'X': 'RQLExpression', 'ET': 'CWEType'}, {'X': 'Societe', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   971
                                         {'X': 'SubDivision', 'ET': 'CWEType'}, {'X': 'SubWorkflowExitPoint', 'ET': 'CWEType'},
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   972
                                         {'X': 'Tag', 'ET': 'CWEType'}, {'X': 'TrInfo', 'ET': 'CWEType'},
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   973
                                         {'X': 'Transition', 'ET': 'CWEType'}, {'X': 'Workflow', 'ET': 'CWEType'},
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   974
                                         {'X': 'WorkflowTransition', 'ET': 'CWEType'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   975
                         [self.system], {}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   976
                        ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   977
                         [('Any ET,X WHERE X is ET, ET is CWEType, X is IN(Card, Note, State)',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   978
                           [{'ET': 'CWEType', 'X': 'Card'},
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   979
                            {'ET': 'CWEType', 'X': 'Note'},
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   980
                            {'ET': 'CWEType', 'X': 'State'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   981
                         [self.system], {'X': 'table1.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   982
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   983
                    ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   984
                    ('OneFetchStep',
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2715
diff changeset
   985
                     [('Any ET,COUNT(X) GROUPBY ET ORDERBY ET', X_ET_ALL_SOLS)],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   986
                     None, None, [self.system], {'ET': 'table0.C0', 'X': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   987
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   988
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   989
    def test_security_3sources(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   990
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   991
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   992
        self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   993
                   [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   994
                     [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   995
                     [self.cards, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   996
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
   997
                     [('Any U WHERE U login "syt", U is CWUser', [{'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   998
                     [self.ldap, self.system], None, {'U': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   999
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1000
                     [('Any X,XT WHERE X owned_by U, X title XT, EXISTS(U owned_by 5), U is CWUser, X is Card',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1001
                       [{'X': 'Card', 'U': 'CWUser', 'XT': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1002
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1003
                     {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1', 'U': 'table1.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1004
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1005
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1006
    def test_security_3sources_identity(self):
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
  1007
        self.restore_orig_cwuser_security()
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1008
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1009
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1010
        self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1011
                   [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1012
                     [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1013
                     [self.cards, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1014
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1015
                     [('Any X,XT WHERE X owned_by U, X title XT, U login "syt", EXISTS(U identity 5), U is CWUser, X is Card',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1016
                       [{'U': 'CWUser', 'X': 'Card', 'XT': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1017
                     None, None, [self.system], {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1018
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1019
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1020
    def test_security_3sources_identity_optional_var(self):
4191
01638461d4b0 test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
  1021
        self.restore_orig_cwuser_security()
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1022
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1023
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1024
        self._test('Any X,XT,U WHERE X is Card, X owned_by U?, X title XT, U login L',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1025
                   [('FetchStep',
4915
d657b89df9f4 fix test broken by recent rql rewrite / querier changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4823
diff changeset
  1026
                     [('Any U,L WHERE U login L, EXISTS(U identity 5), U is CWUser',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1027
                       [{'L': 'String', u'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1028
                     [self.system], {}, {'L': 'table0.C1', 'U': 'table0.C0', 'U.login': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1029
                    ('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1030
                     [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1031
                     [self.cards, self.system], None, {'X': 'table1.C0', 'X.title': 'table1.C1', 'XT': 'table1.C1'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1032
                    ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1033
                     [('Any X,XT,U WHERE X owned_by U?, X title XT, X is Card',
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1034
                       [{'X': 'Card', 'U': 'CWUser', 'XT': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1035
                     None, None, [self.system], {'L': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1036
                                                 'U': 'table0.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1037
                                                 'X': 'table1.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1038
                                                 'X.title': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1039
                                                 'XT': 'table1.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1040
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1041
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1042
    def test_security_3sources_limit_offset(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1043
        # use a guest user
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1044
        self.session = self.user_groups_session('guests')
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1045
        self._test('Any X, XT LIMIT 10 OFFSET 10 WHERE X is Card, X owned_by U, X title XT, U login "syt"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1046
                   [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1047
                     [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1048
                     [self.cards, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1049
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1050
                     [('Any U WHERE U login "syt", U is CWUser', [{'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1051
                     [self.ldap, self.system], None, {'U': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1052
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1053
                     [('Any X,XT LIMIT 10 OFFSET 10 WHERE X owned_by U, X title XT, EXISTS(U owned_by 5), U is CWUser, X is Card',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1054
                       [{'X': 'Card', 'U': 'CWUser', 'XT': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1055
                     10, 10, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1056
                     {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1', 'U': 'table1.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1057
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1058
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1059
    def test_exists_base(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1060
        self._test('Any X,L,S WHERE X in_state S, X login L, EXISTS(X in_group G, G name "bougloup")',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1061
                   [('FetchStep', [('Any X,L WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1062
                     [self.ldap, self.system], None, {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1063
                    ('OneFetchStep', [("Any X,L,S WHERE X in_state S, X login L, "
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1064
                                      'EXISTS(X in_group G, G name "bougloup", G is CWGroup), S is State, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1065
                                       [{'X': 'CWUser', 'L': 'String', 'S': 'State', 'G': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1066
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1067
                     {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1068
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1069
    def test_exists_complex(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1070
        self._test('Any G WHERE X in_group G, G name "managers", EXISTS(X copain T, T login in ("comme", "cochon"))',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1071
                   [('FetchStep', [('Any T WHERE T login IN("comme", "cochon"), T is CWUser', [{'T': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1072
                     [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1073
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1074
                     [('Any G WHERE X in_group G, G name "managers", EXISTS(X copain T, T is CWUser), G is CWGroup, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1075
                       [{'X': 'CWUser', 'T': 'CWUser', 'G': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1076
                     None, None, [self.system], {'T': 'table0.C0'}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1077
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1078
    def test_exists3(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1079
        self._test('Any G,L WHERE X in_group G, X login L, G name "managers", EXISTS(X copain T, T login in ("comme", "cochon"))',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1080
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1081
                     [('Any T WHERE T login IN("comme", "cochon"), T is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1082
                       [{'T': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1083
                     [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1084
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1085
                     [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1086
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1087
                     {'X': 'table1.C1', 'X.login': 'table1.C0', 'L': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1088
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1089
                     [('Any G,L WHERE X in_group G, X login L, G name "managers", EXISTS(X copain T, T is CWUser), G is CWGroup, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1090
                       [{'G': 'CWGroup', 'L': 'String', 'T': 'CWUser', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1091
                     None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1092
                     [self.system], {'T': 'table0.C0', 'X': 'table1.C1', 'X.login': 'table1.C0', 'L': 'table1.C0'}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1093
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1094
    def test_exists4(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1095
        self._test('Any G,L WHERE X in_group G, X login L, G name "managers", '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1096
                   'EXISTS(X copain T, T login L, T login in ("comme", "cochon")) OR '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1097
                   'EXISTS(X in_state S, S name "pascontent", NOT X copain T2, T2 login "billy")',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1098
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1099
                     [('Any T,L WHERE T login L, T login IN("comme", "cochon"), T is CWUser', [{'T': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1100
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1101
                     {'T': 'table0.C0', 'T.login': 'table0.C1', 'L': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1102
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1103
                     [('Any T2 WHERE T2 login "billy", T2 is CWUser', [{'T2': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1104
                     [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1105
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1106
                     [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1107
                     [self.ldap, self.system], None, {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1108
                    ('OneFetchStep',
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
  1109
                     [('Any G,L WHERE X in_group G, X login L, G name "managers", (EXISTS(X copain T, T login L, T is CWUser)) OR (EXISTS(X in_state S, S name "pascontent", NOT EXISTS(X copain T2), S is State)), G is CWGroup, T2 is CWUser, X is CWUser',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1110
                       [{'G': 'CWGroup', 'L': 'String', 'S': 'State', 'T': 'CWUser', 'T2': 'CWUser', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1111
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1112
                     {'T2': 'table1.C0', 'L': 'table2.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1113
                      'T': 'table0.C0', 'T.login': 'table0.C1', 'X': 'table2.C1', 'X.login': 'table2.C0'}, [])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1114
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1115
    def test_exists5(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1116
        self._test('Any GN,L WHERE X in_group G, X login L, G name GN, '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1117
                   'EXISTS(X copain T, T login in ("comme", "cochon")) AND '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1118
                   'NOT EXISTS(X copain T2, T2 login "billy")',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1119
                   [('FetchStep', [('Any T WHERE T login IN("comme", "cochon"), T is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1120
                                    [{'T': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1121
                     [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1122
                    ('FetchStep', [('Any T2 WHERE T2 login "billy", T2 is CWUser', [{'T2': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1123
                     [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1124
                    ('FetchStep', [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1125
                     [self.ldap, self.system], None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1126
                     {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1127
                    ('OneFetchStep', [('Any GN,L WHERE X in_group G, X login L, G name GN, EXISTS(X copain T, T is CWUser), NOT EXISTS(X copain T2, T2 is CWUser), G is CWGroup, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1128
                       [{'G': 'CWGroup', 'GN': 'String', 'L': 'String', 'T': 'CWUser', 'T2': 'CWUser', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1129
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1130
                     {'T': 'table0.C0', 'T2': 'table1.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1131
                      'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1132
392
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1133
    def test_exists_security_no_invariant(self):
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1134
        ueid = self.session.user.eid
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1135
        self._test('Any X,AA,AB,AC,AD ORDERBY AA WHERE X is CWUser, X login AA, X firstname AB, X surname AC, X modification_date AD, A eid %(B)s, \
392
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1136
    EXISTS(((X identity A) OR \
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1137
            (EXISTS(X in_group C, C name IN("managers", "staff"), C is CWGroup))) OR \
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1138
            (EXISTS(X in_group D, A in_group D, NOT D name "users", D is CWGroup)))',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1139
               [('FetchStep', [('Any X,AA,AB,AC,AD WHERE X login AA, X firstname AB, X surname AC, X modification_date AD, X is CWUser',
392
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1140
                                [{'AA': 'String', 'AB': 'String', 'AC': 'String', 'AD': 'Datetime',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1141
                                  'X': 'CWUser'}])],
392
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1142
                 [self.ldap, self.system], None, {'AA': 'table0.C1', 'AB': 'table0.C2',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1143
                                                  'AC': 'table0.C3', 'AD': 'table0.C4',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1144
                                                  'X': 'table0.C0',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1145
                                                  'X.firstname': 'table0.C2',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1146
                                                  'X.login': 'table0.C1',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1147
                                                  'X.modification_date': 'table0.C4',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1148
                                                  'X.surname': 'table0.C3'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1149
                ('OneFetchStep', [('Any X,AA,AB,AC,AD ORDERBY AA WHERE X login AA, X firstname AB, X surname AC, X modification_date AD, EXISTS(((X identity 5) OR (EXISTS(X in_group C, C name IN("managers", "staff"), C is CWGroup))) OR (EXISTS(X in_group D, 5 in_group D, NOT D name "users", D is CWGroup))), X is CWUser',
392
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1150
                                   [{'AA': 'String', 'AB': 'String', 'AC': 'String', 'AD': 'Datetime',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1151
                                     'C': 'CWGroup', 'D': 'CWGroup', 'X': 'CWUser'}])],
392
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1152
                 None, None, [self.system],
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1153
                 {'AA': 'table0.C1', 'AB': 'table0.C2', 'AC': 'table0.C3', 'AD': 'table0.C4',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1154
                  'X': 'table0.C0',
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1155
                  'X.firstname': 'table0.C2', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C4', 'X.surname': 'table0.C3'},
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1156
                 [])],
bccd9a788f7a OR EXISTS fix, typos
sylvain.thenault@logilab.fr
parents: 341
diff changeset
  1157
                   {'B': ueid})
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1158
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1159
    def test_relation_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1160
        self._test('Any X, S WHERE X in_state S',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1161
                   [('UnionStep', None, None, [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1162
                       ('OneFetchStep', [('Any X,S WHERE X in_state S, S is State, X is IN(Affaire, CWUser)',
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1163
                                          [{'X': 'Affaire', 'S': 'State'}, {'X': 'CWUser', 'S': 'State'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1164
                        None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1165
                       ('OneFetchStep', [('Any X,S WHERE X in_state S, S is State, X is Note',
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1166
                                          [{'X': 'Note', 'S': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1167
                        None, None, [self.cards, self.system], {}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1168
                    ])])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1169
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1170
    def test_relation_selection_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1171
        self._test('Any X,S,U WHERE X in_state S, X todo_by U',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1172
                   [('FetchStep', [('Any X,S WHERE X in_state S, S is State, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1173
                                    [{'X': 'Note', 'S': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1174
                     [self.cards, self.system], None, {'X': 'table0.C0', 'S': 'table0.C1'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1175
                     ('UnionStep', None, None,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1176
                      [('OneFetchStep', [('Any X,S,U WHERE X in_state S, X todo_by U, S is State, U is CWUser, X is Note',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1177
                                          [{'X': 'Note', 'S': 'State', 'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1178
                        None, None, [self.system], {'X': 'table0.C0', 'S': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1179
                       ('OneFetchStep', [('Any X,S,U WHERE X in_state S, X todo_by U, S is State, U is Personne, X is Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1180
                                          [{'X': 'Affaire', 'S': 'State', 'U': 'Personne'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1181
                        None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1182
                       ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1183
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1184
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1185
    def test_relation_restriction_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1186
        self._test('Any X,U WHERE X in_state S, S name "pending", X todo_by U',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1187
                   [('FetchStep', [('Any X WHERE X in_state S, S name "pending", S is State, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1188
                                    [{'X': 'Note', 'S': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1189
                     [self.cards, self.system], None, {'X': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1190
                     ('UnionStep', None, None,
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1191
                      [('OneFetchStep', [('Any X,U WHERE X todo_by U, U is CWUser, X is Note',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1192
                                          [{'X': 'Note', 'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1193
                        None, None, [self.system], {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1194
                       ('OneFetchStep', [('Any X,U WHERE X in_state S, S name "pending", X todo_by U, S is State, U is Personne, X is Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1195
                                          [{'S': 'State', 'U': 'Personne', 'X': 'Affaire'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1196
                        None, None, [self.system], {}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1197
                       ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1198
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1199
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1200
    def test_relation_restriction_ambigous_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1201
        self._test('Any X,T WHERE X in_state S, S name "pending", T tags X',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1202
                   [('FetchStep', [('Any X WHERE X in_state S, S name "pending", S is State, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1203
                                    [{'X': 'Note', 'S': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1204
                     [self.cards, self.system], None, {'X': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1205
                    ('UnionStep', None, None, [
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1206
                        ('OneFetchStep', [('Any X,T WHERE T tags X, T is Tag, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1207
                                           [{'X': 'Note', 'T': 'Tag'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1208
                         None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1209
                         [self.system], {'X': 'table0.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1210
                        ('OneFetchStep', [('Any X,T WHERE X in_state S, S name "pending", T tags X, S is State, T is Tag, X is IN(Affaire, CWUser)',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1211
                                           [{'X': 'Affaire', 'S': 'State', 'T': 'Tag'},
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1212
                                            {'X': 'CWUser', 'S': 'State', 'T': 'Tag'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1213
                         None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1214
                         [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1215
                        ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1216
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1217
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1218
    def test_not_relation_no_split_internal(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1219
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1220
        # NOT on a relation supported by rql and system source: we want to get
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1221
        # all states (eg from both sources) which are not related to entity with the
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1222
        # given eid. The "NOT X in_state S, X eid %(x)s" expression is necessarily true
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1223
        # in the source where %(x)s is not coming from and will be removed during rql
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1224
        # generation for the external source
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1225
        self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
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
  1226
                   [('OneFetchStep', [('Any SN WHERE NOT EXISTS(5 in_state S), S name SN, S is State',
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1227
                                       [{'S': 'State', 'SN': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1228
                     None, None, [self.cards, self.system], {}, [])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1229
                   {'x': ueid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1230
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1231
    def test_not_relation_no_split_external(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1232
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1233
        # similar to the above test but with an eid coming from the external source.
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1234
        # the same plan may be used, since we won't find any record in the system source
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1235
        # linking 9999999 to a state
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1236
        self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
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
  1237
                   [('OneFetchStep', [('Any SN WHERE NOT EXISTS(999999 in_state S), S name SN, S is State',
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1238
                                       [{'S': 'State', 'SN': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1239
                     None, None, [self.cards, self.system], {}, [])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1240
                   {'x': 999999})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1241
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1242
    def test_not_relation_need_split(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1243
        self._test('Any SN WHERE NOT X in_state S, S name SN',
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1244
                   [('FetchStep', [('Any SN,S WHERE S name SN, S is State',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1245
                                    [{'S': 'State', 'SN': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1246
                     [self.cards, self.system], None, {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1247
                     []),
341
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1248
                    ('IntersectStep', None, None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1249
                     [('OneFetchStep',
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
  1250
                       [('Any SN WHERE NOT EXISTS(X in_state S, X is Note), S name SN, S is State',
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  1251
                         [{'S': 'State', 'SN': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1252
                       None, None, [self.cards, self.system], {},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  1253
                       []),
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  1254
                      ('OneFetchStep',
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
  1255
                       [('Any SN WHERE NOT EXISTS(X in_state S, X is IN(Affaire, CWUser)), S name SN, S is State',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1256
                         [{'S': 'State', 'SN': 'String', 'X': 'Affaire'},
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1257
                          {'S': 'State', 'SN': 'String', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1258
                       None, None, [self.system], {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  1259
                       []),]
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1260
                     )])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1261
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1262
    def test_external_attributes_and_relation(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1263
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1264
        self._test('Any A,B,C,D WHERE A eid %(x)s,A creation_date B,A modification_date C, A todo_by D?',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1265
                   [('FetchStep', [('Any A,B,C WHERE A eid 999999, A creation_date B, A modification_date C, A is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1266
                                    [{'A': 'Note', 'C': 'Datetime', 'B': 'Datetime'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1267
                     [self.cards], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1268
                     {'A': 'table0.C0', 'A.creation_date': 'table0.C1', 'A.modification_date': 'table0.C2', 'C': 'table0.C2', 'B': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1269
                    #('FetchStep', [('Any D WHERE D is CWUser', [{'D': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1270
                    # [self.ldap, self.system], None, {'D': 'table1.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1271
                    ('OneFetchStep', [('Any A,B,C,D WHERE A creation_date B, A modification_date C, A todo_by D?, A is Note, D is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1272
                                       [{'A': 'Note', 'C': 'Datetime', 'B': 'Datetime', 'D': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1273
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1274
                     {'A': 'table0.C0', 'A.creation_date': 'table0.C1', 'A.modification_date': 'table0.C2', 'C': 'table0.C2', 'B': 'table0.C1'}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1275
                   {'x': 999999})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1276
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1277
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1278
    def test_simplified_var(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1279
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1280
        self._test('Any U WHERE U in_group G, (G name IN ("managers", "logilab") OR (X require_permission P?, P name "bla", P require_group G)), X eid %(x)s, U eid %(u)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1281
                   [('OneFetchStep', [('Any 5 WHERE 5 in_group G, (G name IN("managers", "logilab")) OR (X require_permission P?, P name "bla", P require_group G), X eid 999999',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1282
                                       [{'X': 'Note', 'G': 'CWGroup', 'P': 'CWPermission'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1283
                     None, None, [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1284
                   {'x': 999999, 'u': self.session.user.eid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1285
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1286
    def test_has_text(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1287
        self._test('Card X WHERE X has_text "toto"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1288
                   [('OneFetchStep', [('Any X WHERE X has_text "toto", X is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1289
                                       [{'X': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1290
                     None, None, [self.system], {}, [])])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1291
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1292
    def test_has_text_3(self):
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
  1293
        self._test('Any X WHERE X has_text "toto", X title "zoubidou", X is IN (Card, EmailThread)',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1294
                   [('FetchStep', [(u'Any X WHERE X title "zoubidou", X is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1295
                                    [{'X': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1296
                     [self.cards, self.system], None, {'X': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1297
                    ('UnionStep', None, None, [
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1298
                        ('OneFetchStep', [(u'Any X WHERE X has_text "toto", X is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1299
                                           [{'X': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1300
                         None, None, [self.system], {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1301
                        ('OneFetchStep', [(u'Any X WHERE X has_text "toto", X title "zoubidou", X is EmailThread',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1302
                                           [{'X': 'EmailThread'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1303
                         None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1304
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1305
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1306
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1307
    def test_has_text_orderby_rank(self):
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1308
        self._test('Any X ORDERBY FTIRANK(X) WHERE X has_text "bla", X firstname "bla"',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1309
                   [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1310
                     [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1311
                    ('AggrStep', 'SELECT table1.C1 FROM table1 ORDER BY table1.C0', None, [
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1312
                        ('FetchStep', [('Any FTIRANK(X),X WHERE X has_text "bla", X is CWUser',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1313
                                        [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1314
                         [self.system], {'X': 'table0.C0'}, {'FTIRANK(X)': 'table1.C0', 'X': 'table1.C1'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1315
                        ('FetchStep', [('Any FTIRANK(X),X WHERE X has_text "bla", X firstname "bla", X is Personne',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1316
                                        [{'X': 'Personne'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1317
                         [self.system], {}, {'FTIRANK(X)': 'table1.C0', 'X': 'table1.C1'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1318
                        ]),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1319
                    ])
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1320
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1321
    def test_security_has_text_orderby_rank(self):
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1322
        # use a guest user
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1323
        self.session = self.user_groups_session('guests')
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1324
        self._test('Any X ORDERBY FTIRANK(X) WHERE X has_text "bla", X firstname "bla"',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1325
                   [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1326
                     [self.ldap, self.system], None, {'X': 'table1.C0'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1327
                    ('UnionFetchStep',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1328
                     [('FetchStep', [('Any X WHERE X firstname "bla", X is Personne', [{'X': 'Personne'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1329
                       [self.system], {}, {'X': 'table0.C0'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1330
                      ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1331
                       [self.system], {'X': 'table1.C0'}, {'X': 'table0.C0'}, [])]),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1332
                    ('OneFetchStep', [('Any X ORDERBY FTIRANK(X) WHERE X has_text "bla"',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1333
                                       [{'X': 'CWUser'}, {'X': 'Personne'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1334
                     None, None, [self.system], {'X': 'table0.C0'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1335
                    ])
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1336
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1337
    def test_has_text_select_rank(self):
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1338
        self._test('Any X, FTIRANK(X) WHERE X has_text "bla", X firstname "bla"',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1339
                   # XXX unecessary duplicate selection
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1340
                   [('FetchStep', [('Any X,X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1341
                     [self.ldap, self.system], None, {'X': 'table0.C1'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1342
                    ('UnionStep', None, None, [
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1343
                        ('OneFetchStep', [('Any X,FTIRANK(X) WHERE X has_text "bla", X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1344
                         None, None, [self.system], {'X': 'table0.C1'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1345
                        ('OneFetchStep', [('Any X,FTIRANK(X) WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1346
                         None, None, [self.system], {}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1347
                        ]),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1348
                    ])
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1349
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1350
    def test_security_has_text_select_rank(self):
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1351
        # use a guest user
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1352
        self.session = self.user_groups_session('guests')
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1353
        self._test('Any X, FTIRANK(X) WHERE X has_text "bla", X firstname "bla"',
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1354
                   [('FetchStep', [('Any X,X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1355
                     [self.ldap, self.system], None, {'X': 'table0.C1'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1356
                    ('UnionStep', None, None, [
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1357
                        ('OneFetchStep', [('Any X,FTIRANK(X) WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1358
                         None, None, [self.system], {'X': 'table0.C1'}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1359
                        ('OneFetchStep', [('Any X,FTIRANK(X) WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1360
                         None, None, [self.system], {}, []),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1361
                        ]),
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1362
                    ])
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1363
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1364
    def test_sort_func(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1365
        self._test('Note X ORDERBY DUMB_SORT(RF) WHERE X type RF',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1366
                   [('AggrStep', 'SELECT table0.C0 FROM table0 ORDER BY DUMB_SORT(table0.C1)', None, [
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1367
                       ('FetchStep', [('Any X,RF WHERE X type RF, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1368
                                       [{'X': 'Note', 'RF': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1369
                        [self.cards, self.system], {}, {'X': 'table0.C0', 'X.type': 'table0.C1', 'RF': 'table0.C1'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1370
                       ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1371
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1372
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1373
    def test_ambigous_sort_func(self):
3587
5b3725f315fc test fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3240
diff changeset
  1374
        self._test('Any X ORDERBY DUMB_SORT(RF) WHERE X title RF, X is IN (Bookmark, Card, EmailThread)',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1375
                   [('AggrStep', 'SELECT table0.C0 FROM table0 ORDER BY DUMB_SORT(table0.C1)', None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1376
                     [('FetchStep', [('Any X,RF WHERE X title RF, X is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1377
                                      [{'X': 'Card', 'RF': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1378
                       [self.cards, self.system], {},
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1379
                       {'X': 'table0.C0', 'X.title': 'table0.C1', 'RF': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1380
                      ('FetchStep', [('Any X,RF WHERE X title RF, X is IN(Bookmark, EmailThread)',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1381
                                      [{'RF': 'String', 'X': 'Bookmark'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1382
                                       {'RF': 'String', 'X': 'EmailThread'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1383
                       [self.system], {},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1384
                       {'X': 'table0.C0', 'X.title': 'table0.C1', 'RF': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1385
                      ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1386
                   ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1387
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1388
    def test_attr_unification_1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1389
        self._test('Any X,Y WHERE X is Bookmark, Y is Card, X title T, Y title T',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1390
                   [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1391
                     [('Any Y,T WHERE Y title T, Y is Card', [{'T': 'String', 'Y': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1392
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1393
                     {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.title': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1394
                    ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1395
                     [('Any X,Y WHERE X title T, Y title T, X is Bookmark, Y is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1396
                       [{'T': 'String', 'X': 'Bookmark', 'Y': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1397
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1398
                     {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.title': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1399
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1400
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1401
    def test_attr_unification_2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1402
        self._test('Any X,Y WHERE X is Note, Y is Card, X type T, Y title T',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1403
                   [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1404
                     [('Any X,T WHERE X type T, X is Note', [{'T': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1405
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1406
                     {'T': 'table0.C1', 'X': 'table0.C0', 'X.type': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1407
                    ('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1408
                     [('Any Y,T WHERE Y title T, Y is Card', [{'T': 'String', 'Y': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1409
                     [self.cards, self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1410
                     {'T': 'table1.C1', 'Y': 'table1.C0', 'Y.title': 'table1.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1411
                    ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1412
                     [('Any X,Y WHERE X type T, Y title T, X is Note, Y is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1413
                       [{'T': 'String', 'X': 'Note', 'Y': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1414
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1415
                     {'T': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1416
                      'X': 'table0.C0', 'X.type': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1417
                      'Y': 'table1.C0', 'Y.title': 'table1.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1418
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1419
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1420
    def test_attr_unification_neq_1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1421
        self._test('Any X,Y WHERE X is Bookmark, Y is Card, X creation_date D, Y creation_date > D',
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1422
                   [('FetchStep',
3815
50b87f759b5d test and fix http://www.logilab.org/ticket/499838
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3689
diff changeset
  1423
                     [('Any Y,D WHERE Y creation_date D, Y is Card',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1424
                       [{'D': 'Datetime', 'Y': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1425
                     [self.cards,self.system], None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1426
                     {'D': 'table0.C1', 'Y': 'table0.C0', 'Y.creation_date': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1427
                    ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1428
                     [('Any X,Y WHERE X creation_date D, Y creation_date > D, X is Bookmark, Y is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1429
                       [{'D': 'Datetime', 'X': 'Bookmark', 'Y': 'Card'}])], None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1430
                     [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1431
                     {'D': 'table0.C1', 'Y': 'table0.C0', 'Y.creation_date': 'table0.C1'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1432
                   ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1433
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1434
    def test_subquery_1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1435
        self._test('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by D), D eid %(E)s '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1436
                   'WITH A,N BEING ((Any X,N WHERE X is Tag, X name N) UNION (Any X,T WHERE X is Bookmark, X title T))',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1437
                   [('FetchStep', [('Any X,N WHERE X is Tag, X name N', [{'N': 'String', 'X': 'Tag'}]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1438
                                   ('Any X,T WHERE X is Bookmark, X title T',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1439
                                    [{'T': 'String', 'X': 'Bookmark'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1440
                     [self.system], {}, {'N': 'table0.C1', 'X': 'table0.C0', 'X.name': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1441
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1442
                     [('Any B,C WHERE B login C, B is CWUser', [{'B': 'CWUser', 'C': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1443
                     [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []),
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1444
                    ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser, A is IN(Bookmark, Tag)',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1445
                                       [{'A': 'Bookmark', 'B': 'CWUser', 'C': 'String'},
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1446
                                        {'A': 'Tag', 'B': 'CWUser', 'C': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1447
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1448
                     {'A': 'table0.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1449
                      'B': 'table1.C0', 'B.login': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1450
                      'C': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1451
                      'N': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1452
                     [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1453
                   {'E': self.session.user.eid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1454
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1455
    def test_subquery_2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1456
        self._test('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by D), D eid %(E)s '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1457
                   'WITH A,N BEING ((Any X,N WHERE X is Tag, X name N) UNION (Any X,T WHERE X is Card, X title T))',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1458
                   [('UnionFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1459
                     [('FetchStep', [('Any X,N WHERE X is Tag, X name N', [{'N': 'String', 'X': 'Tag'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1460
                       [self.system], {},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1461
                       {'N': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1462
                        'T': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1463
                        'X': 'table0.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1464
                        'X.name': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1465
                        'X.title': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1466
                      ('FetchStep', [('Any X,T WHERE X is Card, X title T',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1467
                                      [{'T': 'String', 'X': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1468
                       [self.cards, self.system], {},
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1469
                       {'N': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1470
                        'T': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1471
                        'X': 'table0.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1472
                        'X.name': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1473
                        'X.title': 'table0.C1'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1474
                      ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1475
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1476
                     [('Any B,C WHERE B login C, B is CWUser', [{'B': 'CWUser', 'C': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1477
                     [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []),
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1478
                    ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser, A is IN(Card, Tag)',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1479
                                       [{'A': 'Card', 'B': 'CWUser', 'C': 'String'},
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1480
                                        {'A': 'Tag', 'B': 'CWUser', 'C': 'String'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1481
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1482
                     {'A': 'table0.C0',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1483
                      'B': 'table1.C0', 'B.login': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1484
                      'C': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1485
                      'N': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1486
                     [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1487
                   {'E': self.session.user.eid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1488
5420
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1489
    def test_eid_dont_cross_relation_1(self):
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1490
        repo._type_source_cache[999999] = ('Personne', 'system', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1491
        self._test('Any Y,YT WHERE X eid %(x)s, X fiche Y, Y title YT',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1492
                   [('OneFetchStep', [('Any Y,YT WHERE X eid 999999, X fiche Y, Y title YT',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1493
                                       [{'X': 'Personne', 'Y': 'Card', 'YT': 'String'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1494
                     None, None, [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1495
                   {'x': 999999})
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1496
5420
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1497
    def test_eid_dont_cross_relation_2(self):
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1498
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1499
        self.cards.dont_cross_relations.add('concerne')
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1500
        try:
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1501
            self._test('Any Y,S,YT,X WHERE Y concerne X, Y in_state S, X eid 999999, Y ref YT',
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1502
                   [('OneFetchStep', [('Any Y,S,YT,999999 WHERE Y concerne 999999, Y in_state S, Y ref YT',
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1503
                                       [{'Y': 'Affaire', 'YT': 'String', 'S': 'State'}])],
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1504
                     None, None, [self.system], {}, [])],
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1505
                   {'x': 999999})
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1506
        finally:
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1507
            self.cards.dont_cross_relations.remove('concerne')
09b50d7e5321 [ms] fix planning bug with rewritten constants: when removing some source for a const due to relation constraints, we should propagate this change to other constants coming from the same original variable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4915
diff changeset
  1508
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1509
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1510
    # external source w/ .cross_relations == ['multisource_crossed_rel'] ######
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1511
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1512
    def test_crossed_relation_eid_1_invariant(self):
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1513
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1514
        self._test('Any Y WHERE X eid %(x)s, X multisource_crossed_rel Y',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1515
                   [('OneFetchStep', [('Any Y WHERE 999999 multisource_crossed_rel Y', [{u'Y': 'Note'}])],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1516
                      None, None, [self.system], {}, [])
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1517
                    ],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1518
                   {'x': 999999,})
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1519
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1520
    def test_crossed_relation_eid_1_needattr(self):
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1521
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1522
        self._test('Any Y,T WHERE X eid %(x)s, X multisource_crossed_rel Y, Y type T',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1523
                   [('FetchStep', [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1524
                     [self.cards, self.system], None,
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1525
                     {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'}, []),
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1526
                    ('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1527
                                       [{'T': 'String', 'Y': 'Note'}])],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1528
                     None, None, [self.system],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1529
                     {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'}, []),
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1530
                    ],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1531
                   {'x': 999999,})
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1532
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1533
    def test_crossed_relation_eid_2_invariant(self):
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1534
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1535
        self._test('Any Y WHERE X eid %(x)s, X multisource_crossed_rel Y',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1536
                   [('OneFetchStep', [('Any Y WHERE 999999 multisource_crossed_rel Y, Y is Note', [{'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1537
                      None, None, [self.cards, self.system], {}, [])
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1538
                    ],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1539
                   {'x': 999999,})
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1540
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1541
    def test_crossed_relation_eid_2_needattr(self):
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1542
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1543
        self._test('Any Y,T WHERE X eid %(x)s, X multisource_crossed_rel Y, Y type T',
6131
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1544
                   [('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1545
                                       [{'T': 'String', 'Y': 'Note'}])],
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1546
                     None, None, [self.cards, self.system], {},
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1547
                     []),
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1548
                    ],
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1549
                   {'x': 999999,})
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1550
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1551
    def test_crossed_relation_eid_not_1(self):
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1552
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1553
        self._test('Any Y WHERE X eid %(x)s, NOT X multisource_crossed_rel Y',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1554
                   [('FetchStep', [('Any Y WHERE Y is Note', [{'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1555
                     [self.cards, self.system], None, {'Y': 'table0.C0'}, []),
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
  1556
                    ('OneFetchStep', [('Any Y WHERE NOT EXISTS(999999 multisource_crossed_rel Y), Y is Note',
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1557
                                       [{'Y': 'Note'}])],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1558
                     None, None, [self.system],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1559
                     {'Y': 'table0.C0'},  [])],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1560
                   {'x': 999999,})
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1561
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1562
#     def test_crossed_relation_eid_not_2(self):
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1563
#         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1564
#         self._test('Any Y WHERE X eid %(x)s, NOT X multisource_crossed_rel Y',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1565
#                    [],
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1566
#                    {'x': 999999,})
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1567
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1568
    def test_crossed_relation_base_XXXFIXME(self):
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1569
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1570
        self._test('Any X,Y,T WHERE X multisource_crossed_rel Y, Y type T, X type T',
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1571
                   [('FetchStep', [('Any X,T WHERE X type T, X is Note', [{'T': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1572
                     [self.cards, self.system], None,
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1573
                     {'T': 'table0.C1', 'X': 'table0.C0', 'X.type': 'table0.C1'}, []),
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1574
                    ('FetchStep',  [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1575
                     [self.cards, self.system], None,
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1576
                     {'T': 'table1.C1', 'Y': 'table1.C0', 'Y.type': 'table1.C1'},  []),
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1577
                    ('UnionStep', None,  None,
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1578
                     [('OneFetchStep', [('Any X,Y,T WHERE X multisource_crossed_rel Y, Y type T, X type T, X is Note, Y is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1579
                                         [{'T': 'String', 'X': 'Note', 'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1580
                       None, None, [self.cards], None,
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1581
                       []),
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1582
                      ('OneFetchStep', [('Any X,Y,T WHERE X multisource_crossed_rel Y, Y type T, X type T, X is Note, Y is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1583
                                         [{'T': 'String', 'X': 'Note', 'Y': 'Note'}])],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1584
                       None, None, [self.system],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1585
                       {'T': 'table1.C1', 'X': 'table0.C0', 'X.type': 'table0.C1',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1586
                        'Y': 'table1.C0', 'Y.type': 'table1.C1'},
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1587
                       [])]
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  1588
                     )],
393
45a675515427 cross_relations support
sylvain.thenault@logilab.fr
parents: 392
diff changeset
  1589
                    {'x': 999999,})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1590
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1591
    # edition queries tests ###################################################
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1592
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1593
    def test_insert_simplified_var_1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1594
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1595
        repo._type_source_cache[999998] = ('State', 'system', None)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1596
        self._test('INSERT Note X: X in_state S, X type T WHERE S eid %(s)s, N eid %(n)s, N type T',
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1597
                   [('InsertStep',
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1598
                     [('InsertRelationsStep',
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1599
                       [('OneFetchStep', [('Any T WHERE N eid 999999, N type T, N is Note',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1600
                                           [{'N': 'Note', 'T': 'String'}])],
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1601
                        None, None, [self.cards], {}, [])])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1602
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1603
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1604
                   {'n': 999999, 's': 999998})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1605
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1606
    def test_insert_simplified_var_2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1607
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1608
        repo._type_source_cache[999998] = ('State', 'system', None)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1609
        self._test('INSERT Note X: X in_state S, X type T, X migrated_from N WHERE S eid %(s)s, N eid %(n)s, N type T',
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1610
                   [('InsertStep',
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1611
                     [('InsertRelationsStep',
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1612
                       [('OneFetchStep', [('Any T WHERE N eid 999999, N type T, N is Note',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1613
                                           [{'N': 'Note', 'T': 'String'}])],
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1614
                         None, None, [self.cards], {}, [])
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1615
                        ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1616
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1617
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1618
                   {'n': 999999, 's': 999998})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1619
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1620
    def test_insert_simplified_var_3(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1621
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1622
        repo._type_source_cache[999998] = ('State', 'cards', 999998)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1623
        self._test('INSERT Note X: X in_state S, X type T WHERE S eid %(s)s, N eid %(n)s, N type T',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1624
                   [('InsertStep',
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1625
                     [('InsertRelationsStep',
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1626
                       [('OneFetchStep', [('Any T WHERE N eid 999999, N type T, N is Note',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1627
                                           [{'N': 'Note', 'T': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1628
                         None, None, [self.cards], {}, [])]
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1629
                       )]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1630
                     )],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1631
                   {'n': 999999, 's': 999998})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1632
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1633
    def test_insert_simplified_var_4(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1634
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1635
        repo._type_source_cache[999998] = ('State', 'system', None)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1636
        self._test('INSERT Note X: X in_state S, X type "bla", X migrated_from N WHERE S eid %(s)s, N eid %(n)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1637
                   [('InsertStep',
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1638
                      [('InsertRelationsStep', [])]
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1639
                     )],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1640
                   {'n': 999999, 's': 999998})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1641
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1642
    def test_insert_simplified_var_5(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1643
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1644
        repo._type_source_cache[999998] = ('State', 'system', None)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1645
        self._test('INSERT Note X: X in_state S, X type "bla", X migrated_from N WHERE S eid %(s)s, N eid %(n)s, A concerne N',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1646
                   [('InsertStep',
4817
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1647
                     [('InsertRelationsStep',
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1648
                       [('OneFetchStep',
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1649
                         [('Any A WHERE A concerne 999999, A is Affaire',
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1650
                           [{'A': 'Affaire'}])],
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1651
                         None, None, [self.system], {}, []),
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1652
                        ]),
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1653
                      ])
9c8b39914998 fix bad test fix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4775
diff changeset
  1654
                    ],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1655
                   {'n': 999999, 's': 999998})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1656
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1657
    def test_delete_relation1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1658
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1659
        self._test('DELETE X created_by Y WHERE X eid %(x)s, NOT Y eid %(y)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1660
                   [('DeleteRelationsStep', [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1661
                       ('OneFetchStep', [('Any 5,Y WHERE %s created_by Y, NOT Y eid %s, Y is CWUser'%(ueid, ueid),
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1662
                                          [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1663
                        None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1664
                       ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1665
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1666
                   {'x': ueid, 'y': ueid})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1667
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1668
    def test_delete_relation2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1669
        ueid = self.session.user.eid
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1670
        self._test('DELETE X created_by Y WHERE X eid %(x)s, NOT Y login "syt"',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1671
                   [('FetchStep', [('Any Y WHERE NOT Y login "syt", Y is CWUser', [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1672
                     [self.ldap, self.system], None, {'Y': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1673
                    ('DeleteRelationsStep', [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1674
                        ('OneFetchStep', [('Any %s,Y WHERE %s created_by Y, Y is CWUser'%(ueid,ueid), [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1675
                         None, None, [self.system], {'Y': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1676
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1677
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1678
                   {'x': ueid, 'y': ueid})
341
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1679
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1680
    def test_delete_entity1(self):
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1681
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1682
        self._test('DELETE Note X WHERE X eid %(x)s, NOT Y multisource_rel X',
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1683
                   [('DeleteEntitiesStep',
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
  1684
                     [('OneFetchStep', [('Any 999999 WHERE NOT EXISTS(Y multisource_rel 999999), Y is IN(Card, Note)',
341
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1685
                                         [{'Y': 'Card'}, {'Y': 'Note'}])],
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1686
                       None, None, [self.system], {}, [])
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1687
                      ])
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1688
                    ],
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1689
                   {'x': 999999})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1690
341
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1691
    def test_delete_entity2(self):
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1692
        repo._type_source_cache[999999] = ('Note', 'system', 999999)
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1693
        self._test('DELETE Note X WHERE X eid %(x)s, NOT X multisource_inlined_rel Y',
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1694
                   [('DeleteEntitiesStep',
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1695
                     [('OneFetchStep', [('Any X WHERE X eid 999999, NOT X multisource_inlined_rel Y, X is Note, Y is IN(Affaire, Note)',
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1696
                                         [{'X': 'Note', 'Y': 'Affaire'}, {'X': 'Note', 'Y': 'Note'}])],
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1697
                       None, None, [self.system], {}, [])
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1698
                      ])
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1699
                    ],
0a426be2f3a2 fixes for some cases of neged inlined relations, may have to use (new) IntersectStep. XXX: write IntersectFetchStep
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 332
diff changeset
  1700
                   {'x': 999999})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1701
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1702
    def test_update(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1703
        self._test('SET X copain Y WHERE X login "comme", Y login "cochon"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1704
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1705
                     [('Any X WHERE X login "comme", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1706
                     [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1707
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1708
                     [('Any Y WHERE Y login "cochon", Y is CWUser', [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1709
                     [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1710
                    ('UpdateStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1711
                     [('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1712
                       [('DISTINCT Any X,Y WHERE X is CWUser, Y is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1713
                         [{'X': 'CWUser', 'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1714
                       None, None, [self.system], {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1715
                      ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1716
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1717
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1718
    def test_update2(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1719
        self._test('SET U in_group G WHERE G name ~= "bougloup%", U login "admin"',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1720
                   [('FetchStep', [('Any U WHERE U login "admin", U is CWUser', [{'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1721
                     [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1722
                     ('UpdateStep', [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1723
                        ('OneFetchStep', [('DISTINCT Any U,G WHERE G name ILIKE "bougloup%", G is CWGroup, U is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1724
                                           [{'U': 'CWUser', 'G': 'CWGroup'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1725
                         None, None, [self.system], {'U': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1726
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1727
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1728
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1729
    def test_update3(self):
4674
3d509dbb473a [test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
  1730
        anoneid = self.user_groups_session('guests').user.eid
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1731
        # since we are adding a in_state relation for an entity in the system
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1732
        # source, states should only be searched in the system source as well
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1733
        self._test('SET X in_state S WHERE X eid %(x)s, S name "deactivated"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1734
                   [('UpdateStep', [
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1735
                       ('OneFetchStep', [('DISTINCT Any S WHERE S name "deactivated", S is State',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1736
                                          [{'S': 'State'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1737
                        None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1738
                       ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1739
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1740
                   {'x': anoneid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1741
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1742
#     def test_update4(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1743
#         # since we are adding a in_state relation with a state from the system
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1744
#         # source, CWUser should only be searched only in the system source as well
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1745
#         rset = self.execute('State X WHERE X name "activated"')
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1746
#         assert len(rset) == 1, rset
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1747
#         activatedeid = rset[0][0]
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1748
#         self._test('SET X in_state S WHERE X is CWUser, S eid %s' % activatedeid,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1749
#                    [('UpdateStep', [
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1750
#                        ('OneFetchStep', [('DISTINCT Any X,%s WHERE X is CWUser' % activatedeid,
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1751
#                                           [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1752
#                         None, None, [self.system], {}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1753
#                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1754
#                     ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1755
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1756
    def test_ldap_user_related_to_invariant_and_dont_cross_rel(self):
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1757
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1758
        self.cards.dont_cross_relations.add('created_by')
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1759
        try:
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1760
            self._test('Any X,XL WHERE E eid %(x)s, E created_by X, X login XL',
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1761
                   [('FetchStep', [('Any X,XL WHERE X login XL, X is CWUser',
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1762
                                    [{'X': 'CWUser', 'XL': 'String'}])],
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1763
                     [self.ldap, self.system], None,
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1764
                     {'X': 'table0.C0', 'X.login': 'table0.C1', 'XL': 'table0.C1'},
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1765
                     []),
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1766
                    ('OneFetchStep',
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1767
                     [('Any X,XL WHERE 999999 created_by X, X login XL, X is CWUser',
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1768
                       [{'X': 'CWUser', 'XL': 'String'}])],
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1769
                     None, None,
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1770
                     [self.system],
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1771
                     {'X': 'table0.C0', 'X.login': 'table0.C1', 'XL': 'table0.C1'},
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1772
                     [])],
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1773
                       {'x': 999999})
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1774
        finally:
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1775
            self.cards.dont_cross_relations.remove('created_by')
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1776
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1777
    def test_ambigous_cross_relation(self):
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1778
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1779
        self.cards.support_relations['see_also'] = True
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1780
        self.cards.cross_relations.add('see_also')
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1781
        try:
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1782
            self._test('Any X,AA ORDERBY AA WHERE E eid %(x)s, E see_also X, X modification_date AA',
6131
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1783
                       [('AggrStep',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1784
                         'SELECT table0.C0, table0.C1 FROM table0 ORDER BY table0.C1',
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1785
                         None,
6131
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1786
                         [('FetchStep',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1787
                           [('Any X,AA WHERE 999999 see_also X, X modification_date AA, X is Note',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1788
                             [{'AA': 'Datetime', 'X': 'Note'}])], [self.cards, self.system], {},
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1789
                           {'AA': 'table0.C1', 'X': 'table0.C0',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1790
                            'X.modification_date': 'table0.C1'},
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1791
                           []),
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1792
                          ('FetchStep',
6131
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1793
                           [('Any X,AA WHERE 999999 see_also X, X modification_date AA, X is Bookmark',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1794
                             [{'AA': 'Datetime', 'X': 'Bookmark'}])],
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1795
                           [self.system], {},
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1796
                           {'AA': 'table0.C1', 'X': 'table0.C0',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1797
                            'X.modification_date': 'table0.C1'},
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1798
                           [])])],
6129
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1799
                         {'x': 999999})
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1800
        finally:
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1801
            del self.cards.support_relations['see_also']
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1802
            self.cards.cross_relations.remove('see_also')
fea746b60093 [ms] fix two planner bugs: one occuring query such as X created_by U where X in a external source and U may come from an ldap source. The other being that when we've to merge input maps, we were modifying the same tree/solutions while a copy were needed. Also, ensure we add type restrictions, necessary for pyro source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6057
diff changeset
  1803
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1804
    # non regression tests ####################################################
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1805
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1806
    def test_nonregr1(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1807
        self._test('Any X, Y WHERE X copain Y, X login "syt", Y login "cochon"',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1808
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1809
                     [('Any X WHERE X login "syt", X is CWUser', [{'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1810
                     [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1811
                    ('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1812
                     [('Any Y WHERE Y login "cochon", Y is CWUser', [{'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1813
                     [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1814
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1815
                     [('Any X,Y WHERE X copain Y, X is CWUser, Y is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1816
                       [{'X': 'CWUser', 'Y': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1817
                     None, None, [self.system], {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1818
                    ])
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1819
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1820
    def test_nonregr2(self):
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
  1821
        iworkflowable = self.session.user.cw_adapt_to('IWorkflowable')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
  1822
        iworkflowable.fire_transition('deactivate')
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
  1823
        treid = iworkflowable.latest_trinfo().eid
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1824
        self._test('Any X ORDERBY D DESC WHERE E eid %(x)s, E wf_info_for X, X modification_date D',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1825
                   [('FetchStep', [('Any X,D WHERE X modification_date D, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1826
                                    [{'X': 'Note', 'D': 'Datetime'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1827
                     [self.cards, self.system], None, {'X': 'table0.C0', 'X.modification_date': 'table0.C1', 'D': 'table0.C1'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1828
                    ('FetchStep', [('Any X,D WHERE X modification_date D, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1829
                                    [{'X': 'CWUser', 'D': 'Datetime'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1830
                     [self.ldap, self.system], None, {'X': 'table1.C0', 'X.modification_date': 'table1.C1', 'D': 'table1.C1'}, []),
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1831
                    ('AggrStep', 'SELECT table2.C0 FROM table2 ORDER BY table2.C1 DESC', None, [
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1832
                        ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is Affaire'%treid,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1833
                                        [{'X': 'Affaire', 'E': 'TrInfo', 'D': 'Datetime'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1834
                         [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1835
                         {},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1836
                         {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1837
                        ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is CWUser'%treid,
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1838
                                        [{'X': 'CWUser', 'E': 'TrInfo', 'D': 'Datetime'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1839
                         [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1840
                         {'X': 'table1.C0', 'X.modification_date': 'table1.C1', 'D': 'table1.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1841
                         {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1842
                        ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is Note'%treid,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1843
                                        [{'X': 'Note', 'E': 'TrInfo', 'D': 'Datetime'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1844
                         [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1845
                         {'X': 'table0.C0', 'X.modification_date': 'table0.C1', 'D': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1846
                         {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1847
                        ]),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1848
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1849
                   {'x': treid})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1850
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1851
    def test_nonregr3(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1852
        # original jpl query:
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1853
        # Any X, NOW - CD, P WHERE P is Project, U interested_in P, U is CWUser, U login "sthenault", X concerns P, X creation_date CD ORDERBY CD DESC LIMIT 5
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1854
        self._test('Any X, NOW - CD, P ORDERBY CD DESC LIMIT 5 WHERE P bookmarked_by U, U login "admin", P is X, X creation_date CD',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1855
                   [('FetchStep', [('Any U WHERE U login "admin", U is CWUser', [{'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1856
                     [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1857
                    ('OneFetchStep', [('Any X,(NOW - CD),P ORDERBY CD DESC LIMIT 5 WHERE P bookmarked_by U, P is X, X creation_date CD, P is Bookmark, U is CWUser, X is CWEType',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1858
                                       [{'P': 'Bookmark', 'U': 'CWUser', 'X': 'CWEType', 'CD': 'Datetime'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1859
                     5, None,  [self.system], {'U': 'table0.C0'}, [])]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1860
                   )
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1861
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1862
    def test_nonregr4(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1863
        self._test('Any U ORDERBY D DESC WHERE WF wf_info_for X, WF creation_date D, WF from_state FS, '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1864
                   'WF owned_by U?, X eid %(x)s',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1865
                   [#('FetchStep', [('Any U WHERE U is CWUser', [{'U': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1866
                    # [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1867
                    ('OneFetchStep', [('Any U ORDERBY D DESC WHERE WF wf_info_for 5, WF creation_date D, WF from_state FS, WF owned_by U?',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1868
                                       [{'WF': 'TrInfo', 'FS': 'State', 'U': 'CWUser', 'D': 'Datetime'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1869
                     None, None,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1870
                     [self.system], {}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1871
                   {'x': self.session.user.eid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1872
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1873
    def test_nonregr5(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1874
        # original jpl query:
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1875
        # DISTINCT Version V WHERE MB done_in MV, MV eid %(x)s,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1876
        # MB depends_on B, B done_in V, V version_of P, NOT P eid %(p)s'
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1877
        cardeid = self.execute('INSERT Card X: X title "hop"')[0][0]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1878
        noteeid = self.execute('INSERT Note X')[0][0]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1879
        self._test('DISTINCT Card V WHERE MB documented_by MV, MV eid %(x)s, '
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1880
                   'MB depends_on B, B documented_by V, V multisource_rel P, NOT P eid %(p)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1881
                   [('FetchStep', [('Any V WHERE V multisource_rel P, NOT P eid %s, P is Note, V is Card'%noteeid,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1882
                                    [{'P': 'Note', 'V': 'Card'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1883
                     [self.cards, self.system], None, {'V': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1884
                    ('OneFetchStep', [('DISTINCT Any V WHERE MB documented_by %s, MB depends_on B, B documented_by V, B is Affaire, MB is Affaire, V is Card'%cardeid,
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1885
                                       [{'B': 'Affaire', 'MB': 'Affaire', 'V': 'Card'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1886
                     None, None, [self.system], {'V': 'table0.C0'}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1887
                   {'x': cardeid, 'p': noteeid})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1888
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1889
    def test_nonregr6(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1890
        self._test('Any X WHERE X concerne Y',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1891
                   [('OneFetchStep', [('Any X WHERE X concerne Y',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1892
                                       [{'Y': 'Division', 'X': 'Affaire'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1893
                                        {'Y': 'Note', 'X': 'Affaire'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1894
                                        {'Y': 'Societe', 'X': 'Affaire'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1895
                                        {'Y': 'SubDivision', 'X': 'Affaire'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1896
                                        {'Y': 'Affaire', 'X': 'Personne'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1897
                     None,  None, [self.system], {}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1898
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1899
        self._test('Any X WHERE X concerne Y, Y is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1900
                   [('FetchStep', [('Any Y WHERE Y is Note', [{'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1901
                      [self.cards, self.system], None, {'Y': 'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1902
                    ('OneFetchStep', [('Any X WHERE X concerne Y, X is Affaire, Y is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1903
                                       [{'X': 'Affaire', 'Y': 'Note'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1904
                     None, None, [self.system], {'Y': 'table0.C0'}, [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1905
                    ])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1906
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1907
    def test_nonregr7(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1908
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1909
        self._test('Any S,SUM(DUR),SUM(I),(SUM(I) - SUM(DUR)),MIN(DI),MAX(DI) GROUPBY S ORDERBY S WHERE A is Affaire, A duration DUR, A invoiced I, A modification_date DI, A in_state S, S name SN, (EXISTS(A concerne WP, W multisource_rel WP)) OR (EXISTS(A concerne W)), W eid %(n)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1910
                   [('FetchStep', [('Any WP WHERE 999999 multisource_rel WP, WP is Note', [{'WP': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1911
                     [self.cards], None, {'WP': u'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1912
                    ('OneFetchStep', [('Any S,SUM(DUR),SUM(I),(SUM(I) - SUM(DUR)),MIN(DI),MAX(DI) GROUPBY S ORDERBY S WHERE A duration DUR, A invoiced I, A modification_date DI, A in_state S, S name SN, (EXISTS(A concerne WP, WP is Note)) OR (EXISTS(A concerne 999999)), A is Affaire, S is State',
6081
ede33e6400ab [forms] test abs() rql function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6057
diff changeset
  1913
                                       [{'A': 'Affaire', 'DI': 'Datetime', 'DUR': 'Int', 'I': 'Float', 'S': 'State', 'SN': 'String', 'WP': 'Note'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1914
                     None, None, [self.system], {'WP': u'table0.C0'}, [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1915
                   {'n': 999999})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1916
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1917
    def test_nonregr8(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1918
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1919
        self._test('Any X,Z WHERE X eid %(x)s, X multisource_rel Y, Z concerne X',
6131
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1920
                   [('FetchStep', [('Any 999999 WHERE 999999 multisource_rel Y, Y is Note',
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1921
                                    [{'Y': 'Note'}])],
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1922
                     [self.cards],
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1923
                     None, {u'%(x)s': 'table0.C0'},
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1924
                     []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1925
                    ('OneFetchStep', [('Any 999999,Z WHERE Z concerne 999999, Z is Affaire',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1926
                                       [{'Z': 'Affaire'}])],
6131
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1927
                     None, None, [self.system],
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1928
                     {u'%(x)s': 'table0.C0'}, []),
087c5a168010 [ms] more planning bug fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6129
diff changeset
  1929
                    ],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1930
                   {'x': 999999})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1931
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1932
    def test_nonregr9(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1933
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1934
        repo._type_source_cache[999998] = ('Note', 'cards', 999998)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1935
        self._test('SET X migrated_from Y WHERE X eid %(x)s, Y multisource_rel Z, Z eid %(z)s, Y migrated_from Z',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1936
                   [('FetchStep', [('Any Y WHERE Y multisource_rel 999998, Y is Note', [{'Y': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1937
                     [self.cards], None, {'Y': u'table0.C0'}, []),
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1938
                    ('UpdateStep',
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1939
                     [('OneFetchStep', [('DISTINCT Any Y WHERE Y migrated_from 999998, Y is Note',
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1940
                                         [{'Y': 'Note'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1941
                       None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1942
                       {'Y': u'table0.C0'}, [])])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1943
                   {'x': 999999, 'z': 999998})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1944
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1945
    def test_nonregr10(self):
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1946
        repo._type_source_cache[999999] = ('CWUser', 'ldap', 999999)
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1947
        self._test('Any X,AA,AB ORDERBY AA WHERE E eid %(x)s, E owned_by X, X login AA, X modification_date AB',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1948
                   [('FetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1949
                     [('Any X,AA,AB WHERE X login AA, X modification_date AB, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1950
                       [{'AA': 'String', 'AB': 'Datetime', 'X': 'CWUser'}])],
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1951
                     [self.ldap, self.system], None, {'AA': 'table0.C1', 'AB': 'table0.C2',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  1952
                                                      'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2'},
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1953
                     []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1954
                    ('OneFetchStep',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1955
                     [('Any X,AA,AB ORDERBY AA WHERE 999999 owned_by X, X login AA, X modification_date AB, X is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  1956
                       [{'AA': 'String', 'AB': 'Datetime', 'X': 'CWUser'}])],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1957
                     None, None, [self.system], {'AA': 'table0.C1', 'AB': 'table0.C2',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1958
                                                 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1959
                     [])
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1960
                    ],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1961
                   {'x': 999999})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1962
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1963
    def test_nonregr11(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1964
        repo._type_source_cache[999999] = ('Bookmark', 'system', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1965
        self._test('SET X bookmarked_by Y WHERE X eid %(x)s, Y login "hop"',
4764
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1966
                   [('UpdateStep',
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1967
                     [('OneFetchStep', [('DISTINCT Any Y WHERE Y login "hop", Y is CWUser', [{'Y': 'CWUser'}])],
ec9c20c6b9f7 [repo] improve planning of insert/update queries: do not select affected constants so the don't go and back to/from the source.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4685
diff changeset
  1968
                       None, None, [self.ldap, self.system], {}, [])]
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1969
                     )],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1970
                   {'x': 999999})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  1971
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1972
    def test_nonregr12(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1973
        repo._type_source_cache[999999] = ('Note', 'cards', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1974
        self._test('Any X ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E see_also X',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1975
                   [('FetchStep', [('Any X,Z WHERE X modification_date Z, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1976
                                    [{'X': 'Note', 'Z': 'Datetime'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  1977
                     [self.cards, self.system], None, {'X': 'table0.C0', 'X.modification_date': 'table0.C1', 'Z': 'table0.C1'},
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1978
                     []),
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5590
diff changeset
  1979
                    ('AggrStep', 'SELECT table1.C0 FROM table1 ORDER BY table1.C1 DESC', None,
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1980
                     [('FetchStep', [('Any X,Z WHERE X modification_date Z, 999999 see_also X, X is Bookmark',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1981
                                      [{'X': 'Bookmark', 'Z': 'Datetime'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1982
                       [self.system], {},   {'X': 'table1.C0', 'X.modification_date': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1983
                                             'Z': 'table1.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1984
                       []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1985
                      ('FetchStep', [('Any X,Z WHERE X modification_date Z, 999999 see_also X, X is Note',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1986
                                      [{'X': 'Note', 'Z': 'Datetime'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1987
                       [self.system], {'X': 'table0.C0', 'X.modification_date': 'table0.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1988
                                       'Z': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1989
                       {'X': 'table1.C0', 'X.modification_date': 'table1.C1',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1990
                        'Z': 'table1.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1991
                       [])]
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1992
                      )],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1993
                   {'x': 999999})
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  1994
1121
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  1995
    def test_nonregr13_1(self):
1122
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 1121
diff changeset
  1996
        # identity wrapped into exists:
9f37de24251f fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents: 1121
diff changeset
  1997
        # should'nt propagate constraint that U is in the same source as ME
1120
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  1998
        self._test('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  1999
                   'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (EXISTS(U identity ME) '
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2000
                   'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2001
                   'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is CWUser)',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2002
                   [('FetchStep', [('Any U,UL WHERE U login UL, U is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2003
                                    [{'U': 'CWUser', 'UL': 'String'}])],
1120
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2004
                     [self.ldap, self.system], None,
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2005
                     {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2006
                     []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2007
                    ('FetchStep', [('Any U,UL WHERE ((EXISTS(U identity 5)) OR (EXISTS(U in_group G, G name IN("managers", "staff"), G is CWGroup))) OR (EXISTS(U in_group H, 5 in_group H, NOT H name "users", H is CWGroup)), U login UL, U is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2008
                                    [{'G': 'CWGroup', 'H': 'CWGroup', 'U': 'CWUser', 'UL': 'String'}])],
1120
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2009
                     [self.system],
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2010
                     {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2011
                     {'U': 'table1.C0', 'U.login': 'table1.C1', 'UL': 'table1.C1'},
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2012
                     []),
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2013
                    ('OneFetchStep', [('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2014
                                       [{'B': 'File', 'U': 'CWUser', 'UL': 'String'}])],
1120
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2015
                     None, None, [self.system],
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2016
                     {'U': 'table1.C0', 'UL': 'table1.C1'},
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2017
                     [])],
1c24cde4bf72 fix ms planning w/ relation constraint propagation
sylvain.thenault@logilab.fr
parents: 393
diff changeset
  2018
                   {'x': self.session.user.eid})
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2019
1121
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2020
    def test_nonregr13_2(self):
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2021
        # identity *not* wrapped into exists.
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2022
        #
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2023
        # XXX this test fail since in this case, in "U identity 5" U and 5 are
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2024
        # from the same scope so constraints are applied (telling the U should
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2025
        # come from the same source as user with eid 5).
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2026
        #
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2027
        # IMO this is normal, unless we introduce a special case for the
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2028
        # identity relation. BUT I think it's better to leave it as is and to
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2029
        # explain constraint propagation rules, and so why this should be
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2030
        # wrapped in exists() if used in multi-source
1121
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2031
        self.skip('take a look at me if you wish')
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2032
        self._test('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2033
                   'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (U identity ME '
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2034
                   'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2035
                   'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is CWUser)',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2036
                   [('FetchStep', [('Any U,UL WHERE U login UL, U is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2037
                                    [{'U': 'CWUser', 'UL': 'String'}])],
1121
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2038
                     [self.ldap, self.system], None,
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2039
                     {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2040
                     []),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2041
                    ('FetchStep', [('Any U,UL WHERE ((U identity 5) OR (EXISTS(U in_group G, G name IN("managers", "staff"), G is CWGroup))) OR (EXISTS(U in_group H, 5 in_group H, NOT H name "users", H is CWGroup)), U login UL, U is CWUser',
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2042
                                    [{'G': 'CWGroup', 'H': 'CWGroup', 'U': 'CWUser', 'UL': 'String'}])],
1121
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2043
                     [self.system],
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2044
                     {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2045
                     {'U': 'table1.C0', 'U.login': 'table1.C1', 'UL': 'table1.C1'},
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2046
                     []),
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2047
                    ('OneFetchStep', [('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1231
diff changeset
  2048
                                       [{'B': 'File', 'U': 'CWUser', 'UL': 'String'}])],
1121
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2049
                     None, None, [self.system],
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2050
                     {'U': 'table1.C0', 'UL': 'table1.C1'},
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2051
                     [])],
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2052
                   {'x': self.session.user.eid})
43fa67acd9d0 one more test, but skipped in it may be a won't fix
sylvain.thenault@logilab.fr
parents: 1120
diff changeset
  2053
2170
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2054
    def test_nonregr14_1(self):
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2055
        repo._type_source_cache[999999] = ('CWUser', 'ldap', 999999)
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2056
        self._test('Any X WHERE X eid %(x)s, X owned_by U, U eid %(u)s',
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2057
                   [('OneFetchStep', [('Any 999999 WHERE 999999 owned_by 999999', [{}])],
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2058
                     None, None, [self.system], {}, [])],
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2059
                   {'x': 999999, 'u': 999999})
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2060
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2061
    def test_nonregr14_2(self):
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2062
        repo._type_source_cache[999999] = ('CWUser', 'ldap', 999999)
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2063
        repo._type_source_cache[999998] = ('Note', 'system', 999998)
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2064
        self._test('Any X WHERE X eid %(x)s, X owned_by U, U eid %(u)s',
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2065
                   [('OneFetchStep', [('Any 999998 WHERE 999998 owned_by 999999', [{}])],
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2066
                     None, None, [self.system], {}, [])],
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2067
                   {'x': 999998, 'u': 999999})
6adbc965c51b fix jpl/ticket/34862: msplanner bug with query generated to check if a user from ldap is owned_by himself
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2165
diff changeset
  2068
2180
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2069
    def test_nonregr14_3(self):
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2070
        repo._type_source_cache[999999] = ('CWUser', 'system', 999999)
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2071
        repo._type_source_cache[999998] = ('CWUser', 'ldap', 999998)
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2072
        self._test('Any X WHERE X eid %(x)s, X owned_by U, U eid %(u)s',
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2073
                   [('OneFetchStep', [('Any 999998 WHERE 999998 owned_by 999999', [{}])],
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2074
                     None, None, [self.system], {}, [])],
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2075
                   {'x': 999998, 'u': 999999})
bf2e81fb52be one more test (see mrambourg error report. We should ensure the previous fix fix his case as well which include security injection of the rql)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2170
diff changeset
  2076
3239
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2077
    def test_nonregr_identity_no_source_access_1(self):
2688
afa99d53401c [multi-source] test and fix msplanner regression
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2180
diff changeset
  2078
        repo._type_source_cache[999999] = ('CWUser', 'ldap', 999998)
afa99d53401c [multi-source] test and fix msplanner regression
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2180
diff changeset
  2079
        self._test('Any S WHERE S identity U, S eid %(s)s, U eid %(u)s',
afa99d53401c [multi-source] test and fix msplanner regression
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2180
diff changeset
  2080
                   [('OneFetchStep', [('Any 999999 WHERE 999999 identity 999999', [{}])],
afa99d53401c [multi-source] test and fix msplanner regression
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2180
diff changeset
  2081
                     None, None, [self.system], {}, [])],
afa99d53401c [multi-source] test and fix msplanner regression
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2180
diff changeset
  2082
                   {'s': 999999, 'u': 999999})
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2083
3239
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2084
    def test_nonregr_identity_no_source_access_2(self):
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2085
        repo._type_source_cache[999999] = ('EmailAddress', 'system', 999999)
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2086
        repo._type_source_cache[999998] = ('CWUser', 'ldap', 999998)
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2087
        self._test('Any X WHERE O use_email X, ((EXISTS(O identity U)) OR (EXISTS(O in_group G, G name IN("managers", "staff")))) OR (EXISTS(O in_group G2, U in_group G2, NOT G2 name "users")), X eid %(x)s, U eid %(u)s',
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2088
                   [('OneFetchStep', [('Any 999999 WHERE O use_email 999999, ((EXISTS(O identity 999998)) OR (EXISTS(O in_group G, G name IN("managers", "staff")))) OR (EXISTS(O in_group G2, 999998 in_group G2, NOT G2 name "users"))',
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2089
                                       [{'G': 'CWGroup', 'G2': 'CWGroup', 'O': 'CWUser'}])],
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2090
                     None, None, [self.system], {}, [])],
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2091
                   {'x': 999999, 'u': 999998})
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2092
3633
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2093
    def test_state_of_cross(self):
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2094
        self._test('DELETE State X WHERE NOT X state_of Y',
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2095
                   [('DeleteEntitiesStep',
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2096
                     [('OneFetchStep',
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2097
                       [('Any X WHERE NOT X state_of Y, X is State, Y is Workflow',
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2098
                         [{'X': 'State', 'Y': 'Workflow'}])],
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2099
                       None, None, [self.system], {}, [])])]
2d81178bea5f [multi-source] add test case for an encountered bug, fixed by adding state_of to dont_cross_relations. Added a note to remind me that something should be done to be smarter in handling this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3587
diff changeset
  2100
                   )
3239
1ceac4cd4fb7 [ms] fix planning w/ query using identity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
  2101
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2102
class MSPlannerTwoSameExternalSourcesTC(BasePlannerTC):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2103
    """test planner related feature on a 3-sources repository:
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2104
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2105
    * 2 rql sources supporting Card
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2106
    """
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2107
    repo = repo
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2108
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2109
    def setUp(self):
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2110
        self.setup()
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2111
        self.add_source(FakeCardSource, 'cards')
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2112
        self.add_source(FakeCardSource, 'cards2')
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: 3239
diff changeset
  2113
        self.planner = MSPlanner(self.o.schema, self.repo.vreg.rqlhelper)
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2114
        assert repo.sources_by_uri['cards2'].support_relation('multisource_crossed_rel')
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2115
        assert 'multisource_crossed_rel' in repo.sources_by_uri['cards2'].cross_relations
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2116
        assert repo.sources_by_uri['cards'].support_relation('multisource_crossed_rel')
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2117
        assert 'multisource_crossed_rel' in repo.sources_by_uri['cards'].cross_relations
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2118
    _test = test_plan
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2119
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2120
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2121
    def test_linked_external_entities(self):
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2122
        repo._type_source_cache[999999] = ('Tag', 'system', 999999)
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2123
        self._test('Any X,XT WHERE X is Card, X title XT, T tags X, T eid %(t)s',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2124
                   [('FetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2125
                     [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2126
                     [self.cards, self.cards2, self.system],
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2127
                     None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2128
                     []),
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2129
                    ('OneFetchStep',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2130
                     [('Any X,XT WHERE X title XT, 999999 tags X, X is Card',
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2131
                       [{'X': 'Card', 'XT': 'String'}])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2132
                     None, None, [self.system],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2133
                     {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'},
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2134
                     [])],
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2135
                   {'t': 999999})
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2136
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2137
    def test_version_depends_on(self):
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2138
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2139
        self._test('Any X,AD,AE WHERE E eid %(x)s, E migrated_from X, X in_state AD, AD name AE',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2140
                   [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2141
                                    [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2142
                     [self.cards, self.cards2, self.system],
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2143
                     None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2144
                            'AE': 'table0.C2', 'X': 'table0.C0'},
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2145
                     []),
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2146
                    ('OneFetchStep', [('Any X,AD,AE WHERE 999999 migrated_from X, AD name AE, AD is State, X is Note',
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2147
                                       [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2148
                     None, None, [self.system],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2149
                     {'AD': 'table0.C1', 'AD.name': 'table0.C2', 'AE': 'table0.C2', 'X': 'table0.C0'},
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2150
                     [])],
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2151
                   {'x': 999999})
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2152
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2153
    def test_version_crossed_depends_on_1(self):
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2154
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2155
        self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2156
                   [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2157
                                    [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2158
                     [self.cards, self.cards2, self.system],
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2159
                     None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2160
                            'AE': 'table0.C2', 'X': 'table0.C0'},
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2161
                     []),
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2162
                    ('UnionStep', None, None,
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2163
                     [('OneFetchStep', [('Any X,AD,AE WHERE 999999 multisource_crossed_rel X, AD name AE, AD is State, X is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2164
                                         [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2165
                       None, None, [self.cards], None,
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2166
                       []),
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2167
                      ('OneFetchStep', [('Any X,AD,AE WHERE 999999 multisource_crossed_rel X, AD name AE, AD is State, X is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2168
                                         [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2169
                       None, None, [self.system],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2170
                       {'AD': 'table0.C1', 'AD.name': 'table0.C2',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2171
                        'AE': 'table0.C2', 'X': 'table0.C0'},
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2172
                       [])]
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2173
                     )],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2174
                   {'x': 999999})
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2175
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2176
    def test_version_crossed_depends_on_2(self):
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2177
        self.repo._type_source_cache[999999] = ('Note', 'system', 999999)
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2178
        self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2179
                   [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2180
                                    [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2181
                     [self.cards, self.cards2, self.system],
1230
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2182
                     None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2183
                            'AE': 'table0.C2', 'X': 'table0.C0'},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2184
                     []),
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2185
                    ('OneFetchStep', [('Any X,AD,AE WHERE 999999 multisource_crossed_rel X, AD name AE, AD is State, X is Note',
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2186
                                       [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2187
                     None, None, [self.system],
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2188
                     {'AD': 'table0.C1', 'AD.name': 'table0.C2', 'AE': 'table0.C2', 'X': 'table0.C0'},
232e16835fff fix constant handling in sourcesterms + minor cleanup
sylvain.thenault@logilab.fr
parents: 1228
diff changeset
  2189
                     [])],
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2190
                   {'x': 999999})
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2191
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2192
    def test_version_crossed_depends_on_3(self):
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2193
        self._test('Any X,AD,AE WHERE E multisource_crossed_rel X, X in_state AD, AD name AE, E is Note',
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2194
                   [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2195
                                    [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2196
                     [self.cards, self.cards2, self.system],
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2197
                     None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2198
                            'AE': 'table0.C2', 'X': 'table0.C0'},
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2199
                     []),
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2200
                    ('FetchStep', [('Any E WHERE E is Note', [{'E': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2201
                     [self.cards, self.cards2, self.system],
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2202
                     None, {'E': 'table1.C0'},
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2203
                     []),
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2204
                    ('UnionStep', None, None,
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2205
                     [('OneFetchStep', [('Any X,AD,AE WHERE E multisource_crossed_rel X, AD name AE, AD is State, E is Note, X is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2206
                                         [{'AD': 'State', 'AE': 'String', 'E': 'Note', 'X': 'Note'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2207
                       None, None, [self.cards, self.cards2], None,
1231
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2208
                       []),
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2209
                      ('OneFetchStep', [('Any X,AD,AE WHERE E multisource_crossed_rel X, AD name AE, AD is State, E is Note, X is Note',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2210
                                         [{'AD': 'State', 'AE': 'String', 'E': 'Note', 'X': 'Note'}])],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2211
                       None, None, [self.system],
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2212
                       {'AD': 'table0.C1',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2213
                        'AD.name': 'table0.C2',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2214
                        'AE': 'table0.C2',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2215
                        'E': 'table1.C0',
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2216
                        'X': 'table0.C0'},
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2217
                       [])]
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2218
                     )]
1457a545af03 more fix of cross relation handling
sylvain.thenault@logilab.fr
parents: 1230
diff changeset
  2219
                   )
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2220
1786
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2221
    def test_nonregr_dont_cross_rel_source_filtering_1(self):
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2222
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2223
        self._test('Any S WHERE E eid %(x)s, E in_state S, NOT S name "moved"',
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2224
                   [('OneFetchStep', [('Any S WHERE 999999 in_state S, NOT S name "moved", S is State',
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2225
                                       [{'S': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2226
                     None, None, [self.cards], {}, []
1786
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2227
                     )],
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2228
                   {'x': 999999})
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2229
eccd1885d42e one more msplanning bug fixed...
sylvain.thenault@logilab.fr
parents: 1785
diff changeset
  2230
    def test_nonregr_dont_cross_rel_source_filtering_2(self):
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2231
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2232
        self._test('Any X,AA,AB WHERE E eid %(x)s, E in_state X, X name AA, X modification_date AB',
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2233
                   [('OneFetchStep', [('Any X,AA,AB WHERE 999999 in_state X, X name AA, X modification_date AB, X is State',
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2234
                                       [{'AA': 'String', 'AB': 'Datetime', 'X': 'State'}])],
2074
9e268cb6202e enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
  2235
                     None, None, [self.cards], {}, []
1785
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2236
                     )],
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2237
                   {'x': 999999})
01245e2a777d ms planning fix
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
  2238
2165
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2239
    def test_nonregr_eid_query(self):
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2240
        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2241
        self._test('Any X WHERE X eid 999999',
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2242
                   [('OneFetchStep', [('Any 999999', [{}])],
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2243
                     None, None, [self.system], {}, []
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2244
                     )],
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2245
                   {'x': 999999})
dd40c375044e #344177: ms planning bug with "Any X WHERE X eid 123" and 123 coming from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2114
diff changeset
  2246
1228
91ae10ffb611 * refactor ms planner (renaming, reorganization)
sylvain.thenault@logilab.fr
parents: 1122
diff changeset
  2247
6056
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2248
    def test_nonregr_not_is(self):
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2249
        self._test("Any X WHERE X owned_by U, U login 'anon', NOT X is Comment",
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2250
                   [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2251
                                    [{'X': 'Note'}, {'X': 'State'}, {'X': 'Card'}])],
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2252
                     [self.cards, self.cards2, self.system],
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2253
                     None, {'X': 'table0.C0'}, []),
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2254
                    ('UnionStep', None, None,
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2255
                     [('OneFetchStep',
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2256
                       [(u'Any X WHERE X owned_by U, U login "anon", U is CWUser, X is IN(Affaire, BaseTransition, Basket, Bookmark, CWAttribute, CWCache, CWConstraint, CWConstraintType, CWEType, CWGroup, CWPermission, CWProperty, CWRType, CWRelation, CWUser, Division, Email, EmailAddress, EmailPart, EmailThread, ExternalUri, File, Folder, Personne, RQLExpression, Societe, SubDivision, SubWorkflowExitPoint, Tag, TrInfo, Transition, Workflow, WorkflowTransition)',
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2257
                         [{'U': 'CWUser', 'X': 'Affaire'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2258
                          {'U': 'CWUser', 'X': 'BaseTransition'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2259
                          {'U': 'CWUser', 'X': 'Basket'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2260
                          {'U': 'CWUser', 'X': 'Bookmark'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2261
                          {'U': 'CWUser', 'X': 'CWAttribute'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2262
                          {'U': 'CWUser', 'X': 'CWCache'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2263
                          {'U': 'CWUser', 'X': 'CWConstraint'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2264
                          {'U': 'CWUser', 'X': 'CWConstraintType'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2265
                          {'U': 'CWUser', 'X': 'CWEType'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2266
                          {'U': 'CWUser', 'X': 'CWGroup'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2267
                          {'U': 'CWUser', 'X': 'CWPermission'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2268
                          {'U': 'CWUser', 'X': 'CWProperty'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2269
                          {'U': 'CWUser', 'X': 'CWRType'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2270
                          {'U': 'CWUser', 'X': 'CWRelation'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2271
                          {'U': 'CWUser', 'X': 'CWUser'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2272
                          {'U': 'CWUser', 'X': 'Division'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2273
                          {'U': 'CWUser', 'X': 'Email'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2274
                          {'U': 'CWUser', 'X': 'EmailAddress'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2275
                          {'U': 'CWUser', 'X': 'EmailPart'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2276
                          {'U': 'CWUser', 'X': 'EmailThread'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2277
                          {'U': 'CWUser', 'X': 'ExternalUri'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2278
                          {'U': 'CWUser', 'X': 'File'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2279
                          {'U': 'CWUser', 'X': 'Folder'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2280
                          {'U': 'CWUser', 'X': 'Personne'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2281
                          {'U': 'CWUser', 'X': 'RQLExpression'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2282
                          {'U': 'CWUser', 'X': 'Societe'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2283
                          {'U': 'CWUser', 'X': 'SubDivision'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2284
                          {'U': 'CWUser', 'X': 'SubWorkflowExitPoint'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2285
                          {'U': 'CWUser', 'X': 'Tag'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2286
                          {'U': 'CWUser', 'X': 'TrInfo'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2287
                          {'U': 'CWUser', 'X': 'Transition'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2288
                          {'U': 'CWUser', 'X': 'Workflow'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2289
                          {'U': 'CWUser', 'X': 'WorkflowTransition'}])],
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2290
                       None, None,
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2291
                       [self.system], {}, []),
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2292
                      ('OneFetchStep',
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2293
                       [(u'Any X WHERE X owned_by U, U login "anon", U is CWUser, X is IN(Card, Note, State)',
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2294
                         [{'U': 'CWUser', 'X': 'Note'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2295
                          {'U': 'CWUser', 'X': 'State'},
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2296
                          {'U': 'CWUser', 'X': 'Card'}])],
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2297
                       None, None,
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2298
                       [self.system], {'X': 'table0.C0'}, [])
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2299
                      ])
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2300
                    ])
37a37e5ba330 [ms] fix a ms plannification bug with NOT is
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5768
diff changeset
  2301
2075
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2302
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2303
class FakeVCSSource(AbstractSource):
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2304
    uri = 'ccc'
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2305
    support_entities = {'Card': True, 'Note': True}
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2306
    support_relations = {'multisource_inlined_rel': True,
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2307
                         'multisource_rel': True}
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2308
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2309
    def syntax_tree_search(self, *args, **kwargs):
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2310
        return []
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2311
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2312
class MSPlannerVCSSource(BasePlannerTC):
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2313
    repo = repo
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2314
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2315
    def setUp(self):
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2316
        self.setup()
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2317
        self.add_source(FakeVCSSource, 'vcs')
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: 3239
diff changeset
  2318
        self.planner = MSPlanner(self.o.schema, self.repo.vreg.rqlhelper)
2075
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2319
    _test = test_plan
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2320
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2321
    def test_multisource_inlined_rel_skipped(self):
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2322
        self._test('Any MAX(VC) '
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2323
                   'WHERE VC multisource_inlined_rel R2, R para %(branch)s, VC in_state S, S name "published", '
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2324
                   '(EXISTS(R identity R2)) OR (EXISTS(R multisource_rel R2))',
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2325
                   [('FetchStep', [('Any VC WHERE VC multisource_inlined_rel R2, R para "???", (EXISTS(R identity R2)) OR (EXISTS(R multisource_rel R2)), R is Note, R2 is Note, VC is Note',
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2326
                                    [{'R': 'Note', 'R2': 'Note', 'VC': 'Note'}])],
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2327
                     [self.vcs, self.system], None,
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2328
                     {'VC': 'table0.C0'},
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2329
                     []),
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2330
                    ('OneFetchStep', [(u'Any MAX(VC) WHERE VC in_state S, S name "published", S is State, VC is Note',
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2331
                                       [{'S': 'State', 'VC': 'Note'}])],
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2332
                     None, None, [self.system],
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2333
                     {'VC': 'table0.C0'},
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2334
                     [])
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2335
                    ])
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2336
2108
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2337
    def test_fully_simplified_extsource(self):
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2338
        self.repo._type_source_cache[999998] = ('Note', 'vcs', 999998)
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2339
        self.repo._type_source_cache[999999] = ('Note', 'vcs', 999999)
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2340
        self._test('Any X, Y WHERE NOT X multisource_rel Y, X eid 999998, Y eid 999999',
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
  2341
                   [('OneFetchStep', [('Any 999998,999999 WHERE NOT EXISTS(999998 multisource_rel 999999)', [{}])],
2108
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2342
                     None, None, [self.vcs], {}, [])
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2343
                    ])
b3f6fa7ad59f add test and fix for queries where all variables are simplified and come from an external source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2076
diff changeset
  2344
2114
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2345
    def test_nonregr_fully_simplified_extsource(self):
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2346
        self.repo._type_source_cache[999998] = ('Note', 'vcs', 999998)
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2347
        self.repo._type_source_cache[999999] = ('Note', 'vcs', 999999)
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2348
        self.repo._type_source_cache[1000000] = ('Note', 'system', 1000000)
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2349
        self._test('DISTINCT Any T,FALSE,L,M WHERE L eid 1000000, M eid 999999, T eid 999998',
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2350
                   [('OneFetchStep', [('DISTINCT Any 999998,FALSE,1000000,999999', [{}])],
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2351
                     None, None, [self.system], {}, [])
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2352
                    ])
862f27d94af4 one more ms planning bug
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2108
diff changeset
  2353
2075
933ccfce6e91 fix bug in multisource planner, w/ inlined relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2074
diff changeset
  2354
332
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2355
if __name__ == '__main__':
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2356
    from logilab.common.testlib import unittest_main
86b8d58664eb backport msplanner test from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
  2357
    unittest_main()