devtools/repotest.py
branch3.5
changeset 3240 8604a15995d1
parent 2200 25bb65dc4559
child 4184 7002e91d304a
child 4212 ab6573088b4a
equal deleted inserted replaced
3239:1ceac4cd4fb7 3240:8604a15995d1
   106 
   106 
   107 class RQLGeneratorTC(TestCase):
   107 class RQLGeneratorTC(TestCase):
   108     schema = None # set this in concret test
   108     schema = None # set this in concret test
   109 
   109 
   110     def setUp(self):
   110     def setUp(self):
       
   111         self.repo = FakeRepo(self.schema)
   111         self.rqlhelper = RQLHelper(self.schema, special_relations={'eid': 'uid',
   112         self.rqlhelper = RQLHelper(self.schema, special_relations={'eid': 'uid',
   112                                                                    'has_text': 'fti'})
   113                                                                    'has_text': 'fti'})
   113         self.qhelper = QuerierHelper(FakeRepo(self.schema), self.schema)
   114         self.qhelper = QuerierHelper(self.repo, self.schema)
   114         ExecutionPlan._check_permissions = _dummy_check_permissions
   115         ExecutionPlan._check_permissions = _dummy_check_permissions
   115         rqlannotation._select_principal = _select_principal
   116         rqlannotation._select_principal = _select_principal
   116 
   117 
   117     def tearDown(self):
   118     def tearDown(self):
   118         ExecutionPlan._check_permissions = _orig_check_permissions
   119         ExecutionPlan._check_permissions = _orig_check_permissions
   127         #print '********* parsed', union.as_string()
   128         #print '********* parsed', union.as_string()
   128         self.rqlhelper.compute_solutions(union)
   129         self.rqlhelper.compute_solutions(union)
   129         #print '********* solutions', solutions
   130         #print '********* solutions', solutions
   130         self.rqlhelper.simplify(union)
   131         self.rqlhelper.simplify(union)
   131         #print '********* simplified', union.as_string()
   132         #print '********* simplified', union.as_string()
   132         plan = self.qhelper.plan_factory(union, {}, FakeSession())
   133         plan = self.qhelper.plan_factory(union, {}, FakeSession(self.repo))
   133         plan.preprocess(union)
   134         plan.preprocess(union)
   134         for select in union.children:
   135         for select in union.children:
   135             select.solutions.sort()
   136             select.solutions.sort()
   136         #print '********* ppsolutions', solutions
   137         #print '********* ppsolutions', solutions
   137         return union
   138         return union
   165 
   166 
   166     def set_debug(self, debug):
   167     def set_debug(self, debug):
   167         set_debug(debug)
   168         set_debug(debug)
   168 
   169 
   169     def _rqlhelper(self):
   170     def _rqlhelper(self):
   170         rqlhelper = self.o._rqlhelper
   171         rqlhelper = self.repo.vreg.rqlhelper
   171         # reset uid_func so it don't try to get type from eids
   172         # reset uid_func so it don't try to get type from eids
   172         rqlhelper._analyser.uid_func = None
   173         rqlhelper._analyser.uid_func = None
   173         rqlhelper._analyser.uid_func_mapping = {}
   174         rqlhelper._analyser.uid_func_mapping = {}
   174         return rqlhelper
   175         return rqlhelper
   175 
   176 
   239 
   240 
   240     def _prepare_plan(self, rql, kwargs=None):
   241     def _prepare_plan(self, rql, kwargs=None):
   241         rqlst = self.o.parse(rql, annotate=True)
   242         rqlst = self.o.parse(rql, annotate=True)
   242         self.o.solutions(self.session, rqlst, kwargs)
   243         self.o.solutions(self.session, rqlst, kwargs)
   243         if rqlst.TYPE == 'select':
   244         if rqlst.TYPE == 'select':
   244             self.o._rqlhelper.annotate(rqlst)
   245             self.repo.vreg.rqlhelper.annotate(rqlst)
   245             for select in rqlst.children:
   246             for select in rqlst.children:
   246                 select.solutions.sort()
   247                 select.solutions.sort()
   247         else:
   248         else:
   248             rqlst.solutions.sort()
   249             rqlst.solutions.sort()
   249         return self.o.plan_factory(rqlst, kwargs, self.session)
   250         return self.o.plan_factory(rqlst, kwargs, self.session)
   250 
   251 
   251 
   252 
   252 # monkey patch some methods to get predicatable results #######################
   253 # monkey patch some methods to get predicatable results #######################
   253 
   254 
   254 from cubicweb.server.rqlrewrite import RQLRewriter
   255 from cubicweb.rqlrewrite import RQLRewriter
   255 _orig_insert_snippets = RQLRewriter.insert_snippets
   256 _orig_insert_snippets = RQLRewriter.insert_snippets
   256 _orig_build_variantes = RQLRewriter.build_variantes
   257 _orig_build_variantes = RQLRewriter.build_variantes
   257 
   258 
   258 def _insert_snippets(self, snippets, varexistsmap=None):
   259 def _insert_snippets(self, snippets, varexistsmap=None):
   259     _orig_insert_snippets(self, sorted(snippets, snippet_cmp), varexistsmap)
   260     _orig_insert_snippets(self, sorted(snippets, snippet_cmp), varexistsmap)