server/test/unittest_ssplanner.py
changeset 11057 0b59724cb3f2
parent 11052 058bb3dc685f
child 11058 23eb30449fe5
equal deleted inserted replaced
11052:058bb3dc685f 11057:0b59724cb3f2
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     3 #
       
     4 # This file is part of CubicWeb.
       
     5 #
       
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     7 # terms of the GNU Lesser General Public License as published by the Free
       
     8 # Software Foundation, either version 2.1 of the License, or (at your option)
       
     9 # any later version.
       
    10 #
       
    11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    14 # details.
       
    15 #
       
    16 # You should have received a copy of the GNU Lesser General Public License along
       
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    18 
       
    19 from cubicweb.devtools import TestServerConfiguration, get_test_db_handler
       
    20 from cubicweb.devtools.repotest import BasePlannerTC, test_plan
       
    21 from cubicweb.server.ssplanner import SSPlanner
       
    22 
       
    23 # keep cnx so it's not garbage collected and the associated session closed
       
    24 def setUpModule(*args):
       
    25     global repo, cnx
       
    26     handler = get_test_db_handler(TestServerConfiguration(
       
    27             'data', apphome=SSPlannerTC.datadir))
       
    28     handler.build_db_cache()
       
    29     global repo, cnx
       
    30     repo, cnx = handler.get_repo_and_cnx()
       
    31 
       
    32 def tearDownModule(*args):
       
    33     global repo, cnx
       
    34     del repo, cnx
       
    35 
       
    36 class SSPlannerTC(BasePlannerTC):
       
    37     _test = test_plan
       
    38 
       
    39     def setUp(self):
       
    40         self.__class__.repo = repo
       
    41         BasePlannerTC.setUp(self)
       
    42         self.planner = SSPlanner(self.o.schema, self.repo.vreg.rqlhelper)
       
    43         self.system = self.o._repo.system_source
       
    44 
       
    45     def tearDown(self):
       
    46         BasePlannerTC.tearDown(self)
       
    47 
       
    48     def test_ordered_ambigous_sol(self):
       
    49         self._test('Any XN ORDERBY XN WHERE X name XN, X is IN (Basket, State, Folder)',
       
    50                    [('OneFetchStep', [('Any XN ORDERBY XN WHERE X name XN, X is IN(Basket, State, Folder)',
       
    51                                        [{'X': 'Basket', 'XN': 'String'},
       
    52                                         {'X': 'State', 'XN': 'String'},
       
    53                                         {'X': 'Folder', 'XN': 'String'}])],
       
    54                      None, [])])
       
    55 
       
    56     def test_groupeded_ambigous_sol(self):
       
    57         self._test('Any XN,COUNT(X) GROUPBY XN WHERE X name XN, X is IN (Basket, State, Folder)',
       
    58                    [('OneFetchStep', [('Any XN,COUNT(X) GROUPBY XN WHERE X name XN, X is IN(Basket, State, Folder)',
       
    59                                        [{'X': 'Basket', 'XN': 'String'},
       
    60                                         {'X': 'State', 'XN': 'String'},
       
    61                                         {'X': 'Folder', 'XN': 'String'}])],
       
    62                      None, [])])
       
    63 
       
    64 if __name__ == '__main__':
       
    65     from logilab.common.testlib import unittest_main
       
    66     unittest_main()