server/test/unittest_msplanner.py
changeset 1231 1457a545af03
parent 1230 232e16835fff
child 1398 5fe84a5f7035
equal deleted inserted replaced
1230:232e16835fff 1231:1457a545af03
   349                    {self.rql: {'X': s[0], 'AD': s[0]},
   349                    {self.rql: {'X': s[0], 'AD': s[0]},
   350                     self.system: {'X': s[0], 'AD': s[0], 'x': s[0]}},
   350                     self.system: {'X': s[0], 'AD': s[0], 'x': s[0]}},
   351                     True)
   351                     True)
   352 
   352 
   353     def test_simplified_var_3(self):
   353     def test_simplified_var_3(self):
   354         self.set_debug(True)
       
   355         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
   354         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
   356         repo._type_source_cache[999998] = ('State', 'cards', 999998)
   355         repo._type_source_cache[999998] = ('State', 'cards', 999998)
   357         self._test('Any S,T WHERE S eid %(s)s, N eid %(n)s, N type T, N is Note, S is State',
   356         self._test('Any S,T WHERE S eid %(s)s, N eid %(n)s, N type T, N is Note, S is State',
   358                    {'n': 999999, 's': 999998},
   357                    {'n': 999999, 's': 999998},
   359                    {self.rql: {'s': s[0], 'N': s[0]}}, False)
   358                    {self.rql: {'s': s[0], 'N': s[0]}}, False)
  1238                                        [{'S': 'State', 'SN': 'String'}])], 
  1237                                        [{'S': 'State', 'SN': 'String'}])], 
  1239                      None, None, [self.rql, self.system], {}, [])],
  1238                      None, None, [self.rql, self.system], {}, [])],
  1240                    {'x': 999999})
  1239                    {'x': 999999})
  1241 
  1240 
  1242     def test_not_relation_need_split(self):
  1241     def test_not_relation_need_split(self):
  1243         ueid = self.session.user.eid
       
  1244         self._test('Any SN WHERE NOT X in_state S, S name SN',
  1242         self._test('Any SN WHERE NOT X in_state S, S name SN',
  1245                    [('FetchStep', [('Any SN,S WHERE S name SN, S is State',
  1243                    [('FetchStep', [('Any SN,S WHERE S name SN, S is State',
  1246                                     [{'S': 'State', 'SN': 'String'}])],
  1244                                     [{'S': 'State', 'SN': 'String'}])],
  1247                      [self.rql, self.system], None, {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1245                      [self.rql, self.system], None, {'S': 'table0.C1', 'S.name': 'table0.C0', 'SN': 'table0.C0'},
  1248                      []),
  1246                      []),
  1469                    [('OneFetchStep', [('Any Y WHERE 999999 multisource_crossed_rel Y, Y is Note', [{'Y': 'Note'}])],
  1467                    [('OneFetchStep', [('Any Y WHERE 999999 multisource_crossed_rel Y, Y is Note', [{'Y': 'Note'}])],
  1470                       None, None, [self.rql, self.system], {}, [])
  1468                       None, None, [self.rql, self.system], {}, [])
  1471                     ],
  1469                     ],
  1472                    {'x': 999999,})
  1470                    {'x': 999999,})
  1473 
  1471 
  1474     def test_crossed_relation_eid_2_needattr_XXXFIXME(self):
  1472     def test_crossed_relation_eid_2_needattr(self):
  1475         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  1473         repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  1476         self._test('Any Y,T WHERE X eid %(x)s, X multisource_crossed_rel Y, Y type T',
  1474         self._test('Any Y,T WHERE X eid %(x)s, X multisource_crossed_rel Y, Y type T',                   
  1477                    [('FetchStep', [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])],
  1475                    [('FetchStep', [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])],
  1478                      [self.rql, self.system], None,
  1476                      [self.rql, self.system], None,
  1479                      {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'}, []),
  1477                      {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'}, []),
  1480                     ('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note',
  1478                     ('UnionStep', None, None,
  1481                                        [{'T': 'String', 'Y': 'Note'}])],
  1479                      [('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note',
  1482                      None, None, [self.rql, self.system],
  1480                                          [{'T': 'String', 'Y': 'Note'}])],
  1483                      {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'},
  1481                        None, None, [self.rql], None,
  1484                      [])
  1482                        []),
  1485                     ],
  1483                       ('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note',
       
  1484                                          [{'T': 'String', 'Y': 'Note'}])],
       
  1485                        None, None, [self.system],
       
  1486                        {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'},
       
  1487                        [])]
       
  1488                      )],
  1486                    {'x': 999999,})
  1489                    {'x': 999999,})
  1487 
  1490 
  1488     def test_crossed_relation_eid_not_1(self):
  1491     def test_crossed_relation_eid_not_1(self):
  1489         repo._type_source_cache[999999] = ('Note', 'system', 999999)
  1492         repo._type_source_cache[999999] = ('Note', 'system', 999999)
  1490         self._test('Any Y WHERE X eid %(x)s, NOT X multisource_crossed_rel Y',
  1493         self._test('Any Y WHERE X eid %(x)s, NOT X multisource_crossed_rel Y',
  1509                      [self.rql, self.system], None,
  1512                      [self.rql, self.system], None,
  1510                      {'T': 'table0.C1', 'X': 'table0.C0', 'X.type': 'table0.C1'}, []),
  1513                      {'T': 'table0.C1', 'X': 'table0.C0', 'X.type': 'table0.C1'}, []),
  1511                     ('FetchStep',  [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])],
  1514                     ('FetchStep',  [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])],
  1512                      [self.rql, self.system], None,
  1515                      [self.rql, self.system], None,
  1513                      {'T': 'table1.C1', 'Y': 'table1.C0', 'Y.type': 'table1.C1'},  []),
  1516                      {'T': 'table1.C1', 'Y': 'table1.C0', 'Y.type': 'table1.C1'},  []),
  1514                     ('OneFetchStep', [('Any X,Y,T WHERE X multisource_crossed_rel Y, Y type T, X type T, X is Note, Y is Note',
  1517                     ('UnionStep', None,  None,
  1515                                        [{'T': 'String', 'X': 'Note', 'Y': 'Note'}])],
  1518                      [('OneFetchStep', [('Any X,Y,T WHERE X multisource_crossed_rel Y, Y type T, X type T, X is Note, Y is Note',
  1516                      None, None, [self.rql, self.system],
  1519                                          [{'T': 'String', 'X': 'Note', 'Y': 'Note'}])],
  1517                      {'T': 'table1.C1', 'X': 'table0.C0', 'X.type': 'table0.C1',
  1520                        None, None, [self.rql], None,
  1518                       'Y': 'table1.C0', 'Y.type': 'table1.C1'},
  1521                        []),
  1519                     [])],
  1522                       ('OneFetchStep', [('Any X,Y,T WHERE X multisource_crossed_rel Y, Y type T, X type T, X is Note, Y is Note',
       
  1523                                          [{'T': 'String', 'X': 'Note', 'Y': 'Note'}])],
       
  1524                        None, None, [self.system],
       
  1525                        {'T': 'table1.C1', 'X': 'table0.C0', 'X.type': 'table0.C1',
       
  1526                         'Y': 'table1.C0', 'Y.type': 'table1.C1'},
       
  1527                        [])]
       
  1528                      )],
  1520                     {'x': 999999,})
  1529                     {'x': 999999,})
  1521         
  1530         
  1522     # edition queries tests ###################################################
  1531     # edition queries tests ###################################################
  1523 
  1532 
  1524     def test_insert_simplified_var_1(self):
  1533     def test_insert_simplified_var_1(self):
  1916         # come from the same source as user with eid 5).
  1925         # come from the same source as user with eid 5).
  1917         #
  1926         #
  1918         # IMO this is normal, unless we introduce a special case for the
  1927         # IMO this is normal, unless we introduce a special case for the
  1919         # identity relation. BUT I think it's better to leave it as is and to
  1928         # identity relation. BUT I think it's better to leave it as is and to
  1920         # explain constraint propagation rules, and so why this should be
  1929         # explain constraint propagation rules, and so why this should be
  1921         # wrapped in exists() is used in multi-source
  1930         # wrapped in exists() if used in multi-source
  1922         self.skip('take a look at me if you wish')
  1931         self.skip('take a look at me if you wish')
  1923         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 '
  1924                    '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 '
  1925                    'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
  1934                    'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) '
  1926                    '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 EUser)',
  2014                    {'x': 999999})
  2023                    {'x': 999999})
  2015 
  2024 
  2016     def test_version_crossed_depends_on_1(self):
  2025     def test_version_crossed_depends_on_1(self):
  2017         self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  2026         self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
  2018         self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
  2027         self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
  2019                        [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
  2028                    [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
  2020                                         [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2029                                     [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2021                          [self.rql, self.rql2, self.system],
  2030                      [self.rql, self.rql2, self.system],
  2022                          None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
  2031                      None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
  2023                                 'AE': 'table0.C2', 'X': 'table0.C0'},
  2032                             'AE': 'table0.C2', 'X': 'table0.C0'},
  2024                          []),
  2033                      []),
  2025                         ('FetchStep', [('Any X WHERE 999999 multisource_crossed_rel X, X is Note',
  2034                     ('UnionStep', None, None,
  2026                                         [{'X': 'Note'}])],
  2035                      [('OneFetchStep', [('Any X,AD,AE WHERE 999999 multisource_crossed_rel X, AD name AE, AD is State, X is Note',
  2027                          [self.rql, self.system], None, {'X': 'table1.C0'},
  2036                                          [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2028                          []),
  2037                        None, None, [self.rql], None,
  2029                         ('OneFetchStep', [('Any X,AD,AE WHERE AD name AE, AD is State, X is Note, X identity A',
  2038                        []),
  2030                                            [{'A': 'Note', 'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2039                       ('OneFetchStep', [('Any X,AD,AE WHERE 999999 multisource_crossed_rel X, AD name AE, AD is State, X is Note',
  2031                          None, None, [self.system],
  2040                                          [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2032                          {'A': 'table0.C0', 'AD': 'table0.C1', 'AD.name': 'table0.C2',
  2041                        None, None, [self.system],
  2033                           'AE': 'table0.C2', 'X': 'table1.C0'},
  2042                        {'AD': 'table0.C1', 'AD.name': 'table0.C2',
  2034                          [])],
  2043                         'AE': 'table0.C2', 'X': 'table0.C0'},
  2035                        {'x': 999999})
  2044                        [])]
       
  2045                      )],
       
  2046                    {'x': 999999})
  2036 
  2047 
  2037     def test_version_crossed_depends_on_2(self):
  2048     def test_version_crossed_depends_on_2(self):
  2038         self.set_debug(True)
       
  2039         self.repo._type_source_cache[999999] = ('Note', 'system', 999999)
  2049         self.repo._type_source_cache[999999] = ('Note', 'system', 999999)
  2040         self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
  2050         self._test('Any X,AD,AE WHERE E eid %(x)s, E multisource_crossed_rel X, X in_state AD, AD name AE',
  2041                    [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
  2051                    [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
  2042                                     [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2052                                     [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
  2043                      [self.rql, self.rql2, self.system],
  2053                      [self.rql, self.rql2, self.system],
  2049                      None, None, [self.system],
  2059                      None, None, [self.system],
  2050                      {'AD': 'table0.C1', 'AD.name': 'table0.C2', 'AE': 'table0.C2', 'X': 'table0.C0'},
  2060                      {'AD': 'table0.C1', 'AD.name': 'table0.C2', 'AE': 'table0.C2', 'X': 'table0.C0'},
  2051                      [])],
  2061                      [])],
  2052                    {'x': 999999})
  2062                    {'x': 999999})
  2053 
  2063 
  2054     def test_version_crossed_depends_on_3_XXXFIXME(self):
  2064     def test_version_crossed_depends_on_3(self):
  2055         self._test('Any X,AD,AE WHERE E multisource_crossed_rel X, X in_state AD, AD name AE, E is Note',
  2065         self._test('Any X,AD,AE WHERE E multisource_crossed_rel X, X in_state AD, AD name AE, E is Note',
  2056                    [])
  2066                    [('FetchStep', [('Any X,AD,AE WHERE X in_state AD, AD name AE, AD is State, X is Note',
       
  2067                                     [{'AD': 'State', 'AE': 'String', 'X': 'Note'}])],
       
  2068                      [self.rql, self.rql2, self.system],
       
  2069                      None, {'AD': 'table0.C1', 'AD.name': 'table0.C2',
       
  2070                             'AE': 'table0.C2', 'X': 'table0.C0'},
       
  2071                      []),
       
  2072                     ('FetchStep', [('Any E WHERE E is Note', [{'E': 'Note'}])],
       
  2073                      [self.rql, self.rql2, self.system],
       
  2074                      None, {'E': 'table1.C0'},
       
  2075                      []),
       
  2076                     ('UnionStep', None, None,
       
  2077                      [('OneFetchStep', [('Any X,AD,AE WHERE E multisource_crossed_rel X, AD name AE, AD is State, E is Note, X is Note',
       
  2078                                          [{'AD': 'State', 'AE': 'String', 'E': 'Note', 'X': 'Note'}])],
       
  2079                        None, None, [self.rql, self.rql2], None,
       
  2080                        []),
       
  2081                       ('OneFetchStep', [('Any X,AD,AE WHERE E multisource_crossed_rel X, AD name AE, AD is State, E is Note, X is Note',
       
  2082                                          [{'AD': 'State', 'AE': 'String', 'E': 'Note', 'X': 'Note'}])],
       
  2083                        None, None, [self.system],
       
  2084                        {'AD': 'table0.C1',
       
  2085                         'AD.name': 'table0.C2',
       
  2086                         'AE': 'table0.C2',
       
  2087                         'E': 'table1.C0',
       
  2088                         'X': 'table0.C0'},
       
  2089                        [])]
       
  2090                      )]
       
  2091                    )
  2057 
  2092 
  2058 
  2093 
  2059 if __name__ == '__main__':
  2094 if __name__ == '__main__':
  2060     from logilab.common.testlib import unittest_main
  2095     from logilab.common.testlib import unittest_main
  2061     unittest_main()
  2096     unittest_main()