cubicweb/server/test/unittest_rql2sql.py
changeset 11771 96a8ad81317b
parent 11770 22b854d3e8b2
child 11775 39cf9e55ada8
equal deleted inserted replaced
11770:22b854d3e8b2 11771:96a8ad81317b
    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
    26 
    27 
    27 from rql import BadRQLQuery
    28 from rql import BadRQLQuery
    28 from rql.utils import register_function, FunctionDescr
    29 from rql.utils import register_function, FunctionDescr
    29 
    30 
    30 from cubicweb import devtools
    31 from cubicweb import devtools
    31 from cubicweb.devtools.repotest import RQLGeneratorTC
    32 from cubicweb.devtools.repotest import RQLGeneratorTC
    32 from cubicweb.server.sources.rql2sql import remove_unused_solutions
    33 from cubicweb.server.sources.rql2sql import SQLGenerator, remove_unused_solutions
       
    34 
       
    35 
       
    36 def setUpModule():
       
    37     """Monkey-patch the SQL generator to ensure solutions order is predictable."""
       
    38     global orig_solutions_sql
       
    39     orig_solutions_sql = SQLGenerator._solutions_sql
       
    40 
       
    41     @monkeypatch
       
    42     def _solutions_sql(self, select, solutions, distinct, needalias):
       
    43         return orig_solutions_sql(self, select, sorted(solutions), distinct, needalias)
       
    44 
       
    45 
       
    46 def tearDownModule():
       
    47     """Remove monkey-patch done in setUpModule"""
       
    48     SQLGenerator._solutions_sql = orig_solutions_sql
    33 
    49 
    34 
    50 
    35 # add a dumb registered procedure
    51 # add a dumb registered procedure
    36 class stockproc(FunctionDescr):
    52 class stockproc(FunctionDescr):
    37     supported_backends = ('postgres', 'sqlite', 'mysql')
    53     supported_backends = ('postgres', 'sqlite', 'mysql')