web/test/unittest_magicsearch.py
author Julien Cristau <julien.cristau@logilab.fr>
Wed, 09 Apr 2014 10:49:18 +0200
changeset 9670 5b661f58978c
parent 9651 c739ebc18b79
child 10609 e2d8e81bfe68
permissions -rw-r--r--
[web/debug] Fix check for open sessions itervalues returns an iterator, which never evaluates to False. Regression from 0bb18407c053 "[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)".
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     2
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     4
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     6
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     8
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     9
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    10
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    11
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    12
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    14
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    15
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    19
"""Unit tests for cw.web.views.magicsearch"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
import sys
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    22
from contextlib import contextmanager
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
from rql import BadRQLQuery, RQLSyntaxError
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    28
from cubicweb.devtools.testlib import CubicWebTC
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
translations = {
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
    32
    u'CWUser' : u"Utilisateur",
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
    u'EmailAddress' : u"Adresse",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    u'name' : u"nom",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
    u'alias' : u"nom",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    u'surname' : u"nom",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
    u'firstname' : u"prénom",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    u'state' : u"état",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
    u'address' : u"adresse",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    u'use_email' : u"adel",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
    }
3362
2a2dcfb379a0 [magicsearch] update to match new i18n API: config.translations[lang] now returns a couple of function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2661
diff changeset
    42
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
def _translate(msgid):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    return translations.get(msgid, msgid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
3362
2a2dcfb379a0 [magicsearch] update to match new i18n API: config.translations[lang] now returns a couple of function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2661
diff changeset
    46
def _ctxtranslate(ctx, msgid):
2a2dcfb379a0 [magicsearch] update to match new i18n API: config.translations[lang] now returns a couple of function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2661
diff changeset
    47
    return _translate(msgid)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
from cubicweb.web.views.magicsearch import translate_rql_tree, QSPreProcessor, QueryTranslator
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    51
class QueryTranslatorTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    """test suite for QueryTranslatorTC"""
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    53
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    54
    @contextmanager
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    55
    def proc(self):
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    56
        with self.admin_access.web_request() as req:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    57
            self.vreg.config.translations = {'en': (_translate, _ctxtranslate)}
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    58
            proc = self.vreg['components'].select('magicsearch', req)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    59
            proc = [p for p in proc.processors if isinstance(p, QueryTranslator)][0]
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    60
            yield proc
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
    def test_basic_translations(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        """tests basic translations (no ambiguities)"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    64
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    65
            rql = "Any C WHERE C is Adresse, P adel C, C adresse 'Logilab'"
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    66
            rql, = proc.preprocess_query(rql)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    67
            self.assertEqual(rql, "Any C WHERE C is EmailAddress, P use_email C, C address 'Logilab'")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
    def test_ambiguous_translations(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        """tests possibly ambiguous translations"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    71
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    72
            rql = "Any P WHERE P adel C, C is EmailAddress, C nom 'Logilab'"
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    73
            rql, = proc.preprocess_query(rql)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    74
            self.assertEqual(rql, "Any P WHERE P use_email C, C is EmailAddress, C alias 'Logilab'")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    75
            rql = "Any P WHERE P is Utilisateur, P adel C, P nom 'Smith'"
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    76
            rql, = proc.preprocess_query(rql)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    77
            self.assertEqual(rql, "Any P WHERE P is CWUser, P use_email C, P surname 'Smith'")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
    80
class QSPreProcessorTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    """test suite for QSPreProcessor"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    82
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    83
    @contextmanager
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    84
    def proc(self):
3362
2a2dcfb379a0 [magicsearch] update to match new i18n API: config.translations[lang] now returns a couple of function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2661
diff changeset
    85
        self.vreg.config.translations = {'en': (_translate, _ctxtranslate)}
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    86
        with self.admin_access.web_request() as req:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    87
            proc = self.vreg['components'].select('magicsearch', req)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    88
            proc = [p for p in proc.processors if isinstance(p, QSPreProcessor)][0]
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    89
            proc._cw = req
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    90
            yield proc
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
    def test_entity_translation(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        """tests QSPreProcessor._get_entity_name()"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    94
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    95
            translate = proc._get_entity_type
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    96
            self.assertEqual(translate(u'EmailAddress'), "EmailAddress")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    97
            self.assertEqual(translate(u'emailaddress'), "EmailAddress")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    98
            self.assertEqual(translate(u'Adresse'), "EmailAddress")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
    99
            self.assertEqual(translate(u'adresse'), "EmailAddress")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   100
            self.assertRaises(BadRQLQuery, translate, 'whatever')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
    def test_attribute_translation(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        """tests QSPreProcessor._get_attribute_name"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   104
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   105
            translate = proc._get_attribute_name
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   106
            eschema = self.schema.eschema('CWUser')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   107
            self.assertEqual(translate(u'prénom', eschema), "firstname")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   108
            self.assertEqual(translate(u'nom', eschema), 'surname')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   109
            eschema = self.schema.eschema('EmailAddress')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   110
            self.assertEqual(translate(u'adresse', eschema), "address")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   111
            self.assertEqual(translate(u'nom', eschema), 'alias')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   112
            # should fail if the name is not an attribute for the given entity schema
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   113
            self.assertRaises(BadRQLQuery, translate, 'whatever', eschema)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   114
            self.assertRaises(BadRQLQuery, translate, 'prénom', eschema)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
    def test_one_word_query(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
        """tests the 'one word shortcut queries'"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   118
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   119
            transform = proc._one_word_query
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   120
            self.assertEqual(transform('123'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   121
                              ('Any X WHERE X eid %(x)s', {'x': 123}, 'x'))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   122
            self.assertEqual(transform('CWUser'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   123
                              ('CWUser C',))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   124
            self.assertEqual(transform('Utilisateur'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   125
                              ('CWUser C',))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   126
            self.assertEqual(transform('Adresse'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   127
                              ('EmailAddress E',))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   128
            self.assertEqual(transform('adresse'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   129
                              ('EmailAddress E',))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   130
            self.assertRaises(BadRQLQuery, transform, 'Workcases')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
    def test_two_words_query(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
        """tests the 'two words shortcut queries'"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   134
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   135
            transform = proc._two_words_query
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   136
            self.assertEqual(transform('CWUser', 'E'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   137
                              ("CWUser E",))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   138
            self.assertEqual(transform('CWUser', 'Smith'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   139
                              ('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': 'Smith'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   140
            self.assertEqual(transform('utilisateur', 'Smith'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   141
                              ('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': 'Smith'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   142
            self.assertEqual(transform(u'adresse', 'Logilab'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   143
                              ('EmailAddress E ORDERBY FTIRANK(E) DESC WHERE E has_text %(text)s', {'text': 'Logilab'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   144
            self.assertEqual(transform(u'adresse', 'Logi%'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   145
                              ('EmailAddress E WHERE E alias LIKE %(text)s', {'text': 'Logi%'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   146
            self.assertRaises(BadRQLQuery, transform, "pers", "taratata")
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
    def test_three_words_query(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
        """tests the 'three words shortcut queries'"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   150
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   151
            transform = proc._three_words_query
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   152
            self.assertEqual(transform('utilisateur', u'prénom', 'cubicweb'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   153
                              ('CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   154
            self.assertEqual(transform('utilisateur', 'nom', 'cubicweb'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   155
                              ('CWUser C WHERE C surname %(text)s', {'text': 'cubicweb'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   156
            self.assertEqual(transform(u'adresse', 'nom', 'cubicweb'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   157
                              ('EmailAddress E WHERE E alias %(text)s', {'text': 'cubicweb'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   158
            self.assertEqual(transform('EmailAddress', 'nom', 'cubicweb'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   159
                              ('EmailAddress E WHERE E alias %(text)s', {'text': 'cubicweb'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   160
            self.assertEqual(transform('utilisateur', u'prénom', 'cubicweb%'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   161
                              ('CWUser C WHERE C firstname LIKE %(text)s', {'text': 'cubicweb%'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   162
            # expanded shortcuts
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   163
            self.assertEqual(transform('CWUser', 'use_email', 'Logilab'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   164
                              ('CWUser C ORDERBY FTIRANK(C1) DESC WHERE C use_email C1, C1 has_text %(text)s', {'text': 'Logilab'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   165
            self.assertEqual(transform('CWUser', 'use_email', '%Logilab'),
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   166
                              ('CWUser C WHERE C use_email C1, C1 alias LIKE %(text)s', {'text': '%Logilab'}))
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   167
            self.assertRaises(BadRQLQuery, transform, 'word1', 'word2', 'word3')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   168
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
    def test_quoted_queries(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
        """tests how quoted queries are handled"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        queries = [
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   172
            (u'Adresse "My own EmailAddress"', ('EmailAddress E ORDERBY FTIRANK(E) DESC WHERE E has_text %(text)s', {'text': u'My own EmailAddress'})),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   173
            (u'Utilisateur prénom "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   174
            (u'Utilisateur firstname "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})),
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   175
            (u'CWUser firstname "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
            ]
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   177
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   178
            transform = proc._quoted_words_query
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   179
            for query, expected in queries:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   180
                self.assertEqual(transform(query), expected)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   181
            self.assertRaises(BadRQLQuery, transform, "unquoted rql")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   182
            self.assertRaises(BadRQLQuery, transform, 'pers "Jean Paul"')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   183
            self.assertRaises(BadRQLQuery, transform, 'CWUser firstname other "Jean Paul"')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   184
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
    def test_process_query(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
        """tests how queries are processed"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   187
        queries = [
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   188
            (u'Utilisateur', (u"CWUser C",)),
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   189
            (u'Utilisateur P', (u"CWUser P",)),
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   190
            (u'Utilisateur cubicweb', (u'CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': u'cubicweb'})),
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   191
            (u'CWUser prénom cubicweb', (u'CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'},)),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
            ]
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   193
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   194
            for query, expected in queries:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   195
                self.assertEqual(proc.preprocess_query(query), expected)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   196
            self.assertRaises(BadRQLQuery,
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   197
                              proc.preprocess_query, 'Any X WHERE X is Something')
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   198
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   199
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   201
## Processor Chains tests ############################################
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   202
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   203
class ProcessorChainTC(CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
    """test suite for magic_search's processor chains"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   206
    @contextmanager
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   207
    def proc(self):
3362
2a2dcfb379a0 [magicsearch] update to match new i18n API: config.translations[lang] now returns a couple of function
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2661
diff changeset
   208
        self.vreg.config.translations = {'en': (_translate, _ctxtranslate)}
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   209
        with self.admin_access.web_request() as req:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   210
            proc = self.vreg['components'].select('magicsearch', req)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   211
            yield proc
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
    def test_main_preprocessor_chain(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
        """tests QUERY_PROCESSOR"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
        queries = [
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
            (u'foo',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   217
             ("Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s", {'text': u'foo'})),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
            # XXX this sounds like a language translator test...
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2661
diff changeset
   219
            # and it fails
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   220
            (u'Utilisateur Smith',
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   221
             ('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': u'Smith'})),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
            (u'utilisateur nom Smith',
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   223
             ('CWUser C WHERE C surname %(text)s', {'text': u'Smith'})),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
            (u'Any P WHERE P is Utilisateur, P nom "Smith"',
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 0
diff changeset
   225
             ('Any P WHERE P is CWUser, P surname "Smith"', None)),
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
            ]
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   227
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   228
            for query, expected in queries:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   229
                rset = proc.process_query(query)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   230
                self.assertEqual((rset.rql, rset.args), expected)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
5768
1e73a466aa69 [fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   232
    def test_accentuated_fulltext(self):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
        """we must be able to type accentuated characters in the search field"""
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   234
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   235
            rset = proc.process_query(u'écrire')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   236
            self.assertEqual(rset.rql, "Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s")
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   237
            self.assertEqual(rset.args, {'text': u'écrire'})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   238
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
    def test_explicit_component(self):
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   240
        with self.proc() as proc:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   241
            self.assertRaises(RQLSyntaxError,
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   242
                              proc.process_query, u'rql: CWUser E WHERE E noattr "Smith",')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   243
            self.assertRaises(BadRQLQuery,
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   244
                              proc.process_query, u'rql: CWUser E WHERE E noattr "Smith"')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   245
            rset = proc.process_query(u'text: utilisateur Smith')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   246
            self.assertEqual(rset.rql, 'Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s')
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   247
            self.assertEqual(rset.args, {'text': u'utilisateur Smith'})
1654
57b9fd2462b8 test updates
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   248
8505
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   249
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   250
class RQLSuggestionsBuilderTC(CubicWebTC):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   251
    def suggestions(self, rql):
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   252
        with self.admin_access.web_request() as req:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   253
            rbs = self.vreg['components'].select('rql.suggestions', req)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   254
            return rbs.build_suggestions(rql)
8505
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   255
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   256
    def test_no_restrictions_rql(self):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   257
        self.assertListEqual([], self.suggestions(''))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   258
        self.assertListEqual([], self.suggestions('An'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   259
        self.assertListEqual([], self.suggestions('Any X'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   260
        self.assertListEqual([], self.suggestions('Any X, Y'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   261
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   262
    def test_invalid_rql(self):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   263
        self.assertListEqual([], self.suggestions('blabla'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   264
        self.assertListEqual([], self.suggestions('Any X WHERE foo, bar'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   265
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   266
    def test_is_rql(self):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   267
        self.assertListEqual(['Any X WHERE X is %s' % eschema
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   268
                              for eschema in sorted(self.vreg.schema.entities())
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   269
                              if not eschema.final],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   270
                             self.suggestions('Any X WHERE X is'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   271
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   272
        self.assertListEqual(['Any X WHERE X is Personne', 'Any X WHERE X is Project'],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   273
                             self.suggestions('Any X WHERE X is P'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   274
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   275
        self.assertListEqual(['Any X WHERE X is Personne, Y is Personne',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   276
                              'Any X WHERE X is Personne, Y is Project'],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   277
                             self.suggestions('Any X WHERE X is Personne, Y is P'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   278
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   279
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   280
    def test_relations_rql(self):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   281
        self.assertListEqual(['Any X WHERE X is Personne, X ass A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   282
                              'Any X WHERE X is Personne, X datenaiss A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   283
                              'Any X WHERE X is Personne, X description A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   284
                              'Any X WHERE X is Personne, X fax A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   285
                              'Any X WHERE X is Personne, X nom A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   286
                              'Any X WHERE X is Personne, X prenom A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   287
                              'Any X WHERE X is Personne, X promo A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   288
                              'Any X WHERE X is Personne, X salary A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   289
                              'Any X WHERE X is Personne, X sexe A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   290
                              'Any X WHERE X is Personne, X tel A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   291
                              'Any X WHERE X is Personne, X test A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   292
                              'Any X WHERE X is Personne, X titre A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   293
                              'Any X WHERE X is Personne, X travaille A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   294
                              'Any X WHERE X is Personne, X web A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   295
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   296
                             self.suggestions('Any X WHERE X is Personne, X '))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   297
        self.assertListEqual(['Any X WHERE X is Personne, X tel A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   298
                              'Any X WHERE X is Personne, X test A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   299
                              'Any X WHERE X is Personne, X titre A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   300
                              'Any X WHERE X is Personne, X travaille A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   301
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   302
                             self.suggestions('Any X WHERE X is Personne, X t'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   303
        # try completion on selected
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   304
        self.assertListEqual(['Any X WHERE X is Personne, Y is Societe, X tel A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   305
                              'Any X WHERE X is Personne, Y is Societe, X test A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   306
                              'Any X WHERE X is Personne, Y is Societe, X titre A',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   307
                              'Any X WHERE X is Personne, Y is Societe, X travaille Y',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   308
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   309
                             self.suggestions('Any X WHERE X is Personne, Y is Societe, X t'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   310
        # invalid relation should not break
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   311
        self.assertListEqual([],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   312
                             self.suggestions('Any X WHERE X is Personne, X asdasd'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   313
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   314
    def test_attribute_vocabulary_rql(self):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   315
        self.assertListEqual(['Any X WHERE X is Personne, X promo "bon"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   316
                              'Any X WHERE X is Personne, X promo "pasbon"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   317
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   318
                             self.suggestions('Any X WHERE X is Personne, X promo "'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   319
        self.assertListEqual(['Any X WHERE X is Personne, X promo "pasbon"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   320
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   321
                             self.suggestions('Any X WHERE X is Personne, X promo "p'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   322
        # "bon" should be considered complete, hence no suggestion
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   323
        self.assertListEqual([],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   324
                             self.suggestions('Any X WHERE X is Personne, X promo "bon"'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   325
        # no valid vocabulary starts with "po"
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   326
        self.assertListEqual([],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   327
                             self.suggestions('Any X WHERE X is Personne, X promo "po'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   328
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   329
    def test_attribute_value_rql(self):
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   330
        # suggestions should contain any possible value for
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   331
        # a given attribute (limited to 10)
9651
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   332
        with self.admin_access.web_request() as req:
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   333
            for i in xrange(15):
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   334
                req.create_entity('Personne', nom=u'n%s' % i, prenom=u'p%s' % i)
c739ebc18b79 [web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents: 8510
diff changeset
   335
            req.cnx.commit()
8505
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   336
        self.assertListEqual(['Any X WHERE X is Personne, X nom "n0"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   337
                              'Any X WHERE X is Personne, X nom "n1"',
8510
e2913c9880a0 [test rql completion] dont limit number of completion, else we've impredicable results. Also should tell rql.parse to not print error on stdout
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8505
diff changeset
   338
                              'Any X WHERE X is Personne, X nom "n10"',
e2913c9880a0 [test rql completion] dont limit number of completion, else we've impredicable results. Also should tell rql.parse to not print error on stdout
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8505
diff changeset
   339
                              'Any X WHERE X is Personne, X nom "n11"',
e2913c9880a0 [test rql completion] dont limit number of completion, else we've impredicable results. Also should tell rql.parse to not print error on stdout
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8505
diff changeset
   340
                              'Any X WHERE X is Personne, X nom "n12"',
e2913c9880a0 [test rql completion] dont limit number of completion, else we've impredicable results. Also should tell rql.parse to not print error on stdout
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8505
diff changeset
   341
                              'Any X WHERE X is Personne, X nom "n13"',
e2913c9880a0 [test rql completion] dont limit number of completion, else we've impredicable results. Also should tell rql.parse to not print error on stdout
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8505
diff changeset
   342
                              'Any X WHERE X is Personne, X nom "n14"',
8505
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   343
                              'Any X WHERE X is Personne, X nom "n2"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   344
                              'Any X WHERE X is Personne, X nom "n3"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   345
                              'Any X WHERE X is Personne, X nom "n4"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   346
                              'Any X WHERE X is Personne, X nom "n5"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   347
                              'Any X WHERE X is Personne, X nom "n6"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   348
                              'Any X WHERE X is Personne, X nom "n7"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   349
                              'Any X WHERE X is Personne, X nom "n8"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   350
                              'Any X WHERE X is Personne, X nom "n9"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   351
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   352
                             self.suggestions('Any X WHERE X is Personne, X nom "'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   353
        self.assertListEqual(['Any X WHERE X is Personne, X nom "n1"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   354
                              'Any X WHERE X is Personne, X nom "n10"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   355
                              'Any X WHERE X is Personne, X nom "n11"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   356
                              'Any X WHERE X is Personne, X nom "n12"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   357
                              'Any X WHERE X is Personne, X nom "n13"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   358
                              'Any X WHERE X is Personne, X nom "n14"',
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   359
                              ],
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   360
                             self.suggestions('Any X WHERE X is Personne, X nom "n1'))
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   361
dcd9bc1d1bca [ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 6340
diff changeset
   362
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   363
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   364
    unittest_main()