server/test/unittest_msplanner.py
changeset 5590 a56eb02f9ce7
parent 5575 8a531340c3ef
parent 5582 3e133b29a1a4
child 5768 1e73a466aa69
equal deleted inserted replaced
5578:6b9fee0c5c42 5590:a56eb02f9ce7
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """
       
    19 
       
    20 """
       
    21 from cubicweb.devtools import init_test_database
    18 from cubicweb.devtools import init_test_database
    22 from cubicweb.devtools.repotest import BasePlannerTC, test_plan
    19 from cubicweb.devtools.repotest import BasePlannerTC, test_plan
    23 
    20 
    24 class _SetGenerator(object):
    21 class _SetGenerator(object):
    25     """singleton to easily create set using "s[0]" or "s[0,1,2]" for instance
    22     """singleton to easily create set using "s[0]" or "s[0,1,2]" for instance
   746                      None, None,
   743                      None, None,
   747                      [self.cards, self.system], {}, [])
   744                      [self.cards, self.system], {}, [])
   748                     ])
   745                     ])
   749 
   746 
   750     def test_not_identity(self):
   747     def test_not_identity(self):
   751         # both system and rql support all variables, can be
       
   752         self._test('Any X WHERE NOT X identity U, U eid %s' % self.session.user.eid,
   748         self._test('Any X WHERE NOT X identity U, U eid %s' % self.session.user.eid,
   753                    [('OneFetchStep',
   749                    [('OneFetchStep',
   754                      [('Any X WHERE NOT X identity 5, X is CWUser', [{'X': 'CWUser'}])],
   750                      [('Any X WHERE NOT X identity 5, X is CWUser', [{'X': 'CWUser'}])],
   755                      None, None,
   751                      None, None,
   756                      [self.ldap, self.system], {}, [])
   752                      [self.ldap, self.system], {}, [])
  1103                      [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
  1099                      [self.ldap, self.system], None, {'T2': 'table1.C0'}, []),
  1104                     ('FetchStep',
  1100                     ('FetchStep',
  1105                      [('Any L,X WHERE X login L, X is CWUser', [{'X': 'CWUser', 'L': 'String'}])],
  1101                      [('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'}, []),
  1102                      [self.ldap, self.system], None, {'X': 'table2.C1', 'X.login': 'table2.C0', 'L': 'table2.C0'}, []),
  1107                     ('OneFetchStep',
  1103                     ('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 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',
  1104                      [('Any G,L WHERE X in_group G, X login L, G name "managers", (EXISTS(X copain T, T login L, T is CWUser)) OR (EXISTS(X in_state S, S name "pascontent", NOT EXISTS(X copain T2), S is State)), G is CWGroup, T2 is CWUser, X is CWUser',
  1109                        [{'G': 'CWGroup', 'L': 'String', 'S': 'State', 'T': 'CWUser', 'T2': 'CWUser', 'X': 'CWUser'}])],
  1105                        [{'G': 'CWGroup', 'L': 'String', 'S': 'State', 'T': 'CWUser', 'T2': 'CWUser', 'X': 'CWUser'}])],
  1110                      None, None, [self.system],
  1106                      None, None, [self.system],
  1111                      {'T2': 'table1.C0', 'L': 'table2.C0',
  1107                      {'T2': 'table1.C0', 'L': 'table2.C0',
  1112                       'T': 'table0.C0', 'T.login': 'table0.C1', 'X': 'table2.C1', 'X.login': 'table2.C0'}, [])])
  1108                       'T': 'table0.C0', 'T.login': 'table0.C1', 'X': 'table2.C1', 'X.login': 'table2.C0'}, [])])
  1113 
  1109 
  1220         # all states (eg from both sources) which are not related to entity with the
  1216         # all states (eg from both sources) which are not related to entity with the
  1221         # given eid. The "NOT X in_state S, X eid %(x)s" expression is necessarily true
  1217         # given eid. The "NOT X in_state S, X eid %(x)s" expression is necessarily true
  1222         # in the source where %(x)s is not coming from and will be removed during rql
  1218         # in the source where %(x)s is not coming from and will be removed during rql
  1223         # generation for the external source
  1219         # generation for the external source
  1224         self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
  1220         self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
  1225                    [('OneFetchStep', [('Any SN WHERE NOT 5 in_state S, S name SN, S is State',
  1221                    [('OneFetchStep', [('Any SN WHERE NOT EXISTS(5 in_state S), S name SN, S is State',
  1226                                        [{'S': 'State', 'SN': 'String'}])],
  1222                                        [{'S': 'State', 'SN': 'String'}])],
  1227                      None, None, [self.cards, self.system], {}, [])],
  1223                      None, None, [self.cards, self.system], {}, [])],
  1228                    {'x': ueid})
  1224                    {'x': ueid})
  1229 
  1225 
  1230     def test_not_relation_no_split_external(self):
  1226     def test_not_relation_no_split_external(self):
  1231         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  1227         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  1232         # similar to the above test but with an eid coming from the external source.
  1228         # similar to the above test but with an eid coming from the external source.
  1233         # the same plan may be used, since we won't find any record in the system source
  1229         # the same plan may be used, since we won't find any record in the system source
  1234         # linking 9999999 to a state
  1230         # linking 9999999 to a state
  1235         self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
  1231         self._test('Any SN WHERE NOT X in_state S, X eid %(x)s, S name SN',
  1236                    [('OneFetchStep', [('Any SN WHERE NOT 999999 in_state S, S name SN, S is State',
  1232                    [('OneFetchStep', [('Any SN WHERE NOT EXISTS(999999 in_state S), S name SN, S is State',
  1237                                        [{'S': 'State', 'SN': 'String'}])],
  1233                                        [{'S': 'State', 'SN': 'String'}])],
  1238                      None, None, [self.cards, self.system], {}, [])],
  1234                      None, None, [self.cards, self.system], {}, [])],
  1239                    {'x': 999999})
  1235                    {'x': 999999})
  1240 
  1236 
  1241     def test_not_relation_need_split(self):
  1237     def test_not_relation_need_split(self):
  1244                                     [{'S': 'State', 'SN': 'String'}])],
  1240                                     [{'S': 'State', 'SN': 'String'}])],
  1245                      [self.cards, self.system], None, {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1241                      [self.cards, self.system], None, {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1246                      []),
  1242                      []),
  1247                     ('IntersectStep', None, None,
  1243                     ('IntersectStep', None, None,
  1248                      [('OneFetchStep',
  1244                      [('OneFetchStep',
  1249                        [('Any SN WHERE NOT X in_state S, S name SN, S is State, X is Note',
  1245                        [('Any SN WHERE NOT EXISTS(X in_state S, X is Note), S name SN, S is State',
  1250                          [{'S': 'State', 'SN': 'String', 'X': 'Note'}])],
  1246                          [{'S': 'State', 'SN': 'String', 'X': 'Note'}])],
  1251                        None, None, [self.cards, self.system], {},
  1247                        None, None, [self.cards, self.system], {},
  1252                        []),
  1248                        []),
  1253                       ('OneFetchStep',
  1249                       ('OneFetchStep',
  1254                        [('Any SN WHERE NOT X in_state S, S name SN, S is State, X is IN(Affaire, CWUser)',
  1250                        [('Any SN WHERE NOT EXISTS(X in_state S, X is IN(Affaire, CWUser)), S name SN, S is State',
  1255                          [{'S': 'State', 'SN': 'String', 'X': 'Affaire'},
  1251                          [{'S': 'State', 'SN': 'String', 'X': 'Affaire'},
  1256                           {'S': 'State', 'SN': 'String', 'X': 'CWUser'}])],
  1252                           {'S': 'State', 'SN': 'String', 'X': 'CWUser'}])],
  1257                        None, None, [self.system], {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1253                        None, None, [self.system], {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1258                        []),]
  1254                        []),]
  1259                      )])
  1255                      )])
  1503     def test_crossed_relation_eid_not_1(self):
  1499     def test_crossed_relation_eid_not_1(self):
  1504         repo._type_source_cache[999999] = ('Note', 'system', 999999)
  1500         repo._type_source_cache[999999] = ('Note', 'system', 999999)
  1505         self._test('Any Y WHERE X eid %(x)s, NOT X multisource_crossed_rel Y',
  1501         self._test('Any Y WHERE X eid %(x)s, NOT X multisource_crossed_rel Y',
  1506                    [('FetchStep', [('Any Y WHERE Y is Note', [{'Y': 'Note'}])],
  1502                    [('FetchStep', [('Any Y WHERE Y is Note', [{'Y': 'Note'}])],
  1507                      [self.cards, self.system], None, {'Y': 'table0.C0'}, []),
  1503                      [self.cards, self.system], None, {'Y': 'table0.C0'}, []),
  1508                     ('OneFetchStep', [('Any Y WHERE NOT 999999 multisource_crossed_rel Y, Y is Note',
  1504                     ('OneFetchStep', [('Any Y WHERE NOT EXISTS(999999 multisource_crossed_rel Y), Y is Note',
  1509                                        [{'Y': 'Note'}])],
  1505                                        [{'Y': 'Note'}])],
  1510                      None, None, [self.system],
  1506                      None, None, [self.system],
  1511                      {'Y': 'table0.C0'},  [])],
  1507                      {'Y': 'table0.C0'},  [])],
  1512                    {'x': 999999,})
  1508                    {'x': 999999,})
  1513 
  1509 
  1631 
  1627 
  1632     def test_delete_entity1(self):
  1628     def test_delete_entity1(self):
  1633         repo._type_source_cache[999999] = ('Note', 'system', 999999)
  1629         repo._type_source_cache[999999] = ('Note', 'system', 999999)
  1634         self._test('DELETE Note X WHERE X eid %(x)s, NOT Y multisource_rel X',
  1630         self._test('DELETE Note X WHERE X eid %(x)s, NOT Y multisource_rel X',
  1635                    [('DeleteEntitiesStep',
  1631                    [('DeleteEntitiesStep',
  1636                      [('OneFetchStep', [('Any 999999 WHERE NOT Y multisource_rel 999999, Y is IN(Card, Note)',
  1632                      [('OneFetchStep', [('Any 999999 WHERE NOT EXISTS(Y multisource_rel 999999), Y is IN(Card, Note)',
  1637                                          [{'Y': 'Card'}, {'Y': 'Note'}])],
  1633                                          [{'Y': 'Card'}, {'Y': 'Note'}])],
  1638                        None, None, [self.system], {}, [])
  1634                        None, None, [self.system], {}, [])
  1639                       ])
  1635                       ])
  1640                     ],
  1636                     ],
  1641                    {'x': 999999})
  1637                    {'x': 999999})
  2184 
  2180 
  2185     def test_fully_simplified_extsource(self):
  2181     def test_fully_simplified_extsource(self):
  2186         self.repo._type_source_cache[999998] = ('Note', 'vcs', 999998)
  2182         self.repo._type_source_cache[999998] = ('Note', 'vcs', 999998)
  2187         self.repo._type_source_cache[999999] = ('Note', 'vcs', 999999)
  2183         self.repo._type_source_cache[999999] = ('Note', 'vcs', 999999)
  2188         self._test('Any X, Y WHERE NOT X multisource_rel Y, X eid 999998, Y eid 999999',
  2184         self._test('Any X, Y WHERE NOT X multisource_rel Y, X eid 999998, Y eid 999999',
  2189                    [('OneFetchStep', [('Any 999998,999999 WHERE NOT 999998 multisource_rel 999999', [{}])],
  2185                    [('OneFetchStep', [('Any 999998,999999 WHERE NOT EXISTS(999998 multisource_rel 999999)', [{}])],
  2190                      None, None, [self.vcs], {}, [])
  2186                      None, None, [self.vcs], {}, [])
  2191                     ])
  2187                     ])
  2192 
  2188 
  2193     def test_nonregr_fully_simplified_extsource(self):
  2189     def test_nonregr_fully_simplified_extsource(self):
  2194         self.repo._type_source_cache[999998] = ('Note', 'vcs', 999998)
  2190         self.repo._type_source_cache[999998] = ('Note', 'vcs', 999998)