server/test/unittest_rqlannotation.py
branchtls-sprint
changeset 1802 d628defebc17
parent 1398 5fe84a5f7035
child 1977 606923dff11b
equal deleted inserted replaced
1801:672acc730ce5 1802:d628defebc17
     7 
     7 
     8 repo, cnx = init_test_database('sqlite')
     8 repo, cnx = init_test_database('sqlite')
     9 
     9 
    10 class SQLGenAnnotatorTC(BaseQuerierTC):
    10 class SQLGenAnnotatorTC(BaseQuerierTC):
    11     repo = repo
    11     repo = repo
    12     
    12 
    13     def get_max_eid(self):
    13     def get_max_eid(self):
    14         # no need for cleanup here
    14         # no need for cleanup here
    15         return None
    15         return None
    16     def cleanup(self):
    16     def cleanup(self):
    17         # no need for cleanup here
    17         # no need for cleanup here
    18         pass
    18         pass
    19                 
    19 
    20     def test_0_1(self):        
    20     def test_0_1(self):
    21         rqlst = self._prepare('Any SEN,RN,OEN WHERE X from_entity SE, SE eid 44, X relation_type R, R eid 139, X to_entity OE, OE eid 42, R name RN, SE name SEN, OE name OEN')
    21         rqlst = self._prepare('Any SEN,RN,OEN WHERE X from_entity SE, SE eid 44, X relation_type R, R eid 139, X to_entity OE, OE eid 42, R name RN, SE name SEN, OE name OEN')
    22         self.assertEquals(rqlst.defined_vars['SE']._q_invariant, False)
    22         self.assertEquals(rqlst.defined_vars['SE']._q_invariant, False)
    23         self.assertEquals(rqlst.defined_vars['OE']._q_invariant, False)
    23         self.assertEquals(rqlst.defined_vars['OE']._q_invariant, False)
    24         self.assertEquals(rqlst.defined_vars['R']._q_invariant, False)
    24         self.assertEquals(rqlst.defined_vars['R']._q_invariant, False)
    25         self.assertEquals(rqlst.defined_vars['SE'].stinfo['attrvar'], None)
    25         self.assertEquals(rqlst.defined_vars['SE'].stinfo['attrvar'], None)
    26         self.assertEquals(rqlst.defined_vars['OE'].stinfo['attrvar'], None)
    26         self.assertEquals(rqlst.defined_vars['OE'].stinfo['attrvar'], None)
    27         self.assertEquals(rqlst.defined_vars['R'].stinfo['attrvar'], None)
    27         self.assertEquals(rqlst.defined_vars['R'].stinfo['attrvar'], None)
    28         
    28 
    29     def test_0_2(self):        
    29     def test_0_2(self):
    30         rqlst = self._prepare('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P')
    30         rqlst = self._prepare('Any O WHERE NOT S ecrit_par O, S eid 1, S inline1 P, O inline2 P')
    31         self.assertEquals(rqlst.defined_vars['P']._q_invariant, True)
    31         self.assertEquals(rqlst.defined_vars['P']._q_invariant, True)
    32         self.assertEquals(rqlst.defined_vars['O'].stinfo['attrvar'], None)
    32         self.assertEquals(rqlst.defined_vars['O'].stinfo['attrvar'], None)
    33 
    33 
    34     def test_0_4(self):        
    34     def test_0_4(self):
    35         rqlst = self._prepare('Any A,B,C WHERE A eid 12,A comment B, A ?wf_info_for C')
    35         rqlst = self._prepare('Any A,B,C WHERE A eid 12,A comment B, A ?wf_info_for C')
    36         self.assertEquals(rqlst.defined_vars['A']._q_invariant, False)
    36         self.assertEquals(rqlst.defined_vars['A']._q_invariant, False)
    37         self.assert_(rqlst.defined_vars['B'].stinfo['attrvar'])
    37         self.assert_(rqlst.defined_vars['B'].stinfo['attrvar'])
    38         self.assertEquals(rqlst.defined_vars['C']._q_invariant, False)
    38         self.assertEquals(rqlst.defined_vars['C']._q_invariant, False)
    39         self.assertEquals(rqlst.solutions, [{'A': 'TrInfo', 'B': 'String', 'C': 'Affaire'},
    39         self.assertEquals(rqlst.solutions, [{'A': 'TrInfo', 'B': 'String', 'C': 'Affaire'},
    40                                       {'A': 'TrInfo', 'B': 'String', 'C': 'CWUser'},
    40                                       {'A': 'TrInfo', 'B': 'String', 'C': 'CWUser'},
    41                                       {'A': 'TrInfo', 'B': 'String', 'C': 'Note'}])
    41                                       {'A': 'TrInfo', 'B': 'String', 'C': 'Note'}])
    42 
    42 
    43     def test_0_5(self):        
    43     def test_0_5(self):
    44         rqlst = self._prepare('Any P WHERE N ecrit_par P, N eid 0')
    44         rqlst = self._prepare('Any P WHERE N ecrit_par P, N eid 0')
    45         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
    45         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
    46         self.assertEquals(rqlst.defined_vars['P']._q_invariant, True)
    46         self.assertEquals(rqlst.defined_vars['P']._q_invariant, True)
    47 
    47 
    48     def test_0_6(self):        
    48     def test_0_6(self):
    49         rqlst = self._prepare('Any P WHERE NOT N ecrit_par P, N eid 512')
    49         rqlst = self._prepare('Any P WHERE NOT N ecrit_par P, N eid 512')
    50         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
    50         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
    51 
    51 
    52     def test_0_7(self):        
    52     def test_0_7(self):
    53         rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE')
    53         rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE')
    54         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    54         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    55         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
    55         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
    56         self.assert_(rqlst.defined_vars['XE'].stinfo['attrvar'])
    56         self.assert_(rqlst.defined_vars['XE'].stinfo['attrvar'])
    57 
    57 
    58     def test_0_8(self):        
    58     def test_0_8(self):
    59         rqlst = self._prepare('Any P WHERE X eid 0, NOT X connait P')
    59         rqlst = self._prepare('Any P WHERE X eid 0, NOT X connait P')
    60         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
    60         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
    61         #self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
    61         #self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
    62         self.assertEquals(len(rqlst.solutions), 1, rqlst.solutions)
    62         self.assertEquals(len(rqlst.solutions), 1, rqlst.solutions)
    63 
    63 
    64     def test_0_10(self):        
    64     def test_0_10(self):
    65         rqlst = self._prepare('Any X WHERE X concerne Y, Y is Note')
    65         rqlst = self._prepare('Any X WHERE X concerne Y, Y is Note')
    66         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
    66         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
    67         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
    67         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
    68 
    68 
    69     def test_0_11(self):
    69     def test_0_11(self):
    70         rqlst = self._prepare('Any X WHERE X todo_by Y, X is Affaire')
    70         rqlst = self._prepare('Any X WHERE X todo_by Y, X is Affaire')
    71         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    71         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    72         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
    72         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
    73 
    73 
    74     def test_0_12(self):        
    74     def test_0_12(self):
    75         rqlst = self._prepare('Personne P WHERE P concerne A, A concerne S, S nom "Logilab"')
    75         rqlst = self._prepare('Personne P WHERE P concerne A, A concerne S, S nom "Logilab"')
    76         self.assertEquals(rqlst.defined_vars['P']._q_invariant, True)
    76         self.assertEquals(rqlst.defined_vars['P']._q_invariant, True)
    77         self.assertEquals(rqlst.defined_vars['A']._q_invariant, True)
    77         self.assertEquals(rqlst.defined_vars['A']._q_invariant, True)
    78         self.assertEquals(rqlst.defined_vars['S']._q_invariant, False)
    78         self.assertEquals(rqlst.defined_vars['S']._q_invariant, False)
    79         
    79 
    80     def test_1_0(self):
    80     def test_1_0(self):
    81         rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6')
    81         rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid 6')
    82         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
    82         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
    83                 
    83 
    84     def test_1_1(self):
    84     def test_1_1(self):
    85         rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid IN (6,7)')
    85         rqlst = self._prepare('Any X,Y WHERE X created_by Y, X eid 5, NOT Y eid IN (6,7)')
    86         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
    86         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
    87                 
    87 
    88     def test_2(self):
    88     def test_2(self):
    89         rqlst = self._prepare('Any X WHERE X identity Y, Y eid 1')
    89         rqlst = self._prepare('Any X WHERE X identity Y, Y eid 1')
    90         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    90         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    91         
    91 
    92     def test_7(self):
    92     def test_7(self):
    93         rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE')
    93         rqlst = self._prepare('Personne X,Y where X nom NX, Y nom NX, X eid XE, not Y eid XE')
    94         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    94         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    95         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
    95         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
    96         
    96 
    97     def test_optional_inlined(self):
    97     def test_optional_inlined(self):
    98         rqlst = self._prepare('Any X,S where X from_state S?')
    98         rqlst = self._prepare('Any X,S where X from_state S?')
    99         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
    99         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   100         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   100         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   101                 
   101 
   102     def test_optional_inlined_2(self):
   102     def test_optional_inlined_2(self):
   103         rqlst = self._prepare('Any N,A WHERE N? inline1 A')
   103         rqlst = self._prepare('Any N,A WHERE N? inline1 A')
   104         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
   104         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
   105         self.assertEquals(rqlst.defined_vars['A']._q_invariant, False)
   105         self.assertEquals(rqlst.defined_vars['A']._q_invariant, False)
   106         
   106 
   107     def test_optional_1(self):
   107     def test_optional_1(self):
   108         rqlst = self._prepare('Any X,S WHERE X travaille S?')
   108         rqlst = self._prepare('Any X,S WHERE X travaille S?')
   109         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   109         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   110         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   110         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   111         
   111 
   112     def test_greater_eid(self):
   112     def test_greater_eid(self):
   113         rqlst = self._prepare('Any X WHERE X eid > 5')
   113         rqlst = self._prepare('Any X WHERE X eid > 5')
   114         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   114         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   115         
   115 
   116     def test_greater_eid_typed(self):
   116     def test_greater_eid_typed(self):
   117         rqlst = self._prepare('Any X WHERE X eid > 5, X is Note')
   117         rqlst = self._prepare('Any X WHERE X eid > 5, X is Note')
   118         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   118         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   119         
   119 
   120     def test_max_eid(self):
   120     def test_max_eid(self):
   121         rqlst = self._prepare('Any MAX(X)')
   121         rqlst = self._prepare('Any MAX(X)')
   122         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   122         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   123         
   123 
   124     def test_max_eid_typed(self):
   124     def test_max_eid_typed(self):
   125         rqlst = self._prepare('Any MAX(X) WHERE X is Note')
   125         rqlst = self._prepare('Any MAX(X) WHERE X is Note')
   126         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   126         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   127         
   127 
   128     def test_all_entities(self):
   128     def test_all_entities(self):
   129         rqlst = self._prepare('Any X')
   129         rqlst = self._prepare('Any X')
   130         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   130         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   131         
   131 
   132     def test_all_typed_entity(self):
   132     def test_all_typed_entity(self):
   133         rqlst = self._prepare('Any X WHERE X is Note')
   133         rqlst = self._prepare('Any X WHERE X is Note')
   134         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   134         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   135         
   135 
   136     def test_has_text_1(self):
   136     def test_has_text_1(self):
   137         rqlst = self._prepare('Any X WHERE X has_text "toto tata"')
   137         rqlst = self._prepare('Any X WHERE X has_text "toto tata"')
   138         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   138         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   139         self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'has_text')
   139         self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'has_text')
   140         
   140 
   141     def test_has_text_2(self):
   141     def test_has_text_2(self):
   142         rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"')
   142         rqlst = self._prepare('Any X WHERE X is Personne, X has_text "coucou"')
   143         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   143         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   144         self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'has_text')
   144         self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'has_text')
   145         
   145 
   146     def test_not_relation_1(self):
   146     def test_not_relation_1(self):
   147         # P can't be invariant since deambiguification caused by "NOT X require_permission P"
   147         # P can't be invariant since deambiguification caused by "NOT X require_permission P"
   148         # is not considered by generated sql (NOT EXISTS(...))
   148         # is not considered by generated sql (NOT EXISTS(...))
   149         rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P')
   149         rqlst = self._prepare('Any P,G WHERE P require_group G, NOT X require_permission P')
   150         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
   150         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
   151         self.assertEquals(rqlst.defined_vars['G']._q_invariant, True)
   151         self.assertEquals(rqlst.defined_vars['G']._q_invariant, True)
   152         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   152         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   153         
   153 
   154     def test_not_relation_2(self):
   154     def test_not_relation_2(self):
   155         rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State')
   155         rqlst = self._prepare('TrInfo X WHERE X eid 2, NOT X from_state Y, Y is State')
   156         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   156         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   157         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   157         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   158                 
   158 
   159     def test_not_relation_3(self):
   159     def test_not_relation_3(self):
   160         rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)')
   160         rqlst = self._prepare('Any X, Y WHERE X eid 1, Y eid in (2, 3)')
   161         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   161         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   162                 
   162 
   163     def test_not_relation_4_1(self):
   163     def test_not_relation_4_1(self):
   164         rqlst = self._prepare('Note X WHERE NOT Y evaluee X')
   164         rqlst = self._prepare('Note X WHERE NOT Y evaluee X')
   165         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   165         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   166         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   166         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   167         
   167 
   168     def test_not_relation_4_2(self):
   168     def test_not_relation_4_2(self):
   169         rqlst = self._prepare('Any X WHERE NOT Y evaluee X')
   169         rqlst = self._prepare('Any X WHERE NOT Y evaluee X')
   170         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   170         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   171         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   171         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   172         
   172 
   173     def test_not_relation_4_3(self):
   173     def test_not_relation_4_3(self):
   174         rqlst = self._prepare('Any Y WHERE NOT Y evaluee X')
   174         rqlst = self._prepare('Any Y WHERE NOT Y evaluee X')
   175         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   175         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   176         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   176         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   177         
   177 
   178     def test_not_relation_4_4(self):
   178     def test_not_relation_4_4(self):
   179         rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser')
   179         rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y is CWUser')
   180         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   180         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   181         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   181         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   182 
   182 
   183     def test_not_relation_4_5(self):
   183     def test_not_relation_4_5(self):
   184         rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid)
   184         rqlst = self._prepare('Any X WHERE NOT Y evaluee X, Y eid %s, X is Note' % self.ueid)
   185         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   185         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   186         self.assertEquals(rqlst.solutions, [{'X': 'Note'}])
   186         self.assertEquals(rqlst.solutions, [{'X': 'Note'}])
   187         
   187 
   188     def test_not_relation_5_1(self):
   188     def test_not_relation_5_1(self):
   189         rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y')
   189         rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT X read_permission Y')
   190         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   190         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   191         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   191         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   192 
   192 
   199         rqlst = self._prepare('Personne P where NOT P concerne A')
   199         rqlst = self._prepare('Personne P where NOT P concerne A')
   200         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
   200         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
   201         self.assertEquals(rqlst.defined_vars['A']._q_invariant, True)
   201         self.assertEquals(rqlst.defined_vars['A']._q_invariant, True)
   202 
   202 
   203     def test_not_relation_7(self):
   203     def test_not_relation_7(self):
   204         rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U') 
   204         rqlst = self._prepare('Any K,V WHERE P is CWProperty, P pkey K, P value V, NOT P for_user U')
   205         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
   205         self.assertEquals(rqlst.defined_vars['P']._q_invariant, False)
   206         self.assertEquals(rqlst.defined_vars['U']._q_invariant, True)
   206         self.assertEquals(rqlst.defined_vars['U']._q_invariant, True)
   207        
   207 
   208     def test_exists_1(self):        
   208     def test_exists_1(self):
   209         rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)')
   209         rqlst = self._prepare('Any U WHERE U eid IN (1,2), EXISTS(X owned_by U)')
   210         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   210         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   211         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   211         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   212        
   212 
   213     def test_exists_2(self):        
   213     def test_exists_2(self):
   214         rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)')
   214         rqlst = self._prepare('Any U WHERE EXISTS(U eid IN (1,2), X owned_by U)')
   215         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   215         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   216         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   216         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   217 
   217 
   218     def test_exists_3(self):        
   218     def test_exists_3(self):
   219         rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_by U)')
   219         rqlst = self._prepare('Any U WHERE EXISTS(X owned_by U, X bookmarked_by U)')
   220         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   220         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   221         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   221         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   222         
   222 
   223     def test_exists_4(self):
   223     def test_exists_4(self):
   224         rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)')
   224         rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)')
   225         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   225         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   226         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   226         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   227         
   227 
   228     def test_exists_5(self):
   228     def test_exists_5(self):
   229         rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)')
   229         rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), EXISTS(X read_permission Y)')
   230         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   230         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   231         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   231         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, True)
   232 
   232 
   233     def test_not_exists_1(self):        
   233     def test_not_exists_1(self):
   234         rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)')
   234         rqlst = self._prepare('Any U WHERE NOT EXISTS(X owned_by U, X bookmarked_by U)')
   235         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   235         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   236         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)        
   236         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   237 
   237 
   238     def test_not_exists_2(self):        
   238     def test_not_exists_2(self):
   239         rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)')
   239         rqlst = self._prepare('Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)')
   240         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   240         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   241 
   241 
   242     def test_not_exists_distinct_1(self):        
   242     def test_not_exists_distinct_1(self):
   243         rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)')
   243         rqlst = self._prepare('DISTINCT Any X,Y WHERE X name "CWGroup", Y eid IN(1, 2, 3), NOT EXISTS(X read_permission Y)')
   244         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   244         self.assertEquals(rqlst.defined_vars['Y']._q_invariant, False)
   245         
   245 
   246     def test_or_1(self):        
   246     def test_or_1(self):
   247         rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13')
   247         rqlst = self._prepare('Any X WHERE X concerne B OR C concerne X, B eid 12, C eid 13')
   248         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   248         self.assertEquals(rqlst.defined_vars['X']._q_invariant, False)
   249 
   249 
   250     def test_or_2(self):        
   250     def test_or_2(self):
   251         rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13')
   251         rqlst = self._prepare('Any X WHERE X created_by U, X concerne B OR C concerne X, B eid 12, C eid 13')
   252         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   252         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   253         self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) 
   253         self.assertEquals(rqlst.defined_vars['U']._q_invariant, True)
   254         self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by')
   254         self.assertEquals(rqlst.defined_vars['X'].stinfo['principal'].r_type, 'created_by')
   255 
   255 
   256     def test_or_3(self):        
   256     def test_or_3(self):
   257         rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)')
   257         rqlst = self._prepare('Any N WHERE A evaluee N or EXISTS(N todo_by U)')
   258         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
   258         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
   259         self.assertEquals(rqlst.defined_vars['A']._q_invariant, True) 
   259         self.assertEquals(rqlst.defined_vars['A']._q_invariant, True)
   260         self.assertEquals(rqlst.defined_vars['U']._q_invariant, True) 
   260         self.assertEquals(rqlst.defined_vars['U']._q_invariant, True)
   261         
   261 
   262     def test_or_exists_1(self):
   262     def test_or_exists_1(self):
   263         # query generated by security rewriting
   263         # query generated by security rewriting
   264         rqlst = self._prepare('DISTINCT Any A,S WHERE A is Affaire, S nom "chouette", S is IN(Division, Societe, SubDivision),'
   264         rqlst = self._prepare('DISTINCT Any A,S WHERE A is Affaire, S nom "chouette", S is IN(Division, Societe, SubDivision),'
   265                               '(EXISTS(A owned_by %(D)s)) '
   265                               '(EXISTS(A owned_by %(D)s)) '
   266                               'OR ((((EXISTS(E concerne C?, C owned_by %(D)s, A identity E, C is Note, E is Affaire)) '
   266                               'OR ((((EXISTS(E concerne C?, C owned_by %(D)s, A identity E, C is Note, E is Affaire)) '
   268                               'OR (EXISTS(J concerne G?, G owned_by %(D)s, G is SubDivision, A identity J, J is Affaire))) '
   268                               'OR (EXISTS(J concerne G?, G owned_by %(D)s, G is SubDivision, A identity J, J is Affaire))) '
   269                               'OR (EXISTS(K concerne F?, F owned_by %(D)s, F is Division, A identity K, K is Affaire)))')
   269                               'OR (EXISTS(K concerne F?, F owned_by %(D)s, F is Division, A identity K, K is Affaire)))')
   270         self.assertEquals(rqlst.defined_vars['A']._q_invariant, False)
   270         self.assertEquals(rqlst.defined_vars['A']._q_invariant, False)
   271         self.assertEquals(rqlst.defined_vars['S']._q_invariant, False)
   271         self.assertEquals(rqlst.defined_vars['S']._q_invariant, False)
   272 
   272 
   273     def test_or_exists_2(self):        
   273     def test_or_exists_2(self):
   274         rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)')
   274         rqlst = self._prepare('Any U WHERE EXISTS(U in_group G, G name "managers") OR EXISTS(X owned_by U, X bookmarked_by U)')
   275         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   275         self.assertEquals(rqlst.defined_vars['U']._q_invariant, False)
   276         self.assertEquals(rqlst.defined_vars['G']._q_invariant, False)
   276         self.assertEquals(rqlst.defined_vars['G']._q_invariant, False)
   277         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   277         self.assertEquals(rqlst.defined_vars['X']._q_invariant, True)
   278         
   278 
   279     def test_or_exists_3(self):        
   279     def test_or_exists_3(self):
   280         rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 '
   280         rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 '
   281                               'WHERE C is Societe, S concerne C, C nom CS, '
   281                               'WHERE C is Societe, S concerne C, C nom CS, '
   282                               '(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))')
   282                               '(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))')
   283         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   283         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   284         rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 '
   284         rqlst = self._prepare('Any COUNT(S),CS GROUPBY CS ORDERBY 1 DESC LIMIT 10 '
   285                               'WHERE S is Affaire, C is Societe, S concerne C, C nom CS, '
   285                               'WHERE S is Affaire, C is Societe, S concerne C, C nom CS, '
   286                               '(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))')
   286                               '(EXISTS(S owned_by 1)) OR (EXISTS(S documented_by N, N title "published"))')
   287         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   287         self.assertEquals(rqlst.defined_vars['S']._q_invariant, True)
   288 
   288 
   289     def test_nonregr_ambiguity(self):        
   289     def test_nonregr_ambiguity(self):
   290         rqlst = self._prepare('Note N WHERE N attachment F')
   290         rqlst = self._prepare('Note N WHERE N attachment F')
   291         # N may be an image as well, not invariant
   291         # N may be an image as well, not invariant
   292         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
   292         self.assertEquals(rqlst.defined_vars['N']._q_invariant, False)
   293         self.assertEquals(rqlst.defined_vars['F']._q_invariant, True)
   293         self.assertEquals(rqlst.defined_vars['F']._q_invariant, True)
   294 
   294