diff -r 27c47d239739 -r f76599a96238 server/test/unittest_msplanner.py --- a/server/test/unittest_msplanner.py Thu Aug 12 10:12:52 2010 +0200 +++ b/server/test/unittest_msplanner.py Wed Aug 25 09:43:12 2010 +0200 @@ -15,6 +15,9 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . + +from logilab.common.decorators import clear_cache + from cubicweb.devtools import init_test_database from cubicweb.devtools.repotest import BasePlannerTC, test_plan @@ -45,7 +48,7 @@ uri = 'ccc' support_entities = {'Card': True, 'Note': True, 'State': True} support_relations = {'in_state': True, 'multisource_rel': True, 'multisource_inlined_rel': True, - 'multisource_crossed_rel': True} + 'multisource_crossed_rel': True,} dont_cross_relations = set(('fiche', 'state_of')) cross_relations = set(('multisource_crossed_rel',)) @@ -364,6 +367,8 @@ def setUp(self): BaseMSPlannerTC.setUp(self) self.planner = MSPlanner(self.o.schema, self.repo.vreg.rqlhelper) + for cached in ('rel_type_sources', 'can_cross_relation', 'is_multi_sources_relation'): + clear_cache(self.repo, cached) _test = test_plan @@ -1026,7 +1031,7 @@ [self.cards, self.system], None, {'X': 'table1.C0', 'X.title': 'table1.C1', 'XT': 'table1.C1'}, []), ('OneFetchStep', [('Any X,XT,U WHERE X owned_by U?, X title XT, X is Card', - [{'X': 'Card', 'XT': 'String'}])], + [{'X': 'Card', 'U': 'CWUser', 'XT': 'String'}])], None, None, [self.system], {'L': 'table0.C1', 'U': 'table0.C0', 'X': 'table1.C0', @@ -1436,7 +1441,7 @@ ('FetchStep', [('Any B,C WHERE B login C, B is CWUser', [{'B': 'CWUser', 'C': 'String'}])], [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []), - ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser', + ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser, A is IN(Bookmark, Tag)', [{'A': 'Bookmark', 'B': 'CWUser', 'C': 'String'}, {'A': 'Tag', 'B': 'CWUser', 'C': 'String'}])], None, None, [self.system], @@ -1470,7 +1475,7 @@ ('FetchStep', [('Any B,C WHERE B login C, B is CWUser', [{'B': 'CWUser', 'C': 'String'}])], [self.ldap, self.system], None, {'B': 'table1.C0', 'B.login': 'table1.C1', 'C': 'table1.C1'}, []), - ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser', + ('OneFetchStep', [('DISTINCT Any B,C ORDERBY C WHERE A created_by B, B login C, EXISTS(B owned_by 5), B is CWUser, A is IN(Card, Tag)', [{'A': 'Card', 'B': 'CWUser', 'C': 'String'}, {'A': 'Tag', 'B': 'CWUser', 'C': 'String'}])], None, None, [self.system], @@ -1536,20 +1541,11 @@ def test_crossed_relation_eid_2_needattr(self): repo._type_source_cache[999999] = ('Note', 'cards', 999999) self._test('Any Y,T WHERE X eid %(x)s, X multisource_crossed_rel Y, Y type T', - [('FetchStep', [('Any Y,T WHERE Y type T, Y is Note', [{'T': 'String', 'Y': 'Note'}])], - [self.cards, self.system], None, - {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'}, []), - ('UnionStep', None, None, - [('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note', - [{'T': 'String', 'Y': 'Note'}])], - None, None, [self.cards], None, - []), - ('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note', - [{'T': 'String', 'Y': 'Note'}])], - None, None, [self.system], - {'T': 'table0.C1', 'Y': 'table0.C0', 'Y.type': 'table0.C1'}, - [])] - )], + [('OneFetchStep', [('Any Y,T WHERE 999999 multisource_crossed_rel Y, Y type T, Y is Note', + [{'T': 'String', 'Y': 'Note'}])], + None, None, [self.cards, self.system], {}, + []), + ], {'x': 999999,}) def test_crossed_relation_eid_not_1(self): @@ -1757,6 +1753,54 @@ # ]), # ]) + def test_ldap_user_related_to_invariant_and_dont_cross_rel(self): + self.repo._type_source_cache[999999] = ('Note', 'cards', 999999) + self.cards.dont_cross_relations.add('created_by') + try: + self._test('Any X,XL WHERE E eid %(x)s, E created_by X, X login XL', + [('FetchStep', [('Any X,XL WHERE X login XL, X is CWUser', + [{'X': 'CWUser', 'XL': 'String'}])], + [self.ldap, self.system], None, + {'X': 'table0.C0', 'X.login': 'table0.C1', 'XL': 'table0.C1'}, + []), + ('OneFetchStep', + [('Any X,XL WHERE 999999 created_by X, X login XL, X is CWUser', + [{'X': 'CWUser', 'XL': 'String'}])], + None, None, + [self.system], + {'X': 'table0.C0', 'X.login': 'table0.C1', 'XL': 'table0.C1'}, + [])], + {'x': 999999}) + finally: + self.cards.dont_cross_relations.remove('created_by') + + def test_ambigous_cross_relation(self): + self.repo._type_source_cache[999999] = ('Note', 'cards', 999999) + self.cards.support_relations['see_also'] = True + self.cards.cross_relations.add('see_also') + try: + self._test('Any X,AA ORDERBY AA WHERE E eid %(x)s, E see_also X, X modification_date AA', + [('AggrStep', + 'SELECT table0.C0, table0.C1 FROM table0 ORDER BY table0.C1', + None, + [('FetchStep', + [('Any X,AA WHERE 999999 see_also X, X modification_date AA, X is Note', + [{'AA': 'Datetime', 'X': 'Note'}])], [self.cards, self.system], {}, + {'AA': 'table0.C1', 'X': 'table0.C0', + 'X.modification_date': 'table0.C1'}, + []), + ('FetchStep', + [('Any X,AA WHERE 999999 see_also X, X modification_date AA, X is Bookmark', + [{'AA': 'Datetime', 'X': 'Bookmark'}])], + [self.system], {}, + {'AA': 'table0.C1', 'X': 'table0.C0', + 'X.modification_date': 'table0.C1'}, + [])])], + {'x': 999999}) + finally: + del self.cards.support_relations['see_also'] + self.cards.cross_relations.remove('see_also') + # non regression tests #################################################### def test_nonregr1(self): @@ -1873,11 +1917,16 @@ def test_nonregr8(self): repo._type_source_cache[999999] = ('Note', 'cards', 999999) self._test('Any X,Z WHERE X eid %(x)s, X multisource_rel Y, Z concerne X', - [('FetchStep', [('Any WHERE 999999 multisource_rel Y, Y is Note', [{'Y': 'Note'}])], - [self.cards], None, {}, []), + [('FetchStep', [('Any 999999 WHERE 999999 multisource_rel Y, Y is Note', + [{'Y': 'Note'}])], + [self.cards], + None, {u'%(x)s': 'table0.C0'}, + []), ('OneFetchStep', [('Any 999999,Z WHERE Z concerne 999999, Z is Affaire', [{'Z': 'Affaire'}])], - None, None, [self.system], {}, [])], + None, None, [self.system], + {u'%(x)s': 'table0.C0'}, []), + ], {'x': 999999}) def test_nonregr9(self):