cubicweb/server/test/unittest_rql2sql.py
changeset 12236 75a6b2f40c44
parent 12235 03b94c9863de
child 12296 23bc9f385645
equal deleted inserted replaced
12235:03b94c9863de 12236:75a6b2f40c44
    21 import sys
    21 import sys
    22 import unittest
    22 import unittest
    23 
    23 
    24 from logilab import database as db
    24 from logilab import database as db
    25 from logilab.common.testlib import mock_object
    25 from logilab.common.testlib import mock_object
    26 from logilab.common.decorators import monkeypatch
       
    27 
    26 
    28 from rql import BadRQLQuery
    27 from rql import BadRQLQuery
    29 from rql import RQLHelper
    28 from rql import RQLHelper
    30 from rql.utils import register_function, FunctionDescr
    29 from rql.utils import register_function, FunctionDescr
    31 
    30 
    36 from cubicweb.server.querier import QuerierHelper, ExecutionPlan
    35 from cubicweb.server.querier import QuerierHelper, ExecutionPlan
    37 from cubicweb.server.sources import rql2sql
    36 from cubicweb.server.sources import rql2sql
    38 
    37 
    39 _orig_select_principal = rqlannotation._select_principal
    38 _orig_select_principal = rqlannotation._select_principal
    40 _orig_check_permissions = ExecutionPlan._check_permissions
    39 _orig_check_permissions = ExecutionPlan._check_permissions
    41 
       
    42 
       
    43 def setUpModule():
       
    44     """Monkey-patch the SQL generator to ensure solutions order is predictable."""
       
    45     global orig_solutions_sql
       
    46     orig_solutions_sql = rql2sql.SQLGenerator._solutions_sql
       
    47 
       
    48     @monkeypatch
       
    49     def _solutions_sql(self, select, solutions, distinct, needalias):
       
    50         return orig_solutions_sql(self, select, sorted(solutions), distinct, needalias)
       
    51 
       
    52 
       
    53 def tearDownModule():
       
    54     """Remove monkey-patch done in setUpModule"""
       
    55     rql2sql.SQLGenerator._solutions_sql = orig_solutions_sql
       
    56 
       
    57 
    40 
    58 # add a dumb registered procedure
    41 # add a dumb registered procedure
    59 class stockproc(FunctionDescr):
    42 class stockproc(FunctionDescr):
    60     supported_backends = ('postgres', 'sqlite', 'mysql')
    43     supported_backends = ('postgres', 'sqlite', 'mysql')
    61 
    44