server/test/unittest_msplanner.py
branchtls-sprint
changeset 1398 5fe84a5f7035
parent 1231 1457a545af03
child 1785 01245e2a777d
equal deleted inserted replaced
1397:6cbc7bc8ea6d 1398:5fe84a5f7035
    17 from cubicweb.server.sources import AbstractSource
    17 from cubicweb.server.sources import AbstractSource
    18 from cubicweb.server.msplanner import MSPlanner, PartPlanInformation
    18 from cubicweb.server.msplanner import MSPlanner, PartPlanInformation
    19 
    19 
    20 class FakeUserROSource(AbstractSource):
    20 class FakeUserROSource(AbstractSource):
    21     uri = 'zzz'
    21     uri = 'zzz'
    22     support_entities = {'EUser': False}
    22     support_entities = {'CWUser': False}
    23     support_relations = {}
    23     support_relations = {}
    24     def syntax_tree_search(self, *args, **kwargs):
    24     def syntax_tree_search(self, *args, **kwargs):
    25         return []
    25         return []
    26 
    26 
    27         
    27         
    36     def syntax_tree_search(self, *args, **kwargs):
    36     def syntax_tree_search(self, *args, **kwargs):
    37         return []
    37         return []
    38 
    38 
    39 X_ALL_SOLS = sorted([{'X': 'Affaire'}, {'X': 'Basket'}, {'X': 'Bookmark'},
    39 X_ALL_SOLS = sorted([{'X': 'Affaire'}, {'X': 'Basket'}, {'X': 'Bookmark'},
    40                      {'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
    40                      {'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
    41                      {'X': 'ECache'}, {'X': 'EConstraint'}, {'X': 'EConstraintType'},
    41                      {'X': 'CWCache'}, {'X': 'CWConstraint'}, {'X': 'CWConstraintType'},
    42                      {'X': 'EEType'}, {'X': 'EFRDef'}, {'X': 'EGroup'},
    42                      {'X': 'CWEType'}, {'X': 'CWAttribute'}, {'X': 'CWGroup'},
    43                      {'X': 'ENFRDef'}, {'X': 'EPermission'}, {'X': 'EProperty'},
    43                      {'X': 'CWRelation'}, {'X': 'CWPermission'}, {'X': 'CWProperty'},
    44                      {'X': 'ERType'}, {'X': 'EUser'}, {'X': 'Email'},
    44                      {'X': 'CWRType'}, {'X': 'CWUser'}, {'X': 'Email'},
    45                      {'X': 'EmailAddress'}, {'X': 'EmailPart'}, {'X': 'EmailThread'},
    45                      {'X': 'EmailAddress'}, {'X': 'EmailPart'}, {'X': 'EmailThread'},
    46                      {'X': 'File'}, {'X': 'Folder'}, {'X': 'Image'},
    46                      {'X': 'File'}, {'X': 'Folder'}, {'X': 'Image'},
    47                      {'X': 'Note'}, {'X': 'Personne'}, {'X': 'RQLExpression'},
    47                      {'X': 'Note'}, {'X': 'Personne'}, {'X': 'RQLExpression'},
    48                      {'X': 'Societe'}, {'X': 'State'}, {'X': 'SubDivision'},
    48                      {'X': 'Societe'}, {'X': 'State'}, {'X': 'SubDivision'},
    49                      {'X': 'Tag'}, {'X': 'TrInfo'}, {'X': 'Transition'}])
    49                      {'X': 'Tag'}, {'X': 'TrInfo'}, {'X': 'Transition'}])
    59 
    59 
    60 class BaseMSPlannerTC(BasePlannerTC):
    60 class BaseMSPlannerTC(BasePlannerTC):
    61     """test planner related feature on a 3-sources repository:
    61     """test planner related feature on a 3-sources repository:
    62     
    62     
    63     * system source supporting everything
    63     * system source supporting everything
    64     * ldap source supporting EUser
    64     * ldap source supporting CWUser
    65     * rql source supporting Card
    65     * rql source supporting Card
    66     """
    66     """
    67     repo = repo
    67     repo = repo
    68     
    68     
    69     def setUp(self):
    69     def setUp(self):
    77         affreadperms = list(self.schema['Affaire']._groups['read'])
    77         affreadperms = list(self.schema['Affaire']._groups['read'])
    78         self.prevrqlexpr_affaire = affreadperms[-1]
    78         self.prevrqlexpr_affaire = affreadperms[-1]
    79         # add access to type attribute so S can't be invariant
    79         # add access to type attribute so S can't be invariant
    80         affreadperms[-1] = ERQLExpression('X concerne S?, S owned_by U, S type "X"')
    80         affreadperms[-1] = ERQLExpression('X concerne S?, S owned_by U, S type "X"')
    81         self.schema['Affaire']._groups['read'] = tuple(affreadperms)
    81         self.schema['Affaire']._groups['read'] = tuple(affreadperms)
    82         # hijack EUser security
    82         # hijack CWUser security
    83         userreadperms = list(self.schema['EUser']._groups['read'])
    83         userreadperms = list(self.schema['CWUser']._groups['read'])
    84         self.prevrqlexpr_user = userreadperms[-1]
    84         self.prevrqlexpr_user = userreadperms[-1]
    85         userreadperms[-1] = ERQLExpression('X owned_by U')
    85         userreadperms[-1] = ERQLExpression('X owned_by U')
    86         self.schema['EUser']._groups['read'] = tuple(userreadperms)
    86         self.schema['CWUser']._groups['read'] = tuple(userreadperms)
    87         
    87         
    88         self.sources = self.o._repo.sources
    88         self.sources = self.o._repo.sources
    89         self.system = self.sources[-1]
    89         self.system = self.sources[-1]
    90         self.sources.append(FakeUserROSource(self.o._repo, self.o.schema,
    90         self.sources.append(FakeUserROSource(self.o._repo, self.o.schema,
    91                                              {'uri': 'ldapuser'}))
    91                                              {'uri': 'ldapuser'}))
   113         affreadperms[-1] = self.prevrqlexpr_affaire
   113         affreadperms[-1] = self.prevrqlexpr_affaire
   114         self.schema['Affaire']._groups['read'] = tuple(affreadperms)
   114         self.schema['Affaire']._groups['read'] = tuple(affreadperms)
   115         clear_cache(self.schema['Affaire'], 'ERSchema_get_rqlexprs')
   115         clear_cache(self.schema['Affaire'], 'ERSchema_get_rqlexprs')
   116         
   116         
   117     def restore_orig_euser_security(self):
   117     def restore_orig_euser_security(self):
   118         userreadperms = list(self.schema['EUser']._groups['read'])
   118         userreadperms = list(self.schema['CWUser']._groups['read'])
   119         userreadperms[-1] = self.prevrqlexpr_user
   119         userreadperms[-1] = self.prevrqlexpr_user
   120         self.schema['EUser']._groups['read'] = tuple(userreadperms)
   120         self.schema['CWUser']._groups['read'] = tuple(userreadperms)
   121         clear_cache(self.schema['EUser'], 'ERSchema_get_rqlexprs')
   121         clear_cache(self.schema['CWUser'], 'ERSchema_get_rqlexprs')
   122 
   122 
   123                   
   123                   
   124 class PartPlanInformationTC(BaseMSPlannerTC):
   124 class PartPlanInformationTC(BaseMSPlannerTC):
   125 
   125 
   126     def _test(self, rql, *args):
   126     def _test(self, rql, *args):
   141         self.assertEquals(ppi.needsplit, needsplit)
   141         self.assertEquals(ppi.needsplit, needsplit)
   142 
   142 
   143         
   143         
   144     def test_simple_system_only(self):
   144     def test_simple_system_only(self):
   145         """retrieve entities only supported by the system source"""
   145         """retrieve entities only supported by the system source"""
   146         self._test('EGroup X',
   146         self._test('CWGroup X',
   147                    {self.system: {'X': s[0]}}, False)
   147                    {self.system: {'X': s[0]}}, False)
   148         
   148         
   149     def test_simple_system_ldap(self):
   149     def test_simple_system_ldap(self):
   150         """retrieve EUser X from both sources and return concatenation of results
   150         """retrieve CWUser X from both sources and return concatenation of results
   151         """
   151         """
   152         self._test('EUser X',
   152         self._test('CWUser X',
   153                    {self.system: {'X': s[0]}, self.ldap: {'X': s[0]}}, False)
   153                    {self.system: {'X': s[0]}, self.ldap: {'X': s[0]}}, False)
   154         
   154         
   155     def test_simple_system_rql(self):
   155     def test_simple_system_rql(self):
   156         """retrieve Card X from both sources and return concatenation of results
   156         """retrieve Card X from both sources and return concatenation of results
   157         """
   157         """
   158         self._test('Any X, XT WHERE X is Card, X title XT',
   158         self._test('Any X, XT WHERE X is Card, X title XT',
   159                    {self.system: {'X': s[0]}, self.rql: {'X': s[0]}}, False)
   159                    {self.system: {'X': s[0]}, self.rql: {'X': s[0]}}, False)
   160         
   160         
   161     def test_simple_eid_specified(self):
   161     def test_simple_eid_specified(self):
   162         """retrieve EUser X from system source (eid is specified, can locate the entity)
   162         """retrieve CWUser X from system source (eid is specified, can locate the entity)
   163         """
   163         """
   164         ueid = self.session.user.eid
   164         ueid = self.session.user.eid
   165         self._test('Any X,L WHERE X eid %(x)s, X login L', {'x': ueid},
   165         self._test('Any X,L WHERE X eid %(x)s, X login L', {'x': ueid},
   166                    {self.system: {'X': s[0]}}, False)
   166                    {self.system: {'X': s[0]}}, False)
   167         
   167         
   168     def test_simple_eid_invariant(self):
   168     def test_simple_eid_invariant(self):
   169         """retrieve EUser X from system source (eid is specified, can locate the entity)
   169         """retrieve CWUser X from system source (eid is specified, can locate the entity)
   170         """
   170         """
   171         ueid = self.session.user.eid
   171         ueid = self.session.user.eid
   172         self._test('Any X WHERE X eid %(x)s', {'x': ueid},
   172         self._test('Any X WHERE X eid %(x)s', {'x': ueid},
   173                    {self.system: {'x': s[0]}}, False)
   173                    {self.system: {'x': s[0]}}, False)
   174         
   174         
   175     def test_simple_invariant(self):
   175     def test_simple_invariant(self):
   176         """retrieve EUser X from system source only (X is invariant and in_group not supported by ldap source)
   176         """retrieve CWUser X from system source only (X is invariant and in_group not supported by ldap source)
   177         """
   177         """
   178         self._test('Any X WHERE X is EUser, X in_group G, G name "users"',
   178         self._test('Any X WHERE X is CWUser, X in_group G, G name "users"',
   179                    {self.system: {'X': s[0], 'G': s[0], 'in_group': s[0]}}, False)
   179                    {self.system: {'X': s[0], 'G': s[0], 'in_group': s[0]}}, False)
   180         
   180         
   181     def test_security_has_text(self):
   181     def test_security_has_text(self):
   182         """retrieve EUser X from system source only (has_text not supported by ldap source)
   182         """retrieve CWUser X from system source only (has_text not supported by ldap source)
   183         """
   183         """
   184         # specify EUser instead of any since the way this test is written we aren't well dealing
   184         # specify CWUser instead of any since the way this test is written we aren't well dealing
   185         # with ambigous query (eg only considering the first solution)
   185         # with ambigous query (eg only considering the first solution)
   186         self._test('EUser X WHERE X has_text "bla"',
   186         self._test('CWUser X WHERE X has_text "bla"',
   187                    {self.system: {'X': s[0]}}, False)
   187                    {self.system: {'X': s[0]}}, False)
   188         
   188         
   189     def test_complex_base(self):
   189     def test_complex_base(self):
   190         """
   190         """
   191         1. retrieve Any X, L WHERE X is EUser, X login L from system and ldap sources, store
   191         1. retrieve Any X, L WHERE X is CWUser, X login L from system and ldap sources, store
   192            concatenation of results into a temporary table
   192            concatenation of results into a temporary table
   193         2. return the result of Any X, L WHERE X is TMP, X login L, X in_group G,
   193         2. return the result of Any X, L WHERE X is TMP, X login L, X in_group G,
   194            G name 'users' on the system source
   194            G name 'users' on the system source
   195         """
   195         """
   196         self._test('Any X,L WHERE X is EUser, X in_group G, X login L, G name "users"',
   196         self._test('Any X,L WHERE X is CWUser, X in_group G, X login L, G name "users"',
   197                    {self.system: {'X': s[0], 'G': s[0], 'in_group': s[0]},
   197                    {self.system: {'X': s[0], 'G': s[0], 'in_group': s[0]},
   198                     self.ldap : {'X': s[0]}}, True)
   198                     self.ldap : {'X': s[0]}}, True)
   199 
   199 
   200     def test_complex_invariant_ordered(self):
   200     def test_complex_invariant_ordered(self):
   201         """
   201         """
   220         self._test('Any X,L,AA WHERE E eid %(x)s, E owned_by X, X login L, X modification_date AA', {'x': ueid},
   220         self._test('Any X,L,AA WHERE E eid %(x)s, E owned_by X, X login L, X modification_date AA', {'x': ueid},
   221                    {self.system: {'x': s[0], 'X': s[0], 'owned_by': s[0]},
   221                    {self.system: {'x': s[0], 'X': s[0], 'owned_by': s[0]},
   222                     self.ldap : {'X': s[0]}}, True)
   222                     self.ldap : {'X': s[0]}}, True)
   223 
   223 
   224     def test_complex_ambigous(self):
   224     def test_complex_ambigous(self):
   225         """retrieve EUser X from system and ldap sources, Person X from system source only
   225         """retrieve CWUser X from system and ldap sources, Person X from system source only
   226         """
   226         """
   227         self._test('Any X,F WHERE X firstname F',
   227         self._test('Any X,F WHERE X firstname F',
   228                    {self.system: {'X': s[0, 1]},
   228                    {self.system: {'X': s[0, 1]},
   229                     self.ldap: {'X': s[0]}}, True)
   229                     self.ldap: {'X': s[0]}}, True)
   230 
   230 
   368     _test = test_plan
   368     _test = test_plan
   369 
   369 
   370     def test_simple_system_only(self):
   370     def test_simple_system_only(self):
   371         """retrieve entities only supported by the system source
   371         """retrieve entities only supported by the system source
   372         """
   372         """
   373         self._test('EGroup X',
   373         self._test('CWGroup X',
   374                    [('OneFetchStep', [('Any X WHERE X is EGroup', [{'X': 'EGroup'}])],
   374                    [('OneFetchStep', [('Any X WHERE X is CWGroup', [{'X': 'CWGroup'}])],
   375                      None, None, [self.system], {}, [])])
   375                      None, None, [self.system], {}, [])])
   376 
   376 
   377     def test_simple_system_only_limit(self):
   377     def test_simple_system_only_limit(self):
   378         """retrieve entities only supported by the system source
   378         """retrieve entities only supported by the system source
   379         """
   379         """
   380         self._test('EGroup X LIMIT 10',
   380         self._test('CWGroup X LIMIT 10',
   381                    [('OneFetchStep', [('Any X LIMIT 10 WHERE X is EGroup', [{'X': 'EGroup'}])],
   381                    [('OneFetchStep', [('Any X LIMIT 10 WHERE X is CWGroup', [{'X': 'CWGroup'}])],
   382                      10, None, [self.system], {}, [])])
   382                      10, None, [self.system], {}, [])])
   383 
   383 
   384     def test_simple_system_only_limit_offset(self):
   384     def test_simple_system_only_limit_offset(self):
   385         """retrieve entities only supported by the system source
   385         """retrieve entities only supported by the system source
   386         """
   386         """
   387         self._test('EGroup X LIMIT 10 OFFSET 10',
   387         self._test('CWGroup X LIMIT 10 OFFSET 10',
   388                    [('OneFetchStep', [('Any X LIMIT 10 OFFSET 10 WHERE X is EGroup', [{'X': 'EGroup'}])],
   388                    [('OneFetchStep', [('Any X LIMIT 10 OFFSET 10 WHERE X is CWGroup', [{'X': 'CWGroup'}])],
   389                      10, 10, [self.system], {}, [])])
   389                      10, 10, [self.system], {}, [])])
   390         
   390         
   391     def test_simple_system_ldap(self):
   391     def test_simple_system_ldap(self):
   392         """retrieve EUser X from both sources and return concatenation of results
   392         """retrieve CWUser X from both sources and return concatenation of results
   393         """
   393         """
   394         self._test('EUser X',
   394         self._test('CWUser X',
   395                    [('OneFetchStep', [('Any X WHERE X is EUser', [{'X': 'EUser'}])],
   395                    [('OneFetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
   396                      None, None, [self.ldap, self.system], {}, [])])
   396                      None, None, [self.ldap, self.system], {}, [])])
   397         
   397         
   398     def test_simple_system_ldap_limit(self):
   398     def test_simple_system_ldap_limit(self):
   399         """retrieve EUser X from both sources and return concatenation of results
   399         """retrieve CWUser X from both sources and return concatenation of results
   400         """
   400         """
   401         self._test('EUser X LIMIT 10',
   401         self._test('CWUser X LIMIT 10',
   402                    [('OneFetchStep', [('Any X LIMIT 10 WHERE X is EUser', [{'X': 'EUser'}])],
   402                    [('OneFetchStep', [('Any X LIMIT 10 WHERE X is CWUser', [{'X': 'CWUser'}])],
   403                      10, None, [self.ldap, self.system], {}, [])])
   403                      10, None, [self.ldap, self.system], {}, [])])
   404 
   404 
   405     def test_simple_system_ldap_limit_offset(self):
   405     def test_simple_system_ldap_limit_offset(self):
   406         """retrieve EUser X from both sources and return concatenation of results
   406         """retrieve CWUser X from both sources and return concatenation of results
   407         """
   407         """
   408         self._test('EUser X LIMIT 10 OFFSET 10',
   408         self._test('CWUser X LIMIT 10 OFFSET 10',
   409                    [('OneFetchStep', [('Any X LIMIT 10 OFFSET 10 WHERE X is EUser', [{'X': 'EUser'}])],
   409                    [('OneFetchStep', [('Any X LIMIT 10 OFFSET 10 WHERE X is CWUser', [{'X': 'CWUser'}])],
   410                      10, 10, [self.ldap, self.system], {}, [])])
   410                      10, 10, [self.ldap, self.system], {}, [])])
   411 
   411 
   412     def test_simple_system_ldap_ordered_limit_offset(self):
   412     def test_simple_system_ldap_ordered_limit_offset(self):
   413         """retrieve EUser X from both sources and return concatenation of results
   413         """retrieve CWUser X from both sources and return concatenation of results
   414         """
   414         """
   415         self._test('EUser X ORDERBY X LIMIT 10 OFFSET 10',
   415         self._test('CWUser X ORDERBY X LIMIT 10 OFFSET 10',
   416                    [('AggrStep', 'Any X ORDERBY X', 10, 10, 'table0', None, [
   416                    [('AggrStep', 'Any X ORDERBY X', 10, 10, 'table0', None, [
   417                        ('FetchStep', [('Any X WHERE X is EUser', [{'X': 'EUser'}])],
   417                        ('FetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
   418                         [self.ldap, self.system], {}, {'X': 'table0.C0'}, []),
   418                         [self.ldap, self.system], {}, {'X': 'table0.C0'}, []),
   419                        ]),
   419                        ]),
   420                    ])
   420                    ])
   421     def test_simple_system_ldap_aggregat(self):
   421     def test_simple_system_ldap_aggregat(self):
   422         """retrieve EUser X from both sources and return concatenation of results
   422         """retrieve CWUser X from both sources and return concatenation of results
   423         """
   423         """
   424         # COUNT(X) is kept in sub-step and transformed into SUM(X) in the AggrStep
   424         # COUNT(X) is kept in sub-step and transformed into SUM(X) in the AggrStep
   425         self._test('Any COUNT(X) WHERE X is EUser',
   425         self._test('Any COUNT(X) WHERE X is CWUser',
   426                    [('AggrStep', 'Any COUNT(X)', None, None, 'table0', None, [
   426                    [('AggrStep', 'Any COUNT(X)', None, None, 'table0', None, [
   427                        ('FetchStep', [('Any COUNT(X) WHERE X is EUser', [{'X': 'EUser'}])],
   427                        ('FetchStep', [('Any COUNT(X) WHERE X is CWUser', [{'X': 'CWUser'}])],
   428                         [self.ldap, self.system], {}, {'COUNT(X)': 'table0.C0'}, []),
   428                         [self.ldap, self.system], {}, {'COUNT(X)': 'table0.C0'}, []),
   429                        ]),
   429                        ]),
   430                    ])
   430                    ])
   431         
   431         
   432     def test_simple_system_rql(self):
   432     def test_simple_system_rql(self):
   435         self._test('Any X, XT WHERE X is Card, X title XT',
   435         self._test('Any X, XT WHERE X is Card, X title XT',
   436                    [('OneFetchStep', [('Any X,XT WHERE X is Card, X title XT', [{'X': 'Card', 'XT': 'String'}])],
   436                    [('OneFetchStep', [('Any X,XT WHERE X is Card, X title XT', [{'X': 'Card', 'XT': 'String'}])],
   437                      None, None, [self.rql, self.system], {}, [])])
   437                      None, None, [self.rql, self.system], {}, [])])
   438         
   438         
   439     def test_simple_eid_specified(self):
   439     def test_simple_eid_specified(self):
   440         """retrieve EUser X from system source (eid is specified, can locate the entity)
   440         """retrieve CWUser X from system source (eid is specified, can locate the entity)
   441         """
   441         """
   442         ueid = self.session.user.eid
   442         ueid = self.session.user.eid
   443         self._test('Any X,L WHERE X eid %(x)s, X login L',
   443         self._test('Any X,L WHERE X eid %(x)s, X login L',
   444                    [('OneFetchStep', [('Any X,L WHERE X eid %s, X login L'%ueid, [{'X': 'EUser', 'L': 'String'}])],
   444                    [('OneFetchStep', [('Any X,L WHERE X eid %s, X login L'%ueid, [{'X': 'CWUser', 'L': 'String'}])],
   445                      None, None, [self.system], {}, [])],
   445                      None, None, [self.system], {}, [])],
   446                    {'x': ueid})
   446                    {'x': ueid})
   447         
   447         
   448     def test_simple_eid_invariant(self):
   448     def test_simple_eid_invariant(self):
   449         """retrieve EUser X from system source (eid is specified, can locate the entity)
   449         """retrieve CWUser X from system source (eid is specified, can locate the entity)
   450         """
   450         """
   451         ueid = self.session.user.eid
   451         ueid = self.session.user.eid
   452         self._test('Any X WHERE X eid %(x)s',
   452         self._test('Any X WHERE X eid %(x)s',
   453                    [('OneFetchStep', [('Any %s'%ueid, [{}])],
   453                    [('OneFetchStep', [('Any %s'%ueid, [{}])],
   454                      None, None, [self.system], {}, [])],
   454                      None, None, [self.system], {}, [])],
   455                    {'x': ueid})
   455                    {'x': ueid})
   456         
   456         
   457     def test_simple_invariant(self):
   457     def test_simple_invariant(self):
   458         """retrieve EUser X from system source only (X is invariant and in_group not supported by ldap source)
   458         """retrieve CWUser X from system source only (X is invariant and in_group not supported by ldap source)
   459         """
   459         """
   460         self._test('Any X WHERE X is EUser, X in_group G, G name "users"',
   460         self._test('Any X WHERE X is CWUser, X in_group G, G name "users"',
   461                    [('OneFetchStep', [('Any X WHERE X is EUser, X in_group G, G name "users"',
   461                    [('OneFetchStep', [('Any X WHERE X is CWUser, X in_group G, G name "users"',
   462                                        [{'X': 'EUser', 'G': 'EGroup'}])],
   462                                        [{'X': 'CWUser', 'G': 'CWGroup'}])],
   463                      None, None, [self.system], {}, [])])
   463                      None, None, [self.system], {}, [])])
   464         
   464         
   465     def test_complex_base(self):
   465     def test_complex_base(self):
   466         """
   466         """
   467         1. retrieve Any X, L WHERE X is EUser, X login L from system and ldap sources, store
   467         1. retrieve Any X, L WHERE X is CWUser, X login L from system and ldap sources, store
   468            concatenation of results into a temporary table
   468            concatenation of results into a temporary table
   469         2. return the result of Any X, L WHERE X is TMP, X login LX in_group G,
   469         2. return the result of Any X, L WHERE X is TMP, X login LX in_group G,
   470            G name 'users' on the system source
   470            G name 'users' on the system source
   471         """
   471         """
   472         self._test('Any X,L WHERE X is EUser, X in_group G, X login L, G name "users"',
   472         self._test('Any X,L WHERE X is CWUser, X in_group G, X login L, G name "users"',
   473                    [('FetchStep', [('Any X,L WHERE X login L, X is EUser', [{'X': 'EUser', 'L': 'String'}])],
   473                    [('FetchStep', [('Any X,L WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
   474                      [self.ldap, self.system], None,
   474                      [self.ldap, self.system], None,
   475                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
   475                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
   476                     ('OneFetchStep', [('Any X,L WHERE X in_group G, X login L, G name "users", G is EGroup, X is EUser',
   476                     ('OneFetchStep', [('Any X,L WHERE X in_group G, X login L, G name "users", G is CWGroup, X is CWUser',
   477                                        [{'X': 'EUser', 'L': 'String', 'G': 'EGroup'}])],
   477                                        [{'X': 'CWUser', 'L': 'String', 'G': 'CWGroup'}])],
   478                      None, None, [self.system],
   478                      None, None, [self.system],
   479                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])
   479                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])
   480                     ])
   480                     ])
   481 
   481 
   482     def test_complex_base_limit_offset(self):
   482     def test_complex_base_limit_offset(self):
   483         """
   483         """
   484         1. retrieve Any X, L WHERE X is EUser, X login L from system and ldap sources, store
   484         1. retrieve Any X, L WHERE X is CWUser, X login L from system and ldap sources, store
   485            concatenation of results into a temporary table
   485            concatenation of results into a temporary table
   486         2. return the result of Any X, L WHERE X is TMP, X login LX in_group G,
   486         2. return the result of Any X, L WHERE X is TMP, X login LX in_group G,
   487            G name 'users' on the system source
   487            G name 'users' on the system source
   488         """
   488         """
   489         self._test('Any X,L LIMIT 10 OFFSET 10 WHERE X is EUser, X in_group G, X login L, G name "users"',
   489         self._test('Any X,L LIMIT 10 OFFSET 10 WHERE X is CWUser, X in_group G, X login L, G name "users"',
   490                    [('FetchStep', [('Any X,L WHERE X login L, X is EUser', [{'X': 'EUser', 'L': 'String'}])],
   490                    [('FetchStep', [('Any X,L WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
   491                      [self.ldap, self.system], None,
   491                      [self.ldap, self.system], None,
   492                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
   492                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
   493                     ('OneFetchStep', [('Any X,L LIMIT 10 OFFSET 10 WHERE X in_group G, X login L, G name "users", G is EGroup, X is EUser',
   493                     ('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',
   494                                        [{'X': 'EUser', 'L': 'String', 'G': 'EGroup'}])],
   494                                        [{'X': 'CWUser', 'L': 'String', 'G': 'CWGroup'}])],
   495                      10, 10,
   495                      10, 10,
   496                      [self.system], {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])
   496                      [self.system], {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])
   497                     ])
   497                     ])
   498 
   498 
   499     def test_complex_ordered(self):
   499     def test_complex_ordered(self):
   500         self._test('Any L ORDERBY L WHERE X login L',
   500         self._test('Any L ORDERBY L WHERE X login L',
   501                    [('AggrStep', 'Any L ORDERBY L', None, None, 'table0', None, 
   501                    [('AggrStep', 'Any L ORDERBY L', None, None, 'table0', None, 
   502                      [('FetchStep', [('Any L WHERE X login L, X is EUser',
   502                      [('FetchStep', [('Any L WHERE X login L, X is CWUser',
   503                                       [{'X': 'EUser', 'L': 'String'}])],
   503                                       [{'X': 'CWUser', 'L': 'String'}])],
   504                        [self.ldap, self.system], {}, {'X.login': 'table0.C0', 'L': 'table0.C0'}, []),
   504                        [self.ldap, self.system], {}, {'X.login': 'table0.C0', 'L': 'table0.C0'}, []),
   505                       ])
   505                       ])
   506                     ])
   506                     ])
   507 
   507 
   508     def test_complex_ordered_limit_offset(self):
   508     def test_complex_ordered_limit_offset(self):
   509         self._test('Any L ORDERBY L LIMIT 10 OFFSET 10 WHERE X login L',
   509         self._test('Any L ORDERBY L LIMIT 10 OFFSET 10 WHERE X login L',
   510                    [('AggrStep', 'Any L ORDERBY L', 10, 10, 'table0', None, 
   510                    [('AggrStep', 'Any L ORDERBY L', 10, 10, 'table0', None, 
   511                      [('FetchStep', [('Any L WHERE X login L, X is EUser',
   511                      [('FetchStep', [('Any L WHERE X login L, X is CWUser',
   512                                       [{'X': 'EUser', 'L': 'String'}])],
   512                                       [{'X': 'CWUser', 'L': 'String'}])],
   513                        [self.ldap, self.system], {}, {'X.login': 'table0.C0', 'L': 'table0.C0'}, []),
   513                        [self.ldap, self.system], {}, {'X.login': 'table0.C0', 'L': 'table0.C0'}, []),
   514                       ])
   514                       ])
   515                     ])
   515                     ])
   516         
   516         
   517     def test_complex_invariant_ordered(self):
   517     def test_complex_invariant_ordered(self):
   524         herrr, this is what is expected by the XXX :(, not the actual result (which is correct anyway)
   524         herrr, this is what is expected by the XXX :(, not the actual result (which is correct anyway)
   525         """
   525         """
   526         ueid = self.session.user.eid
   526         ueid = self.session.user.eid
   527         self._test('Any X,AA ORDERBY AA WHERE E eid %(x)s, E owned_by X, X modification_date AA',
   527         self._test('Any X,AA ORDERBY AA WHERE E eid %(x)s, E owned_by X, X modification_date AA',
   528                    [('FetchStep',
   528                    [('FetchStep',
   529                      [('Any X,AA WHERE X modification_date AA, X is EUser',
   529                      [('Any X,AA WHERE X modification_date AA, X is CWUser',
   530                        [{'AA': 'Datetime', 'X': 'EUser'}])],
   530                        [{'AA': 'Datetime', 'X': 'CWUser'}])],
   531                      [self.ldap, self.system], None,
   531                      [self.ldap, self.system], None,
   532                      {'AA': 'table0.C1', 'X': 'table0.C0', 'X.modification_date': 'table0.C1'}, []),
   532                      {'AA': 'table0.C1', 'X': 'table0.C0', 'X.modification_date': 'table0.C1'}, []),
   533                     ('OneFetchStep',
   533                     ('OneFetchStep',
   534                      [('Any X,AA ORDERBY AA WHERE 5 owned_by X, X modification_date AA, X is EUser',
   534                      [('Any X,AA ORDERBY AA WHERE 5 owned_by X, X modification_date AA, X is CWUser',
   535                        [{'AA': 'Datetime', 'X': 'EUser'}])],
   535                        [{'AA': 'Datetime', 'X': 'CWUser'}])],
   536                      None, None, [self.system],
   536                      None, None, [self.system],
   537                      {'AA': 'table0.C1', 'X': 'table0.C0', 'X.modification_date': 'table0.C1'}, []),
   537                      {'AA': 'table0.C1', 'X': 'table0.C0', 'X.modification_date': 'table0.C1'}, []),
   538                     ],
   538                     ],
   539                    {'x': ueid})
   539                    {'x': ueid})
   540 
   540 
   545         2. return the result of Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA
   545         2. return the result of Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA
   546            on the system source   
   546            on the system source   
   547         """
   547         """
   548         ueid = self.session.user.eid
   548         ueid = self.session.user.eid
   549         self._test('Any X,L,AA WHERE E eid %(x)s, E owned_by X, X login L, X modification_date AA',
   549         self._test('Any X,L,AA WHERE E eid %(x)s, E owned_by X, X login L, X modification_date AA',
   550                    [('FetchStep', [('Any X,L,AA WHERE X login L, X modification_date AA, X is EUser',
   550                    [('FetchStep', [('Any X,L,AA WHERE X login L, X modification_date AA, X is CWUser',
   551                                     [{'AA': 'Datetime', 'X': 'EUser', 'L': 'String'}])],
   551                                     [{'AA': 'Datetime', 'X': 'CWUser', 'L': 'String'}])],
   552                      [self.ldap, self.system], None,
   552                      [self.ldap, self.system], None,
   553                      {'AA': 'table0.C2', 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2', 'L': 'table0.C1'}, []),
   553                      {'AA': 'table0.C2', 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2', 'L': 'table0.C1'}, []),
   554                     ('OneFetchStep', [('Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA, X is EUser'%ueid,
   554                     ('OneFetchStep', [('Any X,L,AA WHERE %s owned_by X, X login L, X modification_date AA, X is CWUser'%ueid,
   555                                        [{'AA': 'Datetime', 'X': 'EUser', 'L': 'String'}])],
   555                                        [{'AA': 'Datetime', 'X': 'CWUser', 'L': 'String'}])],
   556                      None, None, [self.system],
   556                      None, None, [self.system],
   557                      {'AA': 'table0.C2', 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2', 'L': 'table0.C1'}, [])],
   557                      {'AA': 'table0.C2', 'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2', 'L': 'table0.C1'}, [])],
   558                    {'x': ueid})
   558                    {'x': ueid})
   559 
   559 
   560     def test_complex_ambigous(self):
   560     def test_complex_ambigous(self):
   561         """retrieve EUser X from system and ldap sources, Person X from system source only
   561         """retrieve CWUser X from system and ldap sources, Person X from system source only
   562         """
   562         """
   563         self._test('Any X,F WHERE X firstname F',
   563         self._test('Any X,F WHERE X firstname F',
   564                    [('UnionStep', None, None, [
   564                    [('UnionStep', None, None, [
   565                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is EUser',
   565                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is CWUser',
   566                                           [{'X': 'EUser', 'F': 'String'}])],
   566                                           [{'X': 'CWUser', 'F': 'String'}])],
   567                         None, None, [self.ldap, self.system], {}, []),
   567                         None, None, [self.ldap, self.system], {}, []),
   568                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is Personne',
   568                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is Personne',
   569                                           [{'X': 'Personne', 'F': 'String'}])],
   569                                           [{'X': 'Personne', 'F': 'String'}])],
   570                         None, None, [self.system], {}, []),
   570                         None, None, [self.system], {}, []),
   571                        ]),
   571                        ]),
   572                     ])
   572                     ])
   573 
   573 
   574     def test_complex_ambigous_limit_offset(self):
   574     def test_complex_ambigous_limit_offset(self):
   575         """retrieve EUser X from system and ldap sources, Person X from system source only
   575         """retrieve CWUser X from system and ldap sources, Person X from system source only
   576         """
   576         """
   577         self._test('Any X,F LIMIT 10 OFFSET 10 WHERE X firstname F',
   577         self._test('Any X,F LIMIT 10 OFFSET 10 WHERE X firstname F',
   578                    [('UnionStep', 10, 10, [
   578                    [('UnionStep', 10, 10, [
   579                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is EUser',
   579                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is CWUser',
   580                                           [{'X': 'EUser', 'F': 'String'}])],
   580                                           [{'X': 'CWUser', 'F': 'String'}])],
   581                         None, None,
   581                         None, None,
   582                         [self.ldap, self.system], {}, []),
   582                         [self.ldap, self.system], {}, []),
   583                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is Personne',
   583                        ('OneFetchStep', [('Any X,F WHERE X firstname F, X is Personne',
   584                                           [{'X': 'Personne', 'F': 'String'}])],
   584                                           [{'X': 'Personne', 'F': 'String'}])],
   585                         None, None, [self.system], {}, []),
   585                         None, None, [self.system], {}, []),
   586                        ]),
   586                        ]),
   587                     ])
   587                     ])
   588 
   588 
   589     def test_complex_ambigous_ordered(self):
   589     def test_complex_ambigous_ordered(self):
   590         """
   590         """
   591         1. retrieve EUser X from system and ldap sources, Person X from system source only, store
   591         1. retrieve CWUser X from system and ldap sources, Person X from system source only, store
   592            each result in the same temp table
   592            each result in the same temp table
   593         2. return content of the table sorted
   593         2. return content of the table sorted
   594         """
   594         """
   595         self._test('Any X,F ORDERBY F WHERE X firstname F',
   595         self._test('Any X,F ORDERBY F WHERE X firstname F',
   596                    [('AggrStep', 'Any X,F ORDERBY F', None, None, 'table0', None, 
   596                    [('AggrStep', 'Any X,F ORDERBY F', None, None, 'table0', None, 
   597                      [('FetchStep', [('Any X,F WHERE X firstname F, X is EUser',
   597                      [('FetchStep', [('Any X,F WHERE X firstname F, X is CWUser',
   598                                       [{'X': 'EUser', 'F': 'String'}])],
   598                                       [{'X': 'CWUser', 'F': 'String'}])],
   599                        [self.ldap, self.system], {},
   599                        [self.ldap, self.system], {},
   600                        {'X': 'table0.C0', 'X.firstname': 'table0.C1', 'F': 'table0.C1'}, []),
   600                        {'X': 'table0.C0', 'X.firstname': 'table0.C1', 'F': 'table0.C1'}, []),
   601                       ('FetchStep', [('Any X,F WHERE X firstname F, X is Personne',
   601                       ('FetchStep', [('Any X,F WHERE X firstname F, X is Personne',
   602                                       [{'X': 'Personne', 'F': 'String'}])],
   602                                       [{'X': 'Personne', 'F': 'String'}])],
   603                        [self.system], {},
   603                        [self.system], {},
   613            on the system source   
   613            on the system source   
   614         """
   614         """
   615         ueid = self.session.user.eid
   615         ueid = self.session.user.eid
   616         self._test('Any X,Y WHERE X login "syt", Y login "adim"',
   616         self._test('Any X,Y WHERE X login "syt", Y login "adim"',
   617                    [('FetchStep',
   617                    [('FetchStep',
   618                      [('Any X WHERE X login "syt", X is EUser', [{'X': 'EUser'}])],
   618                      [('Any X WHERE X login "syt", X is CWUser', [{'X': 'CWUser'}])],
   619                      [self.ldap, self.system], None,
   619                      [self.ldap, self.system], None,
   620                      {'X': 'table0.C0'}, []),
   620                      {'X': 'table0.C0'}, []),
   621                     ('FetchStep',
   621                     ('FetchStep',
   622                      [('Any Y WHERE Y login "adim", Y is EUser', [{'Y': 'EUser'}])],
   622                      [('Any Y WHERE Y login "adim", Y is CWUser', [{'Y': 'CWUser'}])],
   623                      [self.ldap, self.system], None,
   623                      [self.ldap, self.system], None,
   624                      {'Y': 'table1.C0'}, []),
   624                      {'Y': 'table1.C0'}, []),
   625                     ('OneFetchStep',
   625                     ('OneFetchStep',
   626                      [('Any X,Y WHERE X is EUser, Y is EUser', [{'X': 'EUser', 'Y': 'EUser'}])],
   626                      [('Any X,Y WHERE X is CWUser, Y is CWUser', [{'X': 'CWUser', 'Y': 'CWUser'}])],
   627                      None, None, [self.system],
   627                      None, None, [self.system],
   628                      {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
   628                      {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
   629                     ], {'x': ueid})
   629                     ], {'x': ueid})
   630         
   630         
   631     def test_complex_multiple_limit_offset(self):
   631     def test_complex_multiple_limit_offset(self):
   636            on the system source   
   636            on the system source   
   637         """
   637         """
   638         ueid = self.session.user.eid
   638         ueid = self.session.user.eid
   639         self._test('Any X,Y LIMIT 10 OFFSET 10 WHERE X login "syt", Y login "adim"',
   639         self._test('Any X,Y LIMIT 10 OFFSET 10 WHERE X login "syt", Y login "adim"',
   640                    [('FetchStep',
   640                    [('FetchStep',
   641                      [('Any X WHERE X login "syt", X is EUser', [{'X': 'EUser'}])],
   641                      [('Any X WHERE X login "syt", X is CWUser', [{'X': 'CWUser'}])],
   642                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
   642                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
   643                     ('FetchStep',
   643                     ('FetchStep',
   644                      [('Any Y WHERE Y login "adim", Y is EUser', [{'Y': 'EUser'}])],
   644                      [('Any Y WHERE Y login "adim", Y is CWUser', [{'Y': 'CWUser'}])],
   645                      [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
   645                      [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
   646                     ('OneFetchStep',
   646                     ('OneFetchStep',
   647                      [('Any X,Y LIMIT 10 OFFSET 10 WHERE X is EUser, Y is EUser', [{'X': 'EUser', 'Y': 'EUser'}])],
   647                      [('Any X,Y LIMIT 10 OFFSET 10 WHERE X is CWUser, Y is CWUser', [{'X': 'CWUser', 'Y': 'CWUser'}])],
   648                      10, 10, [self.system],
   648                      10, 10, [self.system],
   649                      {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
   649                      {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
   650                     ], {'x': ueid})
   650                     ], {'x': ueid})
   651         
   651         
   652     def test_complex_aggregat(self):
   652     def test_complex_aggregat(self):
   681         
   681         
   682     def test_complex_optional(self):
   682     def test_complex_optional(self):
   683         ueid = self.session.user.eid
   683         ueid = self.session.user.eid
   684         self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS',
   684         self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS',
   685                    [('OneFetchStep', [('Any U WHERE WF wf_info_for 5, WF owned_by U?, WF from_state FS',
   685                    [('OneFetchStep', [('Any U WHERE WF wf_info_for 5, WF owned_by U?, WF from_state FS',
   686                                        [{'WF': 'TrInfo', 'FS': 'State', 'U': 'EUser'}])],
   686                                        [{'WF': 'TrInfo', 'FS': 'State', 'U': 'CWUser'}])],
   687                      None, None, [self.system], {}, [])],
   687                      None, None, [self.system], {}, [])],
   688                    {'x': ueid})
   688                    {'x': ueid})
   689 
   689 
   690     def test_complex_optional(self):
   690     def test_complex_optional(self):
   691         ueid = self.session.user.eid
   691         ueid = self.session.user.eid
   692         self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS',
   692         self._test('Any U WHERE WF wf_info_for X, X eid %(x)s, WF owned_by U?, WF from_state FS',
   693                    [('OneFetchStep', [('Any U WHERE WF wf_info_for 5, WF owned_by U?, WF from_state FS',
   693                    [('OneFetchStep', [('Any U WHERE WF wf_info_for 5, WF owned_by U?, WF from_state FS',
   694                                        [{'WF': 'TrInfo', 'FS': 'State', 'U': 'EUser'}])],
   694                                        [{'WF': 'TrInfo', 'FS': 'State', 'U': 'CWUser'}])],
   695                      None, None, [self.system], {}, [])],
   695                      None, None, [self.system], {}, [])],
   696                    {'x': ueid})
   696                    {'x': ueid})
   697 
   697 
   698     
   698     
   699     def test_3sources_ambigous(self):
   699     def test_3sources_ambigous(self):
   700         self._test('Any X,T WHERE X owned_by U, U login "syt", X title T',
   700         self._test('Any X,T WHERE X owned_by U, U login "syt", X title T',
   701                    [('FetchStep', [('Any X,T WHERE X title T, X is Card', [{'X': 'Card', 'T': 'String'}])],
   701                    [('FetchStep', [('Any X,T WHERE X title T, X is Card', [{'X': 'Card', 'T': 'String'}])],
   702                      [self.rql, self.system], None,
   702                      [self.rql, self.system], None,
   703                      {'T': 'table0.C1', 'X': 'table0.C0', 'X.title': 'table0.C1'}, []),
   703                      {'T': 'table0.C1', 'X': 'table0.C0', 'X.title': 'table0.C1'}, []),
   704                     ('FetchStep', [('Any U WHERE U login "syt", U is EUser', [{'U': 'EUser'}])],
   704                     ('FetchStep', [('Any U WHERE U login "syt", U is CWUser', [{'U': 'CWUser'}])],
   705                      [self.ldap, self.system], None,
   705                      [self.ldap, self.system], None,
   706                      {'U': 'table1.C0'}, []),
   706                      {'U': 'table1.C0'}, []),
   707                     ('UnionStep', None, None, [
   707                     ('UnionStep', None, None, [
   708                         ('OneFetchStep', [('Any X,T WHERE X owned_by U, X title T, U is EUser, X is IN(Bookmark, EmailThread)',
   708                         ('OneFetchStep', [('Any X,T WHERE X owned_by U, X title T, U is CWUser, X is IN(Bookmark, EmailThread)',
   709                                            [{'T': 'String', 'U': 'EUser', 'X': 'Bookmark'},
   709                                            [{'T': 'String', 'U': 'CWUser', 'X': 'Bookmark'},
   710                                             {'T': 'String', 'U': 'EUser', 'X': 'EmailThread'}])],
   710                                             {'T': 'String', 'U': 'CWUser', 'X': 'EmailThread'}])],
   711                          None, None, [self.system], {'U': 'table1.C0'}, []),
   711                          None, None, [self.system], {'U': 'table1.C0'}, []),
   712                         ('OneFetchStep', [('Any X,T WHERE X owned_by U, X title T, U is EUser, X is Card',
   712                         ('OneFetchStep', [('Any X,T WHERE X owned_by U, X title T, U is CWUser, X is Card',
   713                                            [{'X': 'Card', 'U': 'EUser', 'T': 'String'}])],
   713                                            [{'X': 'Card', 'U': 'CWUser', 'T': 'String'}])],
   714                          None, None, [self.system],
   714                          None, None, [self.system],
   715                          {'X': 'table0.C0', 'X.title': 'table0.C1', 'T': 'table0.C1', 'U': 'table1.C0'}, []),
   715                          {'X': 'table0.C0', 'X.title': 'table0.C1', 'T': 'table0.C1', 'U': 'table1.C0'}, []),
   716                         ]),
   716                         ]),
   717                     ])
   717                     ])
   718 
   718 
   747 
   747 
   748     def test_not_identity(self):
   748     def test_not_identity(self):
   749         # both system and rql support all variables, can be 
   749         # both system and rql support all variables, can be 
   750         self._test('Any X WHERE NOT X identity U, U eid %s' % self.session.user.eid,
   750         self._test('Any X WHERE NOT X identity U, U eid %s' % self.session.user.eid,
   751                    [('OneFetchStep',
   751                    [('OneFetchStep',
   752                      [('Any X WHERE NOT X identity 5, X is EUser', [{'X': 'EUser'}])],
   752                      [('Any X WHERE NOT X identity 5, X is CWUser', [{'X': 'CWUser'}])],
   753                      None, None,
   753                      None, None,
   754                      [self.ldap, self.system], {}, [])
   754                      [self.ldap, self.system], {}, [])
   755                     ])
   755                     ])
   756 
   756 
   757     def test_outer_supported_rel2(self):
   757     def test_outer_supported_rel2(self):
   759                    'NOT EXISTS(Y is Note, Y in_state S, Y type R)',
   759                    'NOT EXISTS(Y is Note, Y in_state S, Y type R)',
   760                    [('FetchStep', [('Any A,R WHERE Y in_state A, Y type R, A is State, Y is Note',
   760                    [('FetchStep', [('Any A,R WHERE Y in_state A, Y type R, A is State, Y is Note',
   761                                     [{'Y': 'Note', 'A': 'State', 'R': 'String'}])],
   761                                     [{'Y': 'Note', 'A': 'State', 'R': 'String'}])],
   762                      [self.rql, self.system], None,
   762                      [self.rql, self.system], None,
   763                      {'A': 'table0.C0', 'R': 'table0.C1', 'Y.type': 'table0.C1'}, []),
   763                      {'A': 'table0.C0', 'R': 'table0.C1', 'Y.type': 'table0.C1'}, []),
   764                     ('FetchStep', [('Any X,R WHERE X login R, X is EUser', [{'X': 'EUser', 'R': 'String'}])],
   764                     ('FetchStep', [('Any X,R WHERE X login R, X is CWUser', [{'X': 'CWUser', 'R': 'String'}])],
   765                      [self.ldap, self.system], None,
   765                      [self.ldap, self.system], None,
   766                      {'X': 'table1.C0', 'X.login': 'table1.C1', 'R': 'table1.C1'}, []),
   766                      {'X': 'table1.C0', 'X.login': 'table1.C1', 'R': 'table1.C1'}, []),
   767                     ('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 EUser',
   767                     ('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',
   768                                        [{'Y': 'Note', 'X': 'EUser', 'S': 'State', 'R': 'String', 'A': 'State'}])],
   768                                        [{'Y': 'Note', 'X': 'CWUser', 'S': 'State', 'R': 'String', 'A': 'State'}])],
   769                      None, None, [self.system],
   769                      None, None, [self.system],
   770                      {'A': 'table0.C0', 'X': 'table1.C0', 'X.login': 'table1.C1', 'R': 'table1.C1', 'Y.type': 'table0.C1'}, [])
   770                      {'A': 'table0.C0', 'X': 'table1.C0', 'X.login': 'table1.C1', 'R': 'table1.C1', 'Y.type': 'table0.C1'}, [])
   771                     ])
   771                     ])
   772             
   772             
   773     def test_security_has_text(self):
   773     def test_security_has_text(self):
   782                          [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
   782                          [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
   783                        None, None, [self.system], {'E': 'table0.C0'}, []),
   783                        None, None, [self.system], {'E': 'table0.C0'}, []),
   784                       ('OneFetchStep',
   784                       ('OneFetchStep',
   785                        [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is Basket',
   785                        [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is Basket',
   786                          [{'X': 'Basket'}]),
   786                          [{'X': 'Basket'}]),
   787                         ('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is EUser',
   787                         ('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser',
   788                          [{'X': 'EUser'}]),
   788                          [{'X': 'CWUser'}]),
   789                         ('Any X WHERE X has_text "bla", X is IN(Card, Comment, Division, Email, EmailThread, File, Folder, Image, Note, Personne, Societe, State, SubDivision, Tag, Transition)',
   789                         ('Any X WHERE X has_text "bla", X is IN(Card, Comment, Division, Email, EmailThread, File, Folder, Image, Note, Personne, Societe, State, SubDivision, Tag, Transition)',
   790                          [{'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
   790                          [{'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
   791                           {'X': 'Email'}, {'X': 'EmailThread'}, {'X': 'File'},
   791                           {'X': 'Email'}, {'X': 'EmailThread'}, {'X': 'File'},
   792                           {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Note'},
   792                           {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Note'},
   793                           {'X': 'Personne'}, {'X': 'Societe'}, {'X': 'State'},
   793                           {'X': 'Personne'}, {'X': 'Societe'}, {'X': 'State'},
   808                                             [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
   808                                             [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
   809                           [self.system], {'E': 'table1.C0'}, {'X': 'table0.C0'}, []),
   809                           [self.system], {'E': 'table1.C0'}, {'X': 'table0.C0'}, []),
   810                          ('FetchStep',
   810                          ('FetchStep',
   811                           [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is Basket',
   811                           [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is Basket',
   812                          [{'X': 'Basket'}]),
   812                          [{'X': 'Basket'}]),
   813                         ('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is EUser',
   813                         ('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser',
   814                          [{'X': 'EUser'}]),
   814                          [{'X': 'CWUser'}]),
   815                         ('Any X WHERE X has_text "bla", X is IN(Card, Comment, Division, Email, EmailThread, File, Folder, Image, Note, Personne, Societe, State, SubDivision, Tag, Transition)',
   815                         ('Any X WHERE X has_text "bla", X is IN(Card, Comment, Division, Email, EmailThread, File, Folder, Image, Note, Personne, Societe, State, SubDivision, Tag, Transition)',
   816                          [{'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
   816                          [{'X': 'Card'}, {'X': 'Comment'}, {'X': 'Division'},
   817                           {'X': 'Email'}, {'X': 'EmailThread'}, {'X': 'File'},
   817                           {'X': 'Email'}, {'X': 'EmailThread'}, {'X': 'File'},
   818                           {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Note'},
   818                           {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Note'},
   819                           {'X': 'Personne'}, {'X': 'Societe'}, {'X': 'State'},
   819                           {'X': 'Personne'}, {'X': 'Societe'}, {'X': 'State'},
   821                           [self.system], {}, {'X': 'table0.C0'}, []),
   821                           [self.system], {}, {'X': 'table0.C0'}, []),
   822                          ]),
   822                          ]),
   823                     ('OneFetchStep',
   823                     ('OneFetchStep',
   824                      [('Any X LIMIT 10 OFFSET 10',
   824                      [('Any X LIMIT 10 OFFSET 10',
   825                        [{'X': 'Affaire'}, {'X': 'Basket'}, {'X': 'Card'},
   825                        [{'X': 'Affaire'}, {'X': 'Basket'}, {'X': 'Card'},
   826                         {'X': 'Comment'}, {'X': 'Division'}, {'X': 'EUser'},
   826                         {'X': 'Comment'}, {'X': 'Division'}, {'X': 'CWUser'},
   827                         {'X': 'Email'}, {'X': 'EmailThread'}, {'X': 'File'},
   827                         {'X': 'Email'}, {'X': 'EmailThread'}, {'X': 'File'},
   828                         {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Note'},
   828                         {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Note'},
   829                         {'X': 'Personne'}, {'X': 'Societe'}, {'X': 'State'},
   829                         {'X': 'Personne'}, {'X': 'Societe'}, {'X': 'State'},
   830                         {'X': 'SubDivision'}, {'X': 'Tag'}, {'X': 'Transition'}])],
   830                         {'X': 'SubDivision'}, {'X': 'Tag'}, {'X': 'Transition'}])],
   831                      10, 10, [self.system], {'X': 'table0.C0'}, [])                    
   831                      10, 10, [self.system], {'X': 'table0.C0'}, [])                    
   835         """a guest user trying to see another user: EXISTS(X owned_by U) is automatically inserted"""
   835         """a guest user trying to see another user: EXISTS(X owned_by U) is automatically inserted"""
   836         # use a guest user
   836         # use a guest user
   837         self.session = self._user_session()[1]
   837         self.session = self._user_session()[1]
   838         self._test('Any X WHERE X login "bla"',
   838         self._test('Any X WHERE X login "bla"',
   839                    [('FetchStep',
   839                    [('FetchStep',
   840                      [('Any X WHERE X login "bla", X is EUser', [{'X': 'EUser'}])],
   840                      [('Any X WHERE X login "bla", X is CWUser', [{'X': 'CWUser'}])],
   841                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
   841                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
   842                     ('OneFetchStep',
   842                     ('OneFetchStep',
   843                      [('Any X WHERE EXISTS(X owned_by 5), X is EUser', [{'X': 'EUser'}])],
   843                      [('Any X WHERE EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
   844                      None, None, [self.system], {'X': 'table0.C0'}, [])])
   844                      None, None, [self.system], {'X': 'table0.C0'}, [])])
   845                 
   845                 
   846     def test_security_complex_has_text(self):
   846     def test_security_complex_has_text(self):
   847         # use a guest user
   847         # use a guest user
   848         self.session = self._user_session()[1]
   848         self.session = self._user_session()[1]
   849         self._test('Any X WHERE X has_text "bla", X firstname "bla"',
   849         self._test('Any X WHERE X has_text "bla", X firstname "bla"',
   850                    [('FetchStep', [('Any X WHERE X firstname "bla", X is EUser', [{'X': 'EUser'}])],
   850                    [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
   851                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
   851                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
   852                     ('UnionStep', None, None, [
   852                     ('UnionStep', None, None, [
   853                         ('OneFetchStep', [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is EUser', [{'X': 'EUser'}])],
   853                         ('OneFetchStep', [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
   854                          None, None, [self.system], {'X': 'table0.C0'}, []),
   854                          None, None, [self.system], {'X': 'table0.C0'}, []),
   855                         ('OneFetchStep', [('Any X WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
   855                         ('OneFetchStep', [('Any X WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
   856                          None, None, [self.system], {}, []),
   856                          None, None, [self.system], {}, []),
   857                         ]),
   857                         ]),
   858                     ])
   858                     ])
   859 
   859 
   860     def test_security_complex_has_text_limit_offset(self):
   860     def test_security_complex_has_text_limit_offset(self):
   861         # use a guest user
   861         # use a guest user
   862         self.session = self._user_session()[1]
   862         self.session = self._user_session()[1]
   863         self._test('Any X LIMIT 10 OFFSET 10 WHERE X has_text "bla", X firstname "bla"',
   863         self._test('Any X LIMIT 10 OFFSET 10 WHERE X has_text "bla", X firstname "bla"',
   864                    [('FetchStep', [('Any X WHERE X firstname "bla", X is EUser', [{'X': 'EUser'}])],
   864                    [('FetchStep', [('Any X WHERE X firstname "bla", X is CWUser', [{'X': 'CWUser'}])],
   865                      [self.ldap, self.system], None, {'X': 'table1.C0'}, []),
   865                      [self.ldap, self.system], None, {'X': 'table1.C0'}, []),
   866                     ('UnionFetchStep', [
   866                     ('UnionFetchStep', [
   867                         ('FetchStep', [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is EUser', [{'X': 'EUser'}])],
   867                         ('FetchStep', [('Any X WHERE X has_text "bla", EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
   868                          [self.system], {'X': 'table1.C0'}, {'X': 'table0.C0'}, []),
   868                          [self.system], {'X': 'table1.C0'}, {'X': 'table0.C0'}, []),
   869                         ('FetchStep', [('Any X WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
   869                         ('FetchStep', [('Any X WHERE X has_text "bla", X firstname "bla", X is Personne', [{'X': 'Personne'}])],
   870                          [self.system], {}, {'X': 'table0.C0'}, []),
   870                          [self.system], {}, {'X': 'table0.C0'}, []),
   871                         ]),
   871                         ]),
   872                      ('OneFetchStep',
   872                      ('OneFetchStep',
   873                       [('Any X LIMIT 10 OFFSET 10', [{'X': 'EUser'}, {'X': 'Personne'}])],
   873                       [('Any X LIMIT 10 OFFSET 10', [{'X': 'CWUser'}, {'X': 'Personne'}])],
   874                       10, 10, [self.system], {'X': 'table0.C0'}, [])
   874                       10, 10, [self.system], {'X': 'table0.C0'}, [])
   875                     ])
   875                     ])
   876 
   876 
   877     def test_security_complex_aggregat(self):
   877     def test_security_complex_aggregat(self):
   878         # use a guest user
   878         # use a guest user
   879         self.session = self._user_session()[1]
   879         self.session = self._user_session()[1]
   880         self._test('Any MAX(X)',
   880         self._test('Any MAX(X)',
   881                    [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
   881                    [('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
   882                      [self.rql, self.system],  None, {'E': 'table1.C0'}, []), 
   882                      [self.rql, self.system],  None, {'E': 'table1.C0'}, []), 
   883                     ('FetchStep', [('Any X WHERE X is EUser', [{'X': 'EUser'}])],
   883                     ('FetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
   884                      [self.ldap, self.system], None, {'X': 'table2.C0'}, []),
   884                      [self.ldap, self.system], None, {'X': 'table2.C0'}, []),
   885                     ('UnionFetchStep', [
   885                     ('UnionFetchStep', [
   886                         ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is Basket', [{'X': 'Basket'}])],
   886                         ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is Basket', [{'X': 'Basket'}])],
   887                           [self.system], {}, {'X': 'table0.C0'}, []),                        
   887                           [self.system], {}, {'X': 'table0.C0'}, []),                        
   888                         ('UnionFetchStep',
   888                         ('UnionFetchStep',
   889                          [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
   889                          [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
   890                                           [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
   890                                           [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
   891                            [self.rql, self.system], {}, {'X': 'table0.C0'}, []),
   891                            [self.rql, self.system], {}, {'X': 'table0.C0'}, []),
   892                           ('FetchStep',
   892                           ('FetchStep',
   893                            [('Any X WHERE X is IN(Bookmark, Comment, Division, ECache, EConstraint, EConstraintType, EEType, EFRDef, EGroup, ENFRDef, EPermission, EProperty, ERType, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
   893                            [('Any X WHERE X is IN(Bookmark, Comment, Division, CWCache, CWConstraint, CWConstraintType, CWEType, CWAttribute, CWGroup, CWRelation, CWPermission, CWProperty, CWRType, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
   894                              sorted([{'X': 'Bookmark'}, {'X': 'Comment'}, {'X': 'Division'},
   894                              sorted([{'X': 'Bookmark'}, {'X': 'Comment'}, {'X': 'Division'},
   895                                       {'X': 'ECache'}, {'X': 'EConstraint'}, {'X': 'EConstraintType'},
   895                                       {'X': 'CWCache'}, {'X': 'CWConstraint'}, {'X': 'CWConstraintType'},
   896                                       {'X': 'EEType'}, {'X': 'EFRDef'}, {'X': 'EGroup'},
   896                                       {'X': 'CWEType'}, {'X': 'CWAttribute'}, {'X': 'CWGroup'},
   897                                       {'X': 'ENFRDef'}, {'X': 'EPermission'}, {'X': 'EProperty'},
   897                                       {'X': 'CWRelation'}, {'X': 'CWPermission'}, {'X': 'CWProperty'},
   898                                       {'X': 'ERType'}, {'X': 'Email'}, {'X': 'EmailAddress'},
   898                                       {'X': 'CWRType'}, {'X': 'Email'}, {'X': 'EmailAddress'},
   899                                       {'X': 'EmailPart'}, {'X': 'EmailThread'}, {'X': 'File'},
   899                                       {'X': 'EmailPart'}, {'X': 'EmailThread'}, {'X': 'File'},
   900                                       {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Personne'},
   900                                       {'X': 'Folder'}, {'X': 'Image'}, {'X': 'Personne'},
   901                                       {'X': 'RQLExpression'}, {'X': 'Societe'}, {'X': 'SubDivision'},
   901                                       {'X': 'RQLExpression'}, {'X': 'Societe'}, {'X': 'SubDivision'},
   902                                       {'X': 'Tag'}, {'X': 'TrInfo'}, {'X': 'Transition'}]))],
   902                                       {'X': 'Tag'}, {'X': 'TrInfo'}, {'X': 'Transition'}]))],
   903                            [self.system], {}, {'X': 'table0.C0'}, []),
   903                            [self.system], {}, {'X': 'table0.C0'}, []),
   904                           ]),
   904                           ]),
   905                         ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is EUser', [{'X': 'EUser'}])],
   905                         ('FetchStep', [('Any X WHERE EXISTS(X owned_by 5), X is CWUser', [{'X': 'CWUser'}])],
   906                          [self.system], {'X': 'table2.C0'}, {'X': 'table0.C0'}, []),
   906                          [self.system], {'X': 'table2.C0'}, {'X': 'table0.C0'}, []),
   907                         ('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',
   907                         ('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',
   908                                         [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
   908                                         [{'C': 'Division', 'E': 'Note', 'D': 'Affaire', 'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire', 'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire'}])],
   909                          [self.system], {'E': 'table1.C0'}, {'X': 'table0.C0'}, []),                        
   909                          [self.system], {'E': 'table1.C0'}, {'X': 'table0.C0'}, []),                        
   910                         ]),
   910                         ]),
   919                    [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
   919                    [('FetchStep', [('Any X WHERE X is IN(Card, Note, State)',
   920                                     [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
   920                                     [{'X': 'Card'}, {'X': 'Note'}, {'X': 'State'}])],
   921                      [self.rql, self.system], None, {'X': 'table1.C0'}, []),
   921                      [self.rql, self.system], None, {'X': 'table1.C0'}, []),
   922                     ('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
   922                     ('FetchStep', [('Any E WHERE E type "X", E is Note', [{'E': 'Note'}])],
   923                      [self.rql, self.system],  None, {'E': 'table2.C0'}, []),
   923                      [self.rql, self.system],  None, {'E': 'table2.C0'}, []),
   924                     ('FetchStep', [('Any X WHERE X is EUser', [{'X': 'EUser'}])],
   924                     ('FetchStep', [('Any X WHERE X is CWUser', [{'X': 'CWUser'}])],
   925                      [self.ldap, self.system], None, {'X': 'table3.C0'}, []),
   925                      [self.ldap, self.system], None, {'X': 'table3.C0'}, []),
   926                     ('UnionFetchStep',
   926                     ('UnionFetchStep',
   927                      [('FetchStep', [('Any ET,X WHERE X is ET, EXISTS(X owned_by 5), ET is EEType, X is Basket',
   927                      [('FetchStep', [('Any ET,X WHERE X is ET, EXISTS(X owned_by 5), ET is CWEType, X is Basket',
   928                                       [{'ET': 'EEType', 'X': 'Basket'}])],
   928                                       [{'ET': 'CWEType', 'X': 'Basket'}])],
   929                        [self.system], {}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   929                        [self.system], {}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   930                       ('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 EEType, X is Affaire',
   930                       ('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',
   931                                       [{'C': 'Division', 'E': 'Note', 'D': 'Affaire',
   931                                       [{'C': 'Division', 'E': 'Note', 'D': 'Affaire',
   932                                         'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire',
   932                                         'G': 'SubDivision', 'F': 'Societe', 'I': 'Affaire',
   933                                         'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire',
   933                                         'H': 'Affaire', 'J': 'Affaire', 'X': 'Affaire',
   934                                         'ET': 'EEType'}])],
   934                                         'ET': 'CWEType'}])],
   935                        [self.system], {'E': 'table2.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'},
   935                        [self.system], {'E': 'table2.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'},
   936                        []),
   936                        []),
   937                       ('FetchStep', [('Any ET,X WHERE X is ET, EXISTS(X owned_by 5), ET is EEType, X is EUser',
   937                       ('FetchStep', [('Any ET,X WHERE X is ET, EXISTS(X owned_by 5), ET is CWEType, X is CWUser',
   938                                       [{'ET': 'EEType', 'X': 'EUser'}])],
   938                                       [{'ET': 'CWEType', 'X': 'CWUser'}])],
   939                        [self.system], {'X': 'table3.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   939                        [self.system], {'X': 'table3.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   940                       # extra UnionFetchStep could be avoided but has no cost, so don't care
   940                       # extra UnionFetchStep could be avoided but has no cost, so don't care
   941                       ('UnionFetchStep',
   941                       ('UnionFetchStep',
   942                        [('FetchStep', [('Any ET,X WHERE X is ET, ET is EEType, X is IN(Bookmark, Comment, Division, ECache, EConstraint, EConstraintType, EEType, EFRDef, EGroup, ENFRDef, EPermission, EProperty, ERType, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
   942                        [('FetchStep', [('Any ET,X WHERE X is ET, ET is CWEType, X is IN(Bookmark, Comment, Division, CWCache, CWConstraint, CWConstraintType, CWEType, CWAttribute, CWGroup, CWRelation, CWPermission, CWProperty, CWRType, Email, EmailAddress, EmailPart, EmailThread, File, Folder, Image, Personne, RQLExpression, Societe, SubDivision, Tag, TrInfo, Transition)',
   943                                         [{'X': 'Bookmark', 'ET': 'EEType'}, {'X': 'Comment', 'ET': 'EEType'},
   943                                         [{'X': 'Bookmark', 'ET': 'CWEType'}, {'X': 'Comment', 'ET': 'CWEType'},
   944                                          {'X': 'Division', 'ET': 'EEType'}, {'X': 'ECache', 'ET': 'EEType'},
   944                                          {'X': 'Division', 'ET': 'CWEType'}, {'X': 'CWCache', 'ET': 'CWEType'},
   945                                          {'X': 'EConstraint', 'ET': 'EEType'}, {'X': 'EConstraintType', 'ET': 'EEType'},
   945                                          {'X': 'CWConstraint', 'ET': 'CWEType'}, {'X': 'CWConstraintType', 'ET': 'CWEType'},
   946                                          {'X': 'EEType', 'ET': 'EEType'}, {'X': 'EFRDef', 'ET': 'EEType'},
   946                                          {'X': 'CWEType', 'ET': 'CWEType'}, {'X': 'CWAttribute', 'ET': 'CWEType'},
   947                                          {'X': 'EGroup', 'ET': 'EEType'}, {'X': 'ENFRDef', 'ET': 'EEType'},
   947                                          {'X': 'CWGroup', 'ET': 'CWEType'}, {'X': 'CWRelation', 'ET': 'CWEType'},
   948                                          {'X': 'EPermission', 'ET': 'EEType'}, {'X': 'EProperty', 'ET': 'EEType'},
   948                                          {'X': 'CWPermission', 'ET': 'CWEType'}, {'X': 'CWProperty', 'ET': 'CWEType'},
   949                                          {'X': 'ERType', 'ET': 'EEType'}, {'X': 'Email', 'ET': 'EEType'},
   949                                          {'X': 'CWRType', 'ET': 'CWEType'}, {'X': 'Email', 'ET': 'CWEType'},
   950                                          {'X': 'EmailAddress', 'ET': 'EEType'}, {'X': 'EmailPart', 'ET': 'EEType'},
   950                                          {'X': 'EmailAddress', 'ET': 'CWEType'}, {'X': 'EmailPart', 'ET': 'CWEType'},
   951                                          {'X': 'EmailThread', 'ET': 'EEType'}, {'X': 'File', 'ET': 'EEType'},
   951                                          {'X': 'EmailThread', 'ET': 'CWEType'}, {'X': 'File', 'ET': 'CWEType'},
   952                                          {'X': 'Folder', 'ET': 'EEType'}, {'X': 'Image', 'ET': 'EEType'},
   952                                          {'X': 'Folder', 'ET': 'CWEType'}, {'X': 'Image', 'ET': 'CWEType'},
   953                                          {'X': 'Personne', 'ET': 'EEType'}, {'X': 'RQLExpression', 'ET': 'EEType'},
   953                                          {'X': 'Personne', 'ET': 'CWEType'}, {'X': 'RQLExpression', 'ET': 'CWEType'},
   954                                          {'X': 'Societe', 'ET': 'EEType'}, {'X': 'SubDivision', 'ET': 'EEType'},
   954                                          {'X': 'Societe', 'ET': 'CWEType'}, {'X': 'SubDivision', 'ET': 'CWEType'},
   955                                          {'X': 'Tag', 'ET': 'EEType'}, {'X': 'TrInfo', 'ET': 'EEType'},
   955                                          {'X': 'Tag', 'ET': 'CWEType'}, {'X': 'TrInfo', 'ET': 'CWEType'},
   956                                          {'X': 'Transition', 'ET': 'EEType'}])],
   956                                          {'X': 'Transition', 'ET': 'CWEType'}])],
   957                          [self.system], {}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   957                          [self.system], {}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   958                         ('FetchStep',
   958                         ('FetchStep',
   959                          [('Any ET,X WHERE X is ET, ET is EEType, X is IN(Card, Note, State)',
   959                          [('Any ET,X WHERE X is ET, ET is CWEType, X is IN(Card, Note, State)',
   960                            [{'ET': 'EEType', 'X': 'Card'},
   960                            [{'ET': 'CWEType', 'X': 'Card'},
   961                             {'ET': 'EEType', 'X': 'Note'},
   961                             {'ET': 'CWEType', 'X': 'Note'},
   962                             {'ET': 'EEType', 'X': 'State'}])],
   962                             {'ET': 'CWEType', 'X': 'State'}])],
   963                          [self.system], {'X': 'table1.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   963                          [self.system], {'X': 'table1.C0'}, {'ET': 'table0.C0', 'X': 'table0.C1'}, []),
   964                         ]),
   964                         ]),
   965                     ]),
   965                     ]),
   966                     ('OneFetchStep',
   966                     ('OneFetchStep',
   967                      [('Any ET,COUNT(X) GROUPBY ET ORDERBY ET',
   967                      [('Any ET,COUNT(X) GROUPBY ET ORDERBY ET',
   968                        sorted([{'ET': 'EEType', 'X': 'Affaire'}, {'ET': 'EEType', 'X': 'Basket'},
   968                        sorted([{'ET': 'CWEType', 'X': 'Affaire'}, {'ET': 'CWEType', 'X': 'Basket'},
   969                                {'ET': 'EEType', 'X': 'Bookmark'}, {'ET': 'EEType', 'X': 'Card'},
   969                                {'ET': 'CWEType', 'X': 'Bookmark'}, {'ET': 'CWEType', 'X': 'Card'},
   970                                {'ET': 'EEType', 'X': 'Comment'}, {'ET': 'EEType', 'X': 'Division'},
   970                                {'ET': 'CWEType', 'X': 'Comment'}, {'ET': 'CWEType', 'X': 'Division'},
   971                                {'ET': 'EEType', 'X': 'ECache'}, {'ET': 'EEType', 'X': 'EConstraint'},
   971                                {'ET': 'CWEType', 'X': 'CWCache'}, {'ET': 'CWEType', 'X': 'CWConstraint'},
   972                                {'ET': 'EEType', 'X': 'EConstraintType'}, {'ET': 'EEType', 'X': 'EEType'},
   972                                {'ET': 'CWEType', 'X': 'CWConstraintType'}, {'ET': 'CWEType', 'X': 'CWEType'},
   973                                {'ET': 'EEType', 'X': 'EFRDef'}, {'ET': 'EEType', 'X': 'EGroup'},
   973                                {'ET': 'CWEType', 'X': 'CWAttribute'}, {'ET': 'CWEType', 'X': 'CWGroup'},
   974                                {'ET': 'EEType', 'X': 'ENFRDef'}, {'ET': 'EEType', 'X': 'EPermission'},
   974                                {'ET': 'CWEType', 'X': 'CWRelation'}, {'ET': 'CWEType', 'X': 'CWPermission'},
   975                                {'ET': 'EEType', 'X': 'EProperty'}, {'ET': 'EEType', 'X': 'ERType'},
   975                                {'ET': 'CWEType', 'X': 'CWProperty'}, {'ET': 'CWEType', 'X': 'CWRType'},
   976                                {'ET': 'EEType', 'X': 'EUser'}, {'ET': 'EEType', 'X': 'Email'},
   976                                {'ET': 'CWEType', 'X': 'CWUser'}, {'ET': 'CWEType', 'X': 'Email'},
   977                                {'ET': 'EEType', 'X': 'EmailAddress'}, {'ET': 'EEType', 'X': 'EmailPart'},
   977                                {'ET': 'CWEType', 'X': 'EmailAddress'}, {'ET': 'CWEType', 'X': 'EmailPart'},
   978                                {'ET': 'EEType', 'X': 'EmailThread'}, {'ET': 'EEType', 'X': 'File'},
   978                                {'ET': 'CWEType', 'X': 'EmailThread'}, {'ET': 'CWEType', 'X': 'File'},
   979                                {'ET': 'EEType', 'X': 'Folder'}, {'ET': 'EEType', 'X': 'Image'},
   979                                {'ET': 'CWEType', 'X': 'Folder'}, {'ET': 'CWEType', 'X': 'Image'},
   980                                {'ET': 'EEType', 'X': 'Note'}, {'ET': 'EEType', 'X': 'Personne'},
   980                                {'ET': 'CWEType', 'X': 'Note'}, {'ET': 'CWEType', 'X': 'Personne'},
   981                                {'ET': 'EEType', 'X': 'RQLExpression'}, {'ET': 'EEType', 'X': 'Societe'},
   981                                {'ET': 'CWEType', 'X': 'RQLExpression'}, {'ET': 'CWEType', 'X': 'Societe'},
   982                                {'ET': 'EEType', 'X': 'State'}, {'ET': 'EEType', 'X': 'SubDivision'},
   982                                {'ET': 'CWEType', 'X': 'State'}, {'ET': 'CWEType', 'X': 'SubDivision'},
   983                                {'ET': 'EEType', 'X': 'Tag'}, {'ET': 'EEType', 'X': 'TrInfo'},
   983                                {'ET': 'CWEType', 'X': 'Tag'}, {'ET': 'CWEType', 'X': 'TrInfo'},
   984                                {'ET': 'EEType', 'X': 'Transition'}]))],
   984                                {'ET': 'CWEType', 'X': 'Transition'}]))],
   985                      None, None, [self.system], {'ET': 'table0.C0', 'X': 'table0.C1'}, [])
   985                      None, None, [self.system], {'ET': 'table0.C0', 'X': 'table0.C1'}, [])
   986                     ])
   986                     ])
   987 
   987 
   988     def test_security_3sources(self):
   988     def test_security_3sources(self):
   989         # use a guest user
   989         # use a guest user
   991         self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
   991         self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
   992                    [('FetchStep',
   992                    [('FetchStep',
   993                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
   993                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
   994                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
   994                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
   995                     ('FetchStep',
   995                     ('FetchStep',
   996                      [('Any U WHERE U login "syt", U is EUser', [{'U': 'EUser'}])],
   996                      [('Any U WHERE U login "syt", U is CWUser', [{'U': 'CWUser'}])],
   997                      [self.ldap, self.system], None, {'U': 'table1.C0'}, []),
   997                      [self.ldap, self.system], None, {'U': 'table1.C0'}, []),
   998                     ('OneFetchStep',
   998                     ('OneFetchStep',
   999                      [('Any X,XT WHERE X owned_by U, X title XT, EXISTS(U owned_by 5), U is EUser, X is Card',
   999                      [('Any X,XT WHERE X owned_by U, X title XT, EXISTS(U owned_by 5), U is CWUser, X is Card',
  1000                        [{'X': 'Card', 'U': 'EUser', 'XT': 'String'}])],
  1000                        [{'X': 'Card', 'U': 'CWUser', 'XT': 'String'}])],
  1001                      None, None, [self.system],
  1001                      None, None, [self.system],
  1002                      {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1', 'U': 'table1.C0'}, [])
  1002                      {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1', 'U': 'table1.C0'}, [])
  1003                     ])
  1003                     ])
  1004 
  1004 
  1005     def test_security_3sources_identity(self):
  1005     def test_security_3sources_identity(self):
  1009         self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
  1009         self._test('Any X, XT WHERE X is Card, X owned_by U, X title XT, U login "syt"',
  1010                    [('FetchStep',
  1010                    [('FetchStep',
  1011                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
  1011                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
  1012                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
  1012                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
  1013                     ('OneFetchStep',
  1013                     ('OneFetchStep',
  1014                      [('Any X,XT WHERE X owned_by U, X title XT, U login "syt", EXISTS(U identity 5), U is EUser, X is Card',
  1014                      [('Any X,XT WHERE X owned_by U, X title XT, U login "syt", EXISTS(U identity 5), U is CWUser, X is Card',
  1015                        [{'U': 'EUser', 'X': 'Card', 'XT': 'String'}])],
  1015                        [{'U': 'CWUser', 'X': 'Card', 'XT': 'String'}])],
  1016                      None, None, [self.system], {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, [])
  1016                      None, None, [self.system], {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, [])
  1017                     ])
  1017                     ])
  1018 
  1018 
  1019     def test_security_3sources_identity_optional_var(self):
  1019     def test_security_3sources_identity_optional_var(self):
  1020         self.restore_orig_euser_security()
  1020         self.restore_orig_euser_security()
  1021         # use a guest user
  1021         # use a guest user
  1022         self.session = self._user_session()[1]
  1022         self.session = self._user_session()[1]
  1023         self._test('Any X,XT,U WHERE X is Card, X owned_by U?, X title XT, U login L',
  1023         self._test('Any X,XT,U WHERE X is Card, X owned_by U?, X title XT, U login L',
  1024                    [('FetchStep',
  1024                    [('FetchStep',
  1025                      [('Any U,L WHERE U identity 5, U login L, U is EUser',
  1025                      [('Any U,L WHERE U identity 5, U login L, U is CWUser',
  1026                        [{'L': 'String', u'U': 'EUser'}])],
  1026                        [{'L': 'String', u'U': 'CWUser'}])],
  1027                      [self.system], {}, {'L': 'table0.C1', 'U': 'table0.C0', 'U.login': 'table0.C1'}, []),
  1027                      [self.system], {}, {'L': 'table0.C1', 'U': 'table0.C0', 'U.login': 'table0.C1'}, []),
  1028                     ('FetchStep',
  1028                     ('FetchStep',
  1029                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
  1029                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
  1030                      [self.rql, self.system], None, {'X': 'table1.C0', 'X.title': 'table1.C1', 'XT': 'table1.C1'}, []),
  1030                      [self.rql, self.system], None, {'X': 'table1.C0', 'X.title': 'table1.C1', 'XT': 'table1.C1'}, []),
  1031                     ('OneFetchStep',
  1031                     ('OneFetchStep',
  1044         self._test('Any X, XT LIMIT 10 OFFSET 10 WHERE X is Card, X owned_by U, X title XT, U login "syt"',
  1044         self._test('Any X, XT LIMIT 10 OFFSET 10 WHERE X is Card, X owned_by U, X title XT, U login "syt"',
  1045                    [('FetchStep',
  1045                    [('FetchStep',
  1046                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
  1046                      [('Any X,XT WHERE X title XT, X is Card', [{'X': 'Card', 'XT': 'String'}])],
  1047                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
  1047                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1'}, []),
  1048                     ('FetchStep',
  1048                     ('FetchStep',
  1049                      [('Any U WHERE U login "syt", U is EUser', [{'U': 'EUser'}])],
  1049                      [('Any U WHERE U login "syt", U is CWUser', [{'U': 'CWUser'}])],
  1050                      [self.ldap, self.system], None, {'U': 'table1.C0'}, []),
  1050                      [self.ldap, self.system], None, {'U': 'table1.C0'}, []),
  1051                     ('OneFetchStep',
  1051                     ('OneFetchStep',
  1052                      [('Any X,XT LIMIT 10 OFFSET 10 WHERE X owned_by U, X title XT, EXISTS(U owned_by 5), U is EUser, X is Card',
  1052                      [('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',
  1053                        [{'X': 'Card', 'U': 'EUser', 'XT': 'String'}])],
  1053                        [{'X': 'Card', 'U': 'CWUser', 'XT': 'String'}])],
  1054                      10, 10, [self.system],
  1054                      10, 10, [self.system],
  1055                      {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1', 'U': 'table1.C0'}, [])
  1055                      {'X': 'table0.C0', 'X.title': 'table0.C1', 'XT': 'table0.C1', 'U': 'table1.C0'}, [])
  1056                     ])
  1056                     ])
  1057     
  1057     
  1058     def test_exists_base(self):
  1058     def test_exists_base(self):
  1059         self._test('Any X,L,S WHERE X in_state S, X login L, EXISTS(X in_group G, G name "bougloup")',
  1059         self._test('Any X,L,S WHERE X in_state S, X login L, EXISTS(X in_group G, G name "bougloup")',
  1060                    [('FetchStep', [('Any X,L WHERE X login L, X is EUser', [{'X': 'EUser', 'L': 'String'}])],
  1060                    [('FetchStep', [('Any X,L WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
  1061                      [self.ldap, self.system], None, {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
  1061                      [self.ldap, self.system], None, {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, []),
  1062                     ('OneFetchStep', [("Any X,L,S WHERE X in_state S, X login L, "
  1062                     ('OneFetchStep', [("Any X,L,S WHERE X in_state S, X login L, "
  1063                                       'EXISTS(X in_group G, G name "bougloup", G is EGroup), S is State, X is EUser',
  1063                                       'EXISTS(X in_group G, G name "bougloup", G is CWGroup), S is State, X is CWUser',
  1064                                        [{'X': 'EUser', 'L': 'String', 'S': 'State', 'G': 'EGroup'}])],
  1064                                        [{'X': 'CWUser', 'L': 'String', 'S': 'State', 'G': 'CWGroup'}])],
  1065                      None, None, [self.system],
  1065                      None, None, [self.system],
  1066                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])])
  1066                      {'X': 'table0.C0', 'X.login': 'table0.C1', 'L': 'table0.C1'}, [])])
  1067 
  1067 
  1068     def test_exists_complex(self):
  1068     def test_exists_complex(self):
  1069         self._test('Any G WHERE X in_group G, G name "managers", EXISTS(X copain T, T login in ("comme", "cochon"))',
  1069         self._test('Any G WHERE X in_group G, G name "managers", EXISTS(X copain T, T login in ("comme", "cochon"))',
  1070                    [('FetchStep', [('Any T WHERE T login IN("comme", "cochon"), T is EUser', [{'T': 'EUser'}])],
  1070                    [('FetchStep', [('Any T WHERE T login IN("comme", "cochon"), T is CWUser', [{'T': 'CWUser'}])],
  1071                      [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
  1071                      [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
  1072                     ('OneFetchStep',
  1072                     ('OneFetchStep',
  1073                      [('Any G WHERE X in_group G, G name "managers", EXISTS(X copain T, T is EUser), G is EGroup, X is EUser',
  1073                      [('Any G WHERE X in_group G, G name "managers", EXISTS(X copain T, T is CWUser), G is CWGroup, X is CWUser',
  1074                        [{'X': 'EUser', 'T': 'EUser', 'G': 'EGroup'}])],
  1074                        [{'X': 'CWUser', 'T': 'CWUser', 'G': 'CWGroup'}])],
  1075                      None, None, [self.system], {'T': 'table0.C0'}, [])])
  1075                      None, None, [self.system], {'T': 'table0.C0'}, [])])
  1076 
  1076 
  1077     def test_exists3(self):
  1077     def test_exists3(self):
  1078         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"))',
  1078         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"))',
  1079                    [('FetchStep',
  1079                    [('FetchStep',
  1080                      [('Any T WHERE T login IN("comme", "cochon"), T is EUser',
  1080                      [('Any T WHERE T login IN("comme", "cochon"), T is CWUser',
  1081                        [{'T': 'EUser'}])],
  1081                        [{'T': 'CWUser'}])],
  1082                      [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
  1082                      [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
  1083                     ('FetchStep',
  1083                     ('FetchStep',
  1084                      [('Any L,X WHERE X login L, X is EUser', [{'X': 'EUser', 'L': 'String'}])],
  1084                      [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
  1085                      [self.ldap, self.system], None,
  1085                      [self.ldap, self.system], None,
  1086                      {'X': 'table1.C1', 'X.login': 'table1.C0', 'L': 'table1.C0'}, []),
  1086                      {'X': 'table1.C1', 'X.login': 'table1.C0', 'L': 'table1.C0'}, []),
  1087                     ('OneFetchStep',
  1087                     ('OneFetchStep',
  1088                      [('Any G,L WHERE X in_group G, X login L, G name "managers", EXISTS(X copain T, T is EUser), G is EGroup, X is EUser',
  1088                      [('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',
  1089                        [{'G': 'EGroup', 'L': 'String', 'T': 'EUser', 'X': 'EUser'}])],
  1089                        [{'G': 'CWGroup', 'L': 'String', 'T': 'CWUser', 'X': 'CWUser'}])],
  1090                      None, None,
  1090                      None, None,
  1091                      [self.system], {'T': 'table0.C0', 'X': 'table1.C1', 'X.login': 'table1.C0', 'L': 'table1.C0'}, [])])
  1091                      [self.system], {'T': 'table0.C0', 'X': 'table1.C1', 'X.login': 'table1.C0', 'L': 'table1.C0'}, [])])
  1092 
  1092 
  1093     def test_exists4(self):
  1093     def test_exists4(self):
  1094         self._test('Any G,L WHERE X in_group G, X login L, G name "managers", '
  1094         self._test('Any G,L WHERE X in_group G, X login L, G name "managers", '
  1095                    'EXISTS(X copain T, T login L, T login in ("comme", "cochon")) OR '
  1095                    'EXISTS(X copain T, T login L, T login in ("comme", "cochon")) OR '
  1096                    'EXISTS(X in_state S, S name "pascontent", NOT X copain T2, T2 login "billy")',
  1096                    'EXISTS(X in_state S, S name "pascontent", NOT X copain T2, T2 login "billy")',
  1097                    [('FetchStep',
  1097                    [('FetchStep',
  1098                      [('Any T,L WHERE T login L, T login IN("comme", "cochon"), T is EUser', [{'T': 'EUser', 'L': 'String'}])],
  1098                      [('Any T,L WHERE T login L, T login IN("comme", "cochon"), T is CWUser', [{'T': 'CWUser', 'L': 'String'}])],
  1099                      [self.ldap, self.system], None,
  1099                      [self.ldap, self.system], None,
  1100                      {'T': 'table0.C0', 'T.login': 'table0.C1', 'L': 'table0.C1'}, []),
  1100                      {'T': 'table0.C0', 'T.login': 'table0.C1', 'L': 'table0.C1'}, []),
  1101                     ('FetchStep',
  1101                     ('FetchStep',
  1102                      [('Any T2 WHERE T2 login "billy", T2 is EUser', [{'T2': 'EUser'}])],
  1102                      [('Any T2 WHERE T2 login "billy", T2 is CWUser', [{'T2': 'CWUser'}])],
  1103                      [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
  1103                      [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
  1104                     ('FetchStep',
  1104                     ('FetchStep',
  1105                      [('Any L,X WHERE X login L, X is EUser', [{'X': 'EUser', 'L': 'String'}])],
  1105                      [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
  1106                      [self.ldap, self.system], None, {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
  1106                      [self.ldap, self.system], None, {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
  1107                     ('OneFetchStep',
  1107                     ('OneFetchStep',
  1108                      [('Any G,L WHERE X in_group G, X login L, G name "managers", (EXISTS(X copain T, T login L, T is EUser)) OR (EXISTS(X in_state S, S name "pascontent", NOT X copain T2, S is State, T2 is EUser)), G is EGroup, X is EUser',
  1108                      [('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 X copain T2, S is State, T2 is CWUser)), G is CWGroup, X is CWUser',
  1109                        [{'G': 'EGroup', 'L': 'String', 'S': 'State', 'T': 'EUser', 'T2': 'EUser', 'X': 'EUser'}])],
  1109                        [{'G': 'CWGroup', 'L': 'String', 'S': 'State', 'T': 'CWUser', 'T2': 'CWUser', 'X': 'CWUser'}])],
  1110                      None, None, [self.system],
  1110                      None, None, [self.system],
  1111                      {'T2': 'table1.C0', 'L': 'table2.C0',
  1111                      {'T2': 'table1.C0', 'L': 'table2.C0',
  1112                       'T': 'table0.C0', 'T.login': 'table0.C1', 'X': 'table2.C1', 'X.login': 'table2.C0'}, [])])
  1112                       'T': 'table0.C0', 'T.login': 'table0.C1', 'X': 'table2.C1', 'X.login': 'table2.C0'}, [])])
  1113 
  1113 
  1114     def test_exists5(self):
  1114     def test_exists5(self):
  1115         self._test('Any GN,L WHERE X in_group G, X login L, G name GN, '
  1115         self._test('Any GN,L WHERE X in_group G, X login L, G name GN, '
  1116                    'EXISTS(X copain T, T login in ("comme", "cochon")) AND '
  1116                    'EXISTS(X copain T, T login in ("comme", "cochon")) AND '
  1117                    'NOT EXISTS(X copain T2, T2 login "billy")',
  1117                    'NOT EXISTS(X copain T2, T2 login "billy")',
  1118                    [('FetchStep', [('Any T WHERE T login IN("comme", "cochon"), T is EUser',
  1118                    [('FetchStep', [('Any T WHERE T login IN("comme", "cochon"), T is CWUser',
  1119                                     [{'T': 'EUser'}])],
  1119                                     [{'T': 'CWUser'}])],
  1120                      [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
  1120                      [self.ldap, self.system], None, {'T': 'table0.C0'}, []),
  1121                     ('FetchStep', [('Any T2 WHERE T2 login "billy", T2 is EUser', [{'T2': 'EUser'}])],
  1121                     ('FetchStep', [('Any T2 WHERE T2 login "billy", T2 is CWUser', [{'T2': 'CWUser'}])],
  1122                      [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
  1122                      [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
  1123                     ('FetchStep', [('Any L,X WHERE X login L, X is EUser', [{'X': 'EUser', 'L': 'String'}])],
  1123                     ('FetchStep', [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
  1124                      [self.ldap, self.system], None,
  1124                      [self.ldap, self.system], None,
  1125                      {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
  1125                      {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
  1126                     ('OneFetchStep', [('Any GN,L WHERE X in_group G, X login L, G name GN, EXISTS(X copain T, T is EUser), NOT EXISTS(X copain T2, T2 is EUser), G is EGroup, X is EUser',
  1126                     ('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',
  1127                        [{'G': 'EGroup', 'GN': 'String', 'L': 'String', 'T': 'EUser', 'T2': 'EUser', 'X': 'EUser'}])],
  1127                        [{'G': 'CWGroup', 'GN': 'String', 'L': 'String', 'T': 'CWUser', 'T2': 'CWUser', 'X': 'CWUser'}])],
  1128                      None, None, [self.system],
  1128                      None, None, [self.system],
  1129                      {'T': 'table0.C0', 'T2': 'table1.C0',
  1129                      {'T': 'table0.C0', 'T2': 'table1.C0',
  1130                       'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, [])])
  1130                       'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, [])])
  1131             
  1131             
  1132     def test_exists_security_no_invariant(self):
  1132     def test_exists_security_no_invariant(self):
  1133         ueid = self.session.user.eid
  1133         ueid = self.session.user.eid
  1134         self._test('Any X,AA,AB,AC,AD ORDERBY AA WHERE X is EUser, X login AA, X firstname AB, X surname AC, X modification_date AD, A eid %(B)s, \
  1134         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, \
  1135     EXISTS(((X identity A) OR \
  1135     EXISTS(((X identity A) OR \
  1136             (EXISTS(X in_group C, C name IN("managers", "staff"), C is EGroup))) OR \
  1136             (EXISTS(X in_group C, C name IN("managers", "staff"), C is CWGroup))) OR \
  1137             (EXISTS(X in_group D, A in_group D, NOT D name "users", D is EGroup)))',
  1137             (EXISTS(X in_group D, A in_group D, NOT D name "users", D is CWGroup)))',
  1138                [('FetchStep', [('Any X,AA,AB,AC,AD WHERE X login AA, X firstname AB, X surname AC, X modification_date AD, X is EUser',
  1138                [('FetchStep', [('Any X,AA,AB,AC,AD WHERE X login AA, X firstname AB, X surname AC, X modification_date AD, X is CWUser',
  1139                                 [{'AA': 'String', 'AB': 'String', 'AC': 'String', 'AD': 'Datetime',
  1139                                 [{'AA': 'String', 'AB': 'String', 'AC': 'String', 'AD': 'Datetime',
  1140                                   'X': 'EUser'}])],
  1140                                   'X': 'CWUser'}])],
  1141                  [self.ldap, self.system], None, {'AA': 'table0.C1', 'AB': 'table0.C2',
  1141                  [self.ldap, self.system], None, {'AA': 'table0.C1', 'AB': 'table0.C2',
  1142                                                   'AC': 'table0.C3', 'AD': 'table0.C4',
  1142                                                   'AC': 'table0.C3', 'AD': 'table0.C4',
  1143                                                   'X': 'table0.C0',
  1143                                                   'X': 'table0.C0',
  1144                                                   'X.firstname': 'table0.C2',
  1144                                                   'X.firstname': 'table0.C2',
  1145                                                   'X.login': 'table0.C1',
  1145                                                   'X.login': 'table0.C1',
  1146                                                   'X.modification_date': 'table0.C4',
  1146                                                   'X.modification_date': 'table0.C4',
  1147                                                   'X.surname': 'table0.C3'}, []),
  1147                                                   'X.surname': 'table0.C3'}, []),
  1148                 ('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 EGroup))) OR (EXISTS(X in_group D, 5 in_group D, NOT D name "users", D is EGroup))), X is EUser',
  1148                 ('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',
  1149                                    [{'AA': 'String', 'AB': 'String', 'AC': 'String', 'AD': 'Datetime',
  1149                                    [{'AA': 'String', 'AB': 'String', 'AC': 'String', 'AD': 'Datetime',
  1150                                      'C': 'EGroup', 'D': 'EGroup', 'X': 'EUser'}])],
  1150                                      'C': 'CWGroup', 'D': 'CWGroup', 'X': 'CWUser'}])],
  1151                  None, None, [self.system],
  1151                  None, None, [self.system],
  1152                  {'AA': 'table0.C1', 'AB': 'table0.C2', 'AC': 'table0.C3', 'AD': 'table0.C4',
  1152                  {'AA': 'table0.C1', 'AB': 'table0.C2', 'AC': 'table0.C3', 'AD': 'table0.C4',
  1153                   'X': 'table0.C0',
  1153                   'X': 'table0.C0',
  1154                   'X.firstname': 'table0.C2', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C4', 'X.surname': 'table0.C3'},
  1154                   'X.firstname': 'table0.C2', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C4', 'X.surname': 'table0.C3'},
  1155                  [])],
  1155                  [])],
  1156                    {'B': ueid})
  1156                    {'B': ueid})
  1157 
  1157 
  1158     def test_relation_need_split(self):
  1158     def test_relation_need_split(self):
  1159         self._test('Any X, S WHERE X in_state S',
  1159         self._test('Any X, S WHERE X in_state S',
  1160                    [('UnionStep', None, None, [
  1160                    [('UnionStep', None, None, [
  1161                        ('OneFetchStep', [('Any X,S WHERE X in_state S, S is State, X is IN(Affaire, EUser)',
  1161                        ('OneFetchStep', [('Any X,S WHERE X in_state S, S is State, X is IN(Affaire, CWUser)',
  1162                                           [{'X': 'Affaire', 'S': 'State'}, {'X': 'EUser', 'S': 'State'}])], 
  1162                                           [{'X': 'Affaire', 'S': 'State'}, {'X': 'CWUser', 'S': 'State'}])], 
  1163                         None, None, [self.system], {}, []),
  1163                         None, None, [self.system], {}, []),
  1164                        ('OneFetchStep', [('Any X,S WHERE X in_state S, S is State, X is Note',
  1164                        ('OneFetchStep', [('Any X,S WHERE X in_state S, S is State, X is Note',
  1165                                           [{'X': 'Note', 'S': 'State'}])], 
  1165                                           [{'X': 'Note', 'S': 'State'}])], 
  1166                         None, None, [self.rql, self.system], {}, []),
  1166                         None, None, [self.rql, self.system], {}, []),
  1167                     ])])
  1167                     ])])
  1170         self._test('Any X,S,U WHERE X in_state S, X todo_by U',
  1170         self._test('Any X,S,U WHERE X in_state S, X todo_by U',
  1171                    [('FetchStep', [('Any X,S WHERE X in_state S, S is State, X is Note',
  1171                    [('FetchStep', [('Any X,S WHERE X in_state S, S is State, X is Note',
  1172                                     [{'X': 'Note', 'S': 'State'}])],
  1172                                     [{'X': 'Note', 'S': 'State'}])],
  1173                      [self.rql, self.system], None, {'X': 'table0.C0', 'S': 'table0.C1'}, []),
  1173                      [self.rql, self.system], None, {'X': 'table0.C0', 'S': 'table0.C1'}, []),
  1174                      ('UnionStep', None, None,
  1174                      ('UnionStep', None, None,
  1175                       [('OneFetchStep', [('Any X,S,U WHERE X in_state S, X todo_by U, S is State, U is EUser, X is Note',
  1175                       [('OneFetchStep', [('Any X,S,U WHERE X in_state S, X todo_by U, S is State, U is CWUser, X is Note',
  1176                                           [{'X': 'Note', 'S': 'State', 'U': 'EUser'}])],
  1176                                           [{'X': 'Note', 'S': 'State', 'U': 'CWUser'}])],
  1177                         None, None, [self.system], {'X': 'table0.C0', 'S': 'table0.C1'}, []),
  1177                         None, None, [self.system], {'X': 'table0.C0', 'S': 'table0.C1'}, []),
  1178                        ('OneFetchStep', [('Any X,S,U WHERE X in_state S, X todo_by U, S is State, U is Personne, X is Affaire',
  1178                        ('OneFetchStep', [('Any X,S,U WHERE X in_state S, X todo_by U, S is State, U is Personne, X is Affaire',
  1179                                           [{'X': 'Affaire', 'S': 'State', 'U': 'Personne'}])],
  1179                                           [{'X': 'Affaire', 'S': 'State', 'U': 'Personne'}])],
  1180                         None, None, [self.system], {}, []),
  1180                         None, None, [self.system], {}, []),
  1181                        ])
  1181                        ])
  1185         self._test('Any X,U WHERE X in_state S, S name "pending", X todo_by U',
  1185         self._test('Any X,U WHERE X in_state S, S name "pending", X todo_by U',
  1186                    [('FetchStep', [('Any X WHERE X in_state S, S name "pending", S is State, X is Note',
  1186                    [('FetchStep', [('Any X WHERE X in_state S, S name "pending", S is State, X is Note',
  1187                                     [{'X': 'Note', 'S': 'State'}])],
  1187                                     [{'X': 'Note', 'S': 'State'}])],
  1188                      [self.rql, self.system], None, {'X': 'table0.C0'}, []),
  1188                      [self.rql, self.system], None, {'X': 'table0.C0'}, []),
  1189                      ('UnionStep', None, None,
  1189                      ('UnionStep', None, None,
  1190                       [('OneFetchStep', [('Any X,U WHERE X todo_by U, U is EUser, X is Note',
  1190                       [('OneFetchStep', [('Any X,U WHERE X todo_by U, U is CWUser, X is Note',
  1191                                           [{'X': 'Note', 'U': 'EUser'}])],
  1191                                           [{'X': 'Note', 'U': 'CWUser'}])],
  1192                         None, None, [self.system], {'X': 'table0.C0'}, []),
  1192                         None, None, [self.system], {'X': 'table0.C0'}, []),
  1193                        ('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',
  1193                        ('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',
  1194                                           [{'S': 'State', 'U': 'Personne', 'X': 'Affaire'}])],
  1194                                           [{'S': 'State', 'U': 'Personne', 'X': 'Affaire'}])],
  1195                         None, None, [self.system], {}, [])
  1195                         None, None, [self.system], {}, [])
  1196                        ])
  1196                        ])
  1204                     ('UnionStep', None, None, [
  1204                     ('UnionStep', None, None, [
  1205                         ('OneFetchStep', [('Any X,T WHERE T tags X, T is Tag, X is Note',
  1205                         ('OneFetchStep', [('Any X,T WHERE T tags X, T is Tag, X is Note',
  1206                                            [{'X': 'Note', 'T': 'Tag'}])],
  1206                                            [{'X': 'Note', 'T': 'Tag'}])],
  1207                          None, None,
  1207                          None, None,
  1208                          [self.system], {'X': 'table0.C0'}, []),
  1208                          [self.system], {'X': 'table0.C0'}, []),
  1209                         ('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, EUser)',
  1209                         ('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)',
  1210                                            [{'X': 'Affaire', 'S': 'State', 'T': 'Tag'},
  1210                                            [{'X': 'Affaire', 'S': 'State', 'T': 'Tag'},
  1211                                             {'X': 'EUser', 'S': 'State', 'T': 'Tag'}])],
  1211                                             {'X': 'CWUser', 'S': 'State', 'T': 'Tag'}])],
  1212                          None, None,
  1212                          None, None,
  1213                          [self.system], {}, []),
  1213                          [self.system], {}, []),
  1214                         ])
  1214                         ])
  1215                     ])
  1215                     ])
  1216 
  1216 
  1249                        [('Any SN WHERE NOT X in_state S, S name SN, S is State, X is Note',
  1249                        [('Any SN WHERE NOT X in_state S, S name SN, S is State, X is Note',
  1250                          [{'S': 'State', 'SN': 'String', 'X': 'Note'}])],
  1250                          [{'S': 'State', 'SN': 'String', 'X': 'Note'}])],
  1251                        None, None, [self.rql, self.system], {},
  1251                        None, None, [self.rql, self.system], {},
  1252                        []),
  1252                        []),
  1253                       ('OneFetchStep',
  1253                       ('OneFetchStep',
  1254                        [('Any SN WHERE NOT X in_state S, S name SN, S is State, X is IN(Affaire, EUser)',
  1254                        [('Any SN WHERE NOT X in_state S, S name SN, S is State, X is IN(Affaire, CWUser)',
  1255                          [{'S': 'State', 'SN': 'String', 'X': 'Affaire'},
  1255                          [{'S': 'State', 'SN': 'String', 'X': 'Affaire'},
  1256                           {'S': 'State', 'SN': 'String', 'X': 'EUser'}])],
  1256                           {'S': 'State', 'SN': 'String', 'X': 'CWUser'}])],
  1257                        None, None, [self.system], {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1257                        None, None, [self.system], {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1258                        []),]
  1258                        []),]
  1259                      )])
  1259                      )])
  1260             
  1260             
  1261     def test_external_attributes_and_relation(self):
  1261     def test_external_attributes_and_relation(self):
  1263         self._test('Any A,B,C,D WHERE A eid %(x)s,A creation_date B,A modification_date C, A todo_by D?',
  1263         self._test('Any A,B,C,D WHERE A eid %(x)s,A creation_date B,A modification_date C, A todo_by D?',
  1264                    [('FetchStep', [('Any A,B,C WHERE A eid 999999, A creation_date B, A modification_date C, A is Note',
  1264                    [('FetchStep', [('Any A,B,C WHERE A eid 999999, A creation_date B, A modification_date C, A is Note',
  1265                                     [{'A': 'Note', 'C': 'Datetime', 'B': 'Datetime'}])],
  1265                                     [{'A': 'Note', 'C': 'Datetime', 'B': 'Datetime'}])],
  1266                      [self.rql], None,
  1266                      [self.rql], None,
  1267                      {'A': 'table0.C0', 'A.creation_date': 'table0.C1', 'A.modification_date': 'table0.C2', 'C': 'table0.C2', 'B': 'table0.C1'}, []),
  1267                      {'A': 'table0.C0', 'A.creation_date': 'table0.C1', 'A.modification_date': 'table0.C2', 'C': 'table0.C2', 'B': 'table0.C1'}, []),
  1268                     #('FetchStep', [('Any D WHERE D is EUser', [{'D': 'EUser'}])],
  1268                     #('FetchStep', [('Any D WHERE D is CWUser', [{'D': 'CWUser'}])],
  1269                     # [self.ldap, self.system], None, {'D': 'table1.C0'}, []),
  1269                     # [self.ldap, self.system], None, {'D': 'table1.C0'}, []),
  1270                     ('OneFetchStep', [('Any A,B,C,D WHERE A creation_date B, A modification_date C, A todo_by D?, A is Note, D is EUser',
  1270                     ('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',
  1271                                        [{'A': 'Note', 'C': 'Datetime', 'B': 'Datetime', 'D': 'EUser'}])],
  1271                                        [{'A': 'Note', 'C': 'Datetime', 'B': 'Datetime', 'D': 'CWUser'}])],
  1272                      None, None, [self.system],
  1272                      None, None, [self.system],
  1273                      {'A': 'table0.C0', 'A.creation_date': 'table0.C1', 'A.modification_date': 'table0.C2', 'C': 'table0.C2', 'B': 'table0.C1'}, [])],
  1273                      {'A': 'table0.C0', 'A.creation_date': 'table0.C1', 'A.modification_date': 'table0.C2', 'C': 'table0.C2', 'B': 'table0.C1'}, [])],
  1274                    {'x': 999999})
  1274                    {'x': 999999})
  1275 
  1275 
  1276 
  1276 
  1277     def test_simplified_var(self):
  1277     def test_simplified_var(self):
  1278         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  1278         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  1279         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',
  1279         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',
  1280                    [('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',
  1280                    [('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',
  1281                                        [{'X': 'Note', 'G': 'EGroup', 'P': 'EPermission'}])],
  1281                                        [{'X': 'Note', 'G': 'CWGroup', 'P': 'CWPermission'}])],
  1282                      None, None, [self.system], {}, [])],
  1282                      None, None, [self.system], {}, [])],
  1283                    {'x': 999999, 'u': self.session.user.eid})
  1283                    {'x': 999999, 'u': self.session.user.eid})
  1284 
  1284 
  1285     def test_has_text(self):
  1285     def test_has_text(self):
  1286         self._test('Card X WHERE X has_text "toto"',
  1286         self._test('Card X WHERE X has_text "toto"',
  1380                    [('FetchStep', [('Any X,N WHERE X is Tag, X name N', [{'N': 'String', 'X': 'Tag'}]),
  1380                    [('FetchStep', [('Any X,N WHERE X is Tag, X name N', [{'N': 'String', 'X': 'Tag'}]),
  1381                                    ('Any X,T WHERE X is Bookmark, X title T',
  1381                                    ('Any X,T WHERE X is Bookmark, X title T',
  1382                                     [{'T': 'String', 'X': 'Bookmark'}])],
  1382                                     [{'T': 'String', 'X': 'Bookmark'}])],
  1383                      [self.system], {}, {'N': 'table0.C1', 'X': 'table0.C0', 'X.name': 'table0.C1'}, []),
  1383                      [self.system], {}, {'N': 'table0.C1', 'X': 'table0.C0', 'X.name': 'table0.C1'}, []),
  1384                     ('FetchStep',
  1384                     ('FetchStep',
  1385                      [('Any B,C WHERE B login C, B is EUser', [{'B': 'EUser', 'C': 'String'}])],
  1385                      [('Any B,C WHERE B login C, B is CWUser', [{'B': 'CWUser', 'C': 'String'}])],
  1386                      [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []),
  1386                      [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []),
  1387                     ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is EUser',
  1387                     ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser',
  1388                                        [{'A': 'Bookmark', 'B': 'EUser', 'C': 'String'},
  1388                                        [{'A': 'Bookmark', 'B': 'CWUser', 'C': 'String'},
  1389                                         {'A': 'Tag', 'B': 'EUser', 'C': 'String'}])],
  1389                                         {'A': 'Tag', 'B': 'CWUser', 'C': 'String'}])],
  1390                      None, None, [self.system],
  1390                      None, None, [self.system],
  1391                      {'A': 'table0.C0',
  1391                      {'A': 'table0.C0',
  1392                       'B': 'table1.C0', 'B.login': 'table1.C1',
  1392                       'B': 'table1.C0', 'B.login': 'table1.C1',
  1393                       'C': 'table1.C1',
  1393                       'C': 'table1.C1',
  1394                       'N': 'table0.C1'},
  1394                       'N': 'table0.C1'},
  1414                         'X': 'table0.C0',
  1414                         'X': 'table0.C0',
  1415                         'X.name': 'table0.C1',
  1415                         'X.name': 'table0.C1',
  1416                         'X.title': 'table0.C1'}, []),
  1416                         'X.title': 'table0.C1'}, []),
  1417                       ]),
  1417                       ]),
  1418                     ('FetchStep',
  1418                     ('FetchStep',
  1419                      [('Any B,C WHERE B login C, B is EUser', [{'B': 'EUser', 'C': 'String'}])],
  1419                      [('Any B,C WHERE B login C, B is CWUser', [{'B': 'CWUser', 'C': 'String'}])],
  1420                      [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []),
  1420                      [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []),
  1421                     ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is EUser',
  1421                     ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser',
  1422                                        [{'A': 'Card', 'B': 'EUser', 'C': 'String'},
  1422                                        [{'A': 'Card', 'B': 'CWUser', 'C': 'String'},
  1423                                         {'A': 'Tag', 'B': 'EUser', 'C': 'String'}])],
  1423                                         {'A': 'Tag', 'B': 'CWUser', 'C': 'String'}])],
  1424                      None, None, [self.system],
  1424                      None, None, [self.system],
  1425                      {'A': 'table0.C0',
  1425                      {'A': 'table0.C0',
  1426                       'B': 'table1.C0', 'B.login': 'table1.C1',
  1426                       'B': 'table1.C0', 'B.login': 'table1.C1',
  1427                       'C': 'table1.C1',
  1427                       'C': 'table1.C1',
  1428                       'N': 'table0.C1'},
  1428                       'N': 'table0.C1'},
  1605     
  1605     
  1606     def test_delete_relation1(self):
  1606     def test_delete_relation1(self):
  1607         ueid = self.session.user.eid
  1607         ueid = self.session.user.eid
  1608         self._test('DELETE X created_by Y WHERE X eid %(x)s, NOT Y eid %(y)s',
  1608         self._test('DELETE X created_by Y WHERE X eid %(x)s, NOT Y eid %(y)s',
  1609                    [('DeleteRelationsStep', [
  1609                    [('DeleteRelationsStep', [
  1610                        ('OneFetchStep', [('Any 5,Y WHERE %s created_by Y, NOT Y eid %s, Y is EUser'%(ueid, ueid),
  1610                        ('OneFetchStep', [('Any 5,Y WHERE %s created_by Y, NOT Y eid %s, Y is CWUser'%(ueid, ueid),
  1611                                           [{'Y': 'EUser'}])],
  1611                                           [{'Y': 'CWUser'}])],
  1612                         None, None, [self.system], {}, []),
  1612                         None, None, [self.system], {}, []),
  1613                        ]),
  1613                        ]),
  1614                     ],
  1614                     ],
  1615                    {'x': ueid, 'y': ueid})
  1615                    {'x': ueid, 'y': ueid})
  1616         
  1616         
  1617     def test_delete_relation2(self):
  1617     def test_delete_relation2(self):
  1618         ueid = self.session.user.eid
  1618         ueid = self.session.user.eid
  1619         self._test('DELETE X created_by Y WHERE X eid %(x)s, NOT Y login "syt"',
  1619         self._test('DELETE X created_by Y WHERE X eid %(x)s, NOT Y login "syt"',
  1620                    [('FetchStep', [('Any Y WHERE NOT Y login "syt", Y is EUser', [{'Y': 'EUser'}])],
  1620                    [('FetchStep', [('Any Y WHERE NOT Y login "syt", Y is CWUser', [{'Y': 'CWUser'}])],
  1621                      [self.ldap, self.system], None, {'Y': 'table0.C0'}, []),
  1621                      [self.ldap, self.system], None, {'Y': 'table0.C0'}, []),
  1622                     ('DeleteRelationsStep', [
  1622                     ('DeleteRelationsStep', [
  1623                         ('OneFetchStep', [('Any %s,Y WHERE %s created_by Y, Y is EUser'%(ueid,ueid), [{'Y': 'EUser'}])],
  1623                         ('OneFetchStep', [('Any %s,Y WHERE %s created_by Y, Y is CWUser'%(ueid,ueid), [{'Y': 'CWUser'}])],
  1624                          None, None, [self.system], {'Y': 'table0.C0'}, []),
  1624                          None, None, [self.system], {'Y': 'table0.C0'}, []),
  1625                         ]),
  1625                         ]),
  1626                     ],
  1626                     ],
  1627                    {'x': ueid, 'y': ueid})
  1627                    {'x': ueid, 'y': ueid})
  1628 
  1628 
  1649                    {'x': 999999})
  1649                    {'x': 999999})
  1650                    
  1650                    
  1651     def test_update(self):
  1651     def test_update(self):
  1652         self._test('SET X copain Y WHERE X login "comme", Y login "cochon"',
  1652         self._test('SET X copain Y WHERE X login "comme", Y login "cochon"',
  1653                    [('FetchStep',
  1653                    [('FetchStep',
  1654                      [('Any X WHERE X login "comme", X is EUser', [{'X': 'EUser'}])],
  1654                      [('Any X WHERE X login "comme", X is CWUser', [{'X': 'CWUser'}])],
  1655                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
  1655                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
  1656                     ('FetchStep',
  1656                     ('FetchStep',
  1657                      [('Any Y WHERE Y login "cochon", Y is EUser', [{'Y': 'EUser'}])],
  1657                      [('Any Y WHERE Y login "cochon", Y is CWUser', [{'Y': 'CWUser'}])],
  1658                      [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
  1658                      [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
  1659                     ('UpdateStep',
  1659                     ('UpdateStep',
  1660                      [('OneFetchStep',
  1660                      [('OneFetchStep',
  1661                        [('DISTINCT Any X,Y WHERE X is EUser, Y is EUser',
  1661                        [('DISTINCT Any X,Y WHERE X is CWUser, Y is CWUser',
  1662                          [{'X': 'EUser', 'Y': 'EUser'}])],
  1662                          [{'X': 'CWUser', 'Y': 'CWUser'}])],
  1663                        None, None, [self.system], {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
  1663                        None, None, [self.system], {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
  1664                       ])
  1664                       ])
  1665                     ])
  1665                     ])
  1666 
  1666 
  1667     def test_update2(self):
  1667     def test_update2(self):
  1668         self._test('SET U in_group G WHERE G name ~= "bougloup%", U login "admin"',
  1668         self._test('SET U in_group G WHERE G name ~= "bougloup%", U login "admin"',
  1669                    [('FetchStep', [('Any U WHERE U login "admin", U is EUser', [{'U': 'EUser'}])],
  1669                    [('FetchStep', [('Any U WHERE U login "admin", U is CWUser', [{'U': 'CWUser'}])],
  1670                      [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
  1670                      [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
  1671                      ('UpdateStep', [
  1671                      ('UpdateStep', [
  1672                         ('OneFetchStep', [('DISTINCT Any U,G WHERE G name ILIKE "bougloup%", G is EGroup, U is EUser',
  1672                         ('OneFetchStep', [('DISTINCT Any U,G WHERE G name ILIKE "bougloup%", G is CWGroup, U is CWUser',
  1673                                            [{'U': 'EUser', 'G': 'EGroup'}])],
  1673                                            [{'U': 'CWUser', 'G': 'CWGroup'}])],
  1674                          None, None, [self.system], {'U': 'table0.C0'}, []),
  1674                          None, None, [self.system], {'U': 'table0.C0'}, []),
  1675                         ]),
  1675                         ]),
  1676                     ])
  1676                     ])
  1677 
  1677 
  1678     def test_update3(self):
  1678     def test_update3(self):
  1688                     ],
  1688                     ],
  1689                    {'x': anoneid})
  1689                    {'x': anoneid})
  1690 
  1690 
  1691 #     def test_update4(self):
  1691 #     def test_update4(self):
  1692 #         # since we are adding a in_state relation with a state from the system
  1692 #         # since we are adding a in_state relation with a state from the system
  1693 #         # source, EUser should only be searched only in the system source as well
  1693 #         # source, CWUser should only be searched only in the system source as well
  1694 #         rset = self.execute('State X WHERE X name "activated"')
  1694 #         rset = self.execute('State X WHERE X name "activated"')
  1695 #         assert len(rset) == 1, rset
  1695 #         assert len(rset) == 1, rset
  1696 #         activatedeid = rset[0][0]
  1696 #         activatedeid = rset[0][0]
  1697 #         self._test('SET X in_state S WHERE X is EUser, S eid %s' % activatedeid,
  1697 #         self._test('SET X in_state S WHERE X is CWUser, S eid %s' % activatedeid,
  1698 #                    [('UpdateStep', [
  1698 #                    [('UpdateStep', [
  1699 #                        ('OneFetchStep', [('DISTINCT Any X,%s WHERE X is EUser' % activatedeid,
  1699 #                        ('OneFetchStep', [('DISTINCT Any X,%s WHERE X is CWUser' % activatedeid,
  1700 #                                           [{'X': 'EUser'}])],
  1700 #                                           [{'X': 'CWUser'}])],
  1701 #                         None, None, [self.system], {}, []),
  1701 #                         None, None, [self.system], {}, []),
  1702 #                        ]),
  1702 #                        ]),
  1703 #                     ])
  1703 #                     ])
  1704         
  1704         
  1705     # non regression tests ####################################################
  1705     # non regression tests ####################################################
  1706     
  1706     
  1707     def test_nonregr1(self):
  1707     def test_nonregr1(self):
  1708         self._test('Any X, Y WHERE X copain Y, X login "syt", Y login "cochon"',
  1708         self._test('Any X, Y WHERE X copain Y, X login "syt", Y login "cochon"',
  1709                    [('FetchStep',
  1709                    [('FetchStep',
  1710                      [('Any X WHERE X login "syt", X is EUser', [{'X': 'EUser'}])],
  1710                      [('Any X WHERE X login "syt", X is CWUser', [{'X': 'CWUser'}])],
  1711                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
  1711                      [self.ldap, self.system], None, {'X': 'table0.C0'}, []),
  1712                     ('FetchStep',
  1712                     ('FetchStep',
  1713                      [('Any Y WHERE Y login "cochon", Y is EUser', [{'Y': 'EUser'}])],
  1713                      [('Any Y WHERE Y login "cochon", Y is CWUser', [{'Y': 'CWUser'}])],
  1714                      [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
  1714                      [self.ldap, self.system], None, {'Y': 'table1.C0'}, []),
  1715                     ('OneFetchStep',
  1715                     ('OneFetchStep',
  1716                      [('Any X,Y WHERE X copain Y, X is EUser, Y is EUser',
  1716                      [('Any X,Y WHERE X copain Y, X is CWUser, Y is CWUser',
  1717                        [{'X': 'EUser', 'Y': 'EUser'}])],
  1717                        [{'X': 'CWUser', 'Y': 'CWUser'}])],
  1718                      None, None, [self.system], {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
  1718                      None, None, [self.system], {'X': 'table0.C0', 'Y': 'table1.C0'}, [])
  1719                     ])
  1719                     ])
  1720     
  1720     
  1721     def test_nonregr2(self):
  1721     def test_nonregr2(self):
  1722         treid = self.session.user.latest_trinfo().eid
  1722         treid = self.session.user.latest_trinfo().eid
  1723         self._test('Any X ORDERBY D DESC WHERE E eid %(x)s, E wf_info_for X, X modification_date D',
  1723         self._test('Any X ORDERBY D DESC WHERE E eid %(x)s, E wf_info_for X, X modification_date D',
  1724                    [('FetchStep', [('Any X,D WHERE X modification_date D, X is Note',
  1724                    [('FetchStep', [('Any X,D WHERE X modification_date D, X is Note',
  1725                                     [{'X': 'Note', 'D': 'Datetime'}])],
  1725                                     [{'X': 'Note', 'D': 'Datetime'}])],
  1726                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.modification_date': 'table0.C1', 'D': 'table0.C1'}, []),
  1726                      [self.rql, self.system], None, {'X': 'table0.C0', 'X.modification_date': 'table0.C1', 'D': 'table0.C1'}, []),
  1727                     ('FetchStep', [('Any X,D WHERE X modification_date D, X is EUser',
  1727                     ('FetchStep', [('Any X,D WHERE X modification_date D, X is CWUser',
  1728                                     [{'X': 'EUser', 'D': 'Datetime'}])],
  1728                                     [{'X': 'CWUser', 'D': 'Datetime'}])],
  1729                      [self.ldap, self.system], None, {'X': 'table1.C0', 'X.modification_date': 'table1.C1', 'D': 'table1.C1'}, []),
  1729                      [self.ldap, self.system], None, {'X': 'table1.C0', 'X.modification_date': 'table1.C1', 'D': 'table1.C1'}, []),
  1730                     ('AggrStep', 'Any X ORDERBY D DESC', None, None, 'table2', None, [
  1730                     ('AggrStep', 'Any X ORDERBY D DESC', None, None, 'table2', None, [
  1731                         ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is Affaire'%treid,
  1731                         ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is Affaire'%treid,
  1732                                         [{'X': 'Affaire', 'E': 'TrInfo', 'D': 'Datetime'}])],
  1732                                         [{'X': 'Affaire', 'E': 'TrInfo', 'D': 'Datetime'}])],
  1733                          [self.system],
  1733                          [self.system],
  1734                          {},
  1734                          {},
  1735                          {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
  1735                          {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
  1736                         ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is EUser'%treid,
  1736                         ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is CWUser'%treid,
  1737                                         [{'X': 'EUser', 'E': 'TrInfo', 'D': 'Datetime'}])],
  1737                                         [{'X': 'CWUser', 'E': 'TrInfo', 'D': 'Datetime'}])],
  1738                          [self.system],
  1738                          [self.system],
  1739                          {'X': 'table1.C0', 'X.modification_date': 'table1.C1', 'D': 'table1.C1'},
  1739                          {'X': 'table1.C0', 'X.modification_date': 'table1.C1', 'D': 'table1.C1'},
  1740                          {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
  1740                          {'X': 'table2.C0', 'X.modification_date': 'table2.C1', 'D': 'table2.C1', 'E.wf_info_for': 'table2.C0'}, []),
  1741                         ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is Note'%treid,
  1741                         ('FetchStep', [('Any X,D WHERE E eid %s, E wf_info_for X, X modification_date D, E is TrInfo, X is Note'%treid,
  1742                                         [{'X': 'Note', 'E': 'TrInfo', 'D': 'Datetime'}])],
  1742                                         [{'X': 'Note', 'E': 'TrInfo', 'D': 'Datetime'}])],
  1747                     ],
  1747                     ],
  1748                    {'x': treid})
  1748                    {'x': treid})
  1749         
  1749         
  1750     def test_nonregr3(self):
  1750     def test_nonregr3(self):
  1751         # original jpl query:
  1751         # original jpl query:
  1752         # Any X, NOW - CD, P WHERE P is Project, U interested_in P, U is EUser, U login "sthenault", X concerns P, X creation_date CD ORDERBY CD DESC LIMIT 5
  1752         # 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
  1753         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',
  1753         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',
  1754                    [('FetchStep', [('Any U WHERE U login "admin", U is EUser', [{'U': 'EUser'}])],
  1754                    [('FetchStep', [('Any U WHERE U login "admin", U is CWUser', [{'U': 'CWUser'}])],
  1755                      [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
  1755                      [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
  1756                     ('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 EUser, X is EEType',
  1756                     ('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',
  1757                                        [{'P': 'Bookmark', 'U': 'EUser', 'X': 'EEType', 'CD': 'Datetime'}])],
  1757                                        [{'P': 'Bookmark', 'U': 'CWUser', 'X': 'CWEType', 'CD': 'Datetime'}])],
  1758                      5, None,  [self.system], {'U': 'table0.C0'}, [])]
  1758                      5, None,  [self.system], {'U': 'table0.C0'}, [])]
  1759                    )
  1759                    )
  1760         
  1760         
  1761     def test_nonregr4(self):
  1761     def test_nonregr4(self):
  1762         self._test('Any U ORDERBY D DESC WHERE WF wf_info_for X, WF creation_date D, WF from_state FS, '
  1762         self._test('Any U ORDERBY D DESC WHERE WF wf_info_for X, WF creation_date D, WF from_state FS, '
  1763                    'WF owned_by U?, X eid %(x)s',
  1763                    'WF owned_by U?, X eid %(x)s',
  1764                    [#('FetchStep', [('Any U WHERE U is EUser', [{'U': 'EUser'}])],
  1764                    [#('FetchStep', [('Any U WHERE U is CWUser', [{'U': 'CWUser'}])],
  1765                     # [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
  1765                     # [self.ldap, self.system], None, {'U': 'table0.C0'}, []),
  1766                     ('OneFetchStep', [('Any U ORDERBY D DESC WHERE WF wf_info_for 5, WF creation_date D, WF from_state FS, WF owned_by U?',
  1766                     ('OneFetchStep', [('Any U ORDERBY D DESC WHERE WF wf_info_for 5, WF creation_date D, WF from_state FS, WF owned_by U?',
  1767                                        [{'WF': 'TrInfo', 'FS': 'State', 'U': 'EUser', 'D': 'Datetime'}])],
  1767                                        [{'WF': 'TrInfo', 'FS': 'State', 'U': 'CWUser', 'D': 'Datetime'}])],
  1768                      None, None,
  1768                      None, None,
  1769                      [self.system], {}, [])],
  1769                      [self.system], {}, [])],
  1770                    {'x': self.session.user.eid})
  1770                    {'x': self.session.user.eid})
  1771 
  1771 
  1772     def test_nonregr5(self):
  1772     def test_nonregr5(self):
  1835                        None, None, [self.system],
  1835                        None, None, [self.system],
  1836                        {'Y': u'table0.C0'}, [])])],
  1836                        {'Y': u'table0.C0'}, [])])],
  1837                    {'x': 999999, 'z': 999998})
  1837                    {'x': 999999, 'z': 999998})
  1838 
  1838 
  1839     def test_nonregr10(self):
  1839     def test_nonregr10(self):
  1840         repo._type_source_cache[999999] = ('EUser', 'ldapuser', 999999)
  1840         repo._type_source_cache[999999] = ('CWUser', 'ldapuser', 999999)
  1841         self._test('Any X,AA,AB ORDERBY AA WHERE E eid %(x)s, E owned_by X, X login AA, X modification_date AB',
  1841         self._test('Any X,AA,AB ORDERBY AA WHERE E eid %(x)s, E owned_by X, X login AA, X modification_date AB',
  1842                    [('FetchStep',
  1842                    [('FetchStep',
  1843                      [('Any X,AA,AB WHERE X login AA, X modification_date AB, X is EUser',
  1843                      [('Any X,AA,AB WHERE X login AA, X modification_date AB, X is CWUser',
  1844                        [{'AA': 'String', 'AB': 'Datetime', 'X': 'EUser'}])],
  1844                        [{'AA': 'String', 'AB': 'Datetime', 'X': 'CWUser'}])],
  1845                      [self.ldap, self.system], None, {'AA': 'table0.C1', 'AB': 'table0.C2',
  1845                      [self.ldap, self.system], None, {'AA': 'table0.C1', 'AB': 'table0.C2',
  1846                                                       'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2'},
  1846                                                       'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2'},
  1847                      []),
  1847                      []),
  1848                     ('OneFetchStep',
  1848                     ('OneFetchStep',
  1849                      [('Any X,AA,AB ORDERBY AA WHERE 999999 owned_by X, X login AA, X modification_date AB, X is EUser',
  1849                      [('Any X,AA,AB ORDERBY AA WHERE 999999 owned_by X, X login AA, X modification_date AB, X is CWUser',
  1850                        [{'AA': 'String', 'AB': 'Datetime', 'X': 'EUser'}])],
  1850                        [{'AA': 'String', 'AB': 'Datetime', 'X': 'CWUser'}])],
  1851                      None, None, [self.system], {'AA': 'table0.C1', 'AB': 'table0.C2',
  1851                      None, None, [self.system], {'AA': 'table0.C1', 'AB': 'table0.C2',
  1852                                                  'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2'},
  1852                                                  'X': 'table0.C0', 'X.login': 'table0.C1', 'X.modification_date': 'table0.C2'},
  1853                      [])
  1853                      [])
  1854                     ],
  1854                     ],
  1855                    {'x': 999999})
  1855                    {'x': 999999})
  1856         
  1856         
  1857     def test_nonregr11(self):
  1857     def test_nonregr11(self):
  1858         repo._type_source_cache[999999] = ('Bookmark', 'system', 999999)
  1858         repo._type_source_cache[999999] = ('Bookmark', 'system', 999999)
  1859         self._test('SET X bookmarked_by Y WHERE X eid %(x)s, Y login "hop"',
  1859         self._test('SET X bookmarked_by Y WHERE X eid %(x)s, Y login "hop"',
  1860                    [('FetchStep',
  1860                    [('FetchStep',
  1861                      [('Any Y WHERE Y login "hop", Y is EUser', [{'Y': 'EUser'}])],
  1861                      [('Any Y WHERE Y login "hop", Y is CWUser', [{'Y': 'CWUser'}])],
  1862                      [self.ldap, self.system],
  1862                      [self.ldap, self.system],
  1863                      None, {'Y': 'table0.C0'}, []),
  1863                      None, {'Y': 'table0.C0'}, []),
  1864                     ('UpdateStep',
  1864                     ('UpdateStep',
  1865                      [('OneFetchStep', [('DISTINCT Any 999999,Y WHERE Y is EUser', [{'Y': 'EUser'}])],
  1865                      [('OneFetchStep', [('DISTINCT Any 999999,Y WHERE Y is CWUser', [{'Y': 'CWUser'}])],
  1866                        None, None, [self.system], {'Y': 'table0.C0'},
  1866                        None, None, [self.system], {'Y': 'table0.C0'},
  1867                        [])]
  1867                        [])]
  1868                      )],
  1868                      )],
  1869                    {'x': 999999})
  1869                    {'x': 999999})
  1870         
  1870         
  1896         # identity wrapped into exists:
  1896         # identity wrapped into exists:
  1897         # should'nt propagate constraint that U is in the same source as ME
  1897         # should'nt propagate constraint that U is in the same source as ME
  1898         self._test('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
  1898         self._test('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
  1899                    'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (EXISTS(U identity ME) '
  1899                    'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (EXISTS(U identity ME) '
  1900                    'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
  1900                    'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
  1901                    'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is EUser)',
  1901                    'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is CWUser)',
  1902                    [('FetchStep', [('Any U,UL WHERE U login UL, U is EUser',
  1902                    [('FetchStep', [('Any U,UL WHERE U login UL, U is CWUser',
  1903                                     [{'U': 'EUser', 'UL': 'String'}])],
  1903                                     [{'U': 'CWUser', 'UL': 'String'}])],
  1904                      [self.ldap, self.system], None,
  1904                      [self.ldap, self.system], None,
  1905                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1905                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1906                      []),
  1906                      []),
  1907                     ('FetchStep', [('Any U,UL WHERE ((EXISTS(U identity 5)) OR (EXISTS(U in_group G, G name IN("managers", "staff"), G is EGroup))) OR (EXISTS(U in_group H, 5 in_group H, NOT H name "users", H is EGroup)), U login UL, U is EUser',
  1907                     ('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',
  1908                                     [{'G': 'EGroup', 'H': 'EGroup', 'U': 'EUser', 'UL': 'String'}])],
  1908                                     [{'G': 'CWGroup', 'H': 'CWGroup', 'U': 'CWUser', 'UL': 'String'}])],
  1909                      [self.system],
  1909                      [self.system],
  1910                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1910                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1911                      {'U': 'table1.C0', 'U.login': 'table1.C1', 'UL': 'table1.C1'},
  1911                      {'U': 'table1.C0', 'U.login': 'table1.C1', 'UL': 'table1.C1'},
  1912                      []),
  1912                      []),
  1913                     ('OneFetchStep', [('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File',
  1913                     ('OneFetchStep', [('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File',
  1914                                        [{'B': 'File', 'U': 'EUser', 'UL': 'String'}])],
  1914                                        [{'B': 'File', 'U': 'CWUser', 'UL': 'String'}])],
  1915                      None, None, [self.system],
  1915                      None, None, [self.system],
  1916                      {'U': 'table1.C0', 'UL': 'table1.C1'},
  1916                      {'U': 'table1.C0', 'UL': 'table1.C1'},
  1917                      [])],
  1917                      [])],
  1918                    {'x': self.session.user.eid})
  1918                    {'x': self.session.user.eid})
  1919         
  1919         
  1930         # wrapped in exists() if used in multi-source
  1930         # wrapped in exists() if used in multi-source
  1931         self.skip('take a look at me if you wish')
  1931         self.skip('take a look at me if you wish')
  1932         self._test('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
  1932         self._test('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File '
  1933                    'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (U identity ME '
  1933                    'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (U identity ME '
  1934                    'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
  1934                    'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
  1935                    'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is EUser)',
  1935                    'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is CWUser)',
  1936                    [('FetchStep', [('Any U,UL WHERE U login UL, U is EUser',
  1936                    [('FetchStep', [('Any U,UL WHERE U login UL, U is CWUser',
  1937                                     [{'U': 'EUser', 'UL': 'String'}])],
  1937                                     [{'U': 'CWUser', 'UL': 'String'}])],
  1938                      [self.ldap, self.system], None,
  1938                      [self.ldap, self.system], None,
  1939                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1939                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1940                      []),
  1940                      []),
  1941                     ('FetchStep', [('Any U,UL WHERE ((U identity 5) OR (EXISTS(U in_group G, G name IN("managers", "staff"), G is EGroup))) OR (EXISTS(U in_group H, 5 in_group H, NOT H name "users", H is EGroup)), U login UL, U is EUser',
  1941                     ('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',
  1942                                     [{'G': 'EGroup', 'H': 'EGroup', 'U': 'EUser', 'UL': 'String'}])],
  1942                                     [{'G': 'CWGroup', 'H': 'CWGroup', 'U': 'CWUser', 'UL': 'String'}])],
  1943                      [self.system],
  1943                      [self.system],
  1944                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1944                      {'U': 'table0.C0', 'U.login': 'table0.C1', 'UL': 'table0.C1'},
  1945                      {'U': 'table1.C0', 'U.login': 'table1.C1', 'UL': 'table1.C1'},
  1945                      {'U': 'table1.C0', 'U.login': 'table1.C1', 'UL': 'table1.C1'},
  1946                      []),
  1946                      []),
  1947                     ('OneFetchStep', [('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File',
  1947                     ('OneFetchStep', [('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File',
  1948                                        [{'B': 'File', 'U': 'EUser', 'UL': 'String'}])],
  1948                                        [{'B': 'File', 'U': 'CWUser', 'UL': 'String'}])],
  1949                      None, None, [self.system],
  1949                      None, None, [self.system],
  1950                      {'U': 'table1.C0', 'UL': 'table1.C1'},
  1950                      {'U': 'table1.C0', 'UL': 'table1.C1'},
  1951                      [])],
  1951                      [])],
  1952                    {'x': self.session.user.eid})
  1952                    {'x': self.session.user.eid})
  1953 
  1953