author | Rémi Cardona <remi.cardona@logilab.fr> |
Fri, 11 Sep 2015 18:05:38 +0200 | |
changeset 10666 | 7f6b5f023884 |
parent 10657 | 92c96bf05528 |
permissions | -rw-r--r-- |
0 | 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 | 20 |
|
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 | 23 |
|
10609
e2d8e81bfe68
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9651
diff
changeset
|
24 |
from six.moves import range |
e2d8e81bfe68
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9651
diff
changeset
|
25 |
|
0 | 26 |
from logilab.common.testlib import TestCase, unittest_main |
27 |
||
28 |
from rql import BadRQLQuery, RQLSyntaxError |
|
29 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
30 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 31 |
|
32 |
||
33 |
translations = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
34 |
u'CWUser' : u"Utilisateur", |
0 | 35 |
u'EmailAddress' : u"Adresse", |
36 |
u'name' : u"nom", |
|
37 |
u'alias' : u"nom", |
|
38 |
u'surname' : u"nom", |
|
39 |
u'firstname' : u"prénom", |
|
40 |
u'state' : u"état", |
|
41 |
u'address' : u"adresse", |
|
42 |
u'use_email' : u"adel", |
|
43 |
} |
|
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
|
44 |
|
0 | 45 |
def _translate(msgid): |
46 |
return translations.get(msgid, msgid) |
|
47 |
||
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
|
48 |
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
|
49 |
return _translate(msgid) |
0 | 50 |
|
51 |
from cubicweb.web.views.magicsearch import translate_rql_tree, QSPreProcessor, QueryTranslator |
|
52 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
53 |
class QueryTranslatorTC(CubicWebTC): |
0 | 54 |
"""test suite for QueryTranslatorTC""" |
1654 | 55 |
|
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
56 |
@contextmanager |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
57 |
def proc(self): |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
yield proc |
0 | 63 |
|
64 |
def test_basic_translations(self): |
|
65 |
"""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
|
66 |
with self.proc() as proc: |
10657
92c96bf05528
[test] use unicode for rql queries (4/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10609
diff
changeset
|
67 |
rql = u"Any C WHERE C is Adresse, P adel C, C adresse 'Logilab'" |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
68 |
rql, = proc.preprocess_query(rql) |
10657
92c96bf05528
[test] use unicode for rql queries (4/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10609
diff
changeset
|
69 |
self.assertEqual(rql, 'Any C WHERE C is EmailAddress, P use_email C, C address "Logilab"') |
0 | 70 |
|
71 |
def test_ambiguous_translations(self): |
|
72 |
"""tests possibly ambiguous translations""" |
|
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
73 |
with self.proc() as proc: |
10657
92c96bf05528
[test] use unicode for rql queries (4/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10609
diff
changeset
|
74 |
rql = u"Any P WHERE P adel C, C is EmailAddress, C nom 'Logilab'" |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
75 |
rql, = proc.preprocess_query(rql) |
10657
92c96bf05528
[test] use unicode for rql queries (4/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10609
diff
changeset
|
76 |
self.assertEqual(rql, 'Any P WHERE P use_email C, C is EmailAddress, C alias "Logilab"') |
92c96bf05528
[test] use unicode for rql queries (4/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10609
diff
changeset
|
77 |
rql = u"Any P WHERE P is Utilisateur, P adel C, P nom 'Smith'" |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
78 |
rql, = proc.preprocess_query(rql) |
10657
92c96bf05528
[test] use unicode for rql queries (4/7)
Julien Cristau <julien.cristau@logilab.fr>
parents:
10609
diff
changeset
|
79 |
self.assertEqual(rql, 'Any P WHERE P is CWUser, P use_email C, P surname "Smith"') |
0 | 80 |
|
81 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
82 |
class QSPreProcessorTC(CubicWebTC): |
0 | 83 |
"""test suite for QSPreProcessor""" |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
84 |
|
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
85 |
@contextmanager |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
proc._cw = req |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
92 |
yield proc |
0 | 93 |
|
94 |
def test_entity_translation(self): |
|
95 |
"""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
|
96 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
97 |
translate = proc._get_entity_type |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
self.assertRaises(BadRQLQuery, translate, 'whatever') |
0 | 103 |
|
104 |
def test_attribute_translation(self): |
|
105 |
"""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
|
106 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
107 |
translate = proc._get_attribute_name |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
108 |
eschema = self.schema.eschema('CWUser') |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
eschema = self.schema.eschema('EmailAddress') |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
# 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
|
115 |
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
|
116 |
self.assertRaises(BadRQLQuery, translate, 'prénom', eschema) |
0 | 117 |
|
118 |
def test_one_word_query(self): |
|
119 |
"""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
|
120 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
121 |
transform = proc._one_word_query |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
122 |
self.assertEqual(transform('123'), |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
123 |
('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
|
124 |
self.assertEqual(transform('CWUser'), |
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('Utilisateur'), |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
127 |
('CWUser C',)) |
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.assertEqual(transform('adresse'), |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
131 |
('EmailAddress E',)) |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
132 |
self.assertRaises(BadRQLQuery, transform, 'Workcases') |
0 | 133 |
|
134 |
def test_two_words_query(self): |
|
135 |
"""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
|
136 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
137 |
transform = proc._two_words_query |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
138 |
self.assertEqual(transform('CWUser', 'E'), |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
139 |
("CWUser E",)) |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
140 |
self.assertEqual(transform('CWUser', '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('utilisateur', 'Smith'), |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
143 |
('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
|
144 |
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
|
145 |
('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
|
146 |
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
|
147 |
('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
|
148 |
self.assertRaises(BadRQLQuery, transform, "pers", "taratata") |
0 | 149 |
|
150 |
def test_three_words_query(self): |
|
151 |
"""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
|
152 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
153 |
transform = proc._three_words_query |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
154 |
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
|
155 |
('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
|
156 |
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
|
157 |
('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
|
158 |
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
|
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('EmailAddress', 'nom', 'cubicweb'), |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
161 |
('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
|
162 |
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
|
163 |
('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
|
164 |
# expanded shortcuts |
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 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
|
167 |
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
|
168 |
('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
|
169 |
self.assertRaises(BadRQLQuery, transform, 'word1', 'word2', 'word3') |
1654 | 170 |
|
0 | 171 |
def test_quoted_queries(self): |
172 |
"""tests how quoted queries are handled""" |
|
173 |
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
|
174 |
(u'Adresse "My own EmailAddress"', ('EmailAddress E ORDERBY FTIRANK(E) DESC WHERE E has_text %(text)s', {'text': u'My own EmailAddress'})), |
1654 | 175 |
(u'Utilisateur prénom "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})), |
176 |
(u'Utilisateur firstname "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})), |
|
177 |
(u'CWUser firstname "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})), |
|
0 | 178 |
] |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
179 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
180 |
transform = proc._quoted_words_query |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
181 |
for query, expected in queries: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
182 |
self.assertEqual(transform(query), expected) |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
183 |
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
|
184 |
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
|
185 |
self.assertRaises(BadRQLQuery, transform, 'CWUser firstname other "Jean Paul"') |
1654 | 186 |
|
0 | 187 |
def test_process_query(self): |
188 |
"""tests how queries are processed""" |
|
189 |
queries = [ |
|
1654 | 190 |
(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
|
191 |
(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
|
192 |
(u'Utilisateur cubicweb', (u'CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': u'cubicweb'})), |
1654 | 193 |
(u'CWUser prénom cubicweb', (u'CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'},)), |
0 | 194 |
] |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
195 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
196 |
for query, expected in queries: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
197 |
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
|
198 |
self.assertRaises(BadRQLQuery, |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
199 |
proc.preprocess_query, 'Any X WHERE X is Something') |
1654 | 200 |
|
0 | 201 |
|
202 |
||
203 |
## Processor Chains tests ############################################ |
|
1654 | 204 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
205 |
class ProcessorChainTC(CubicWebTC): |
0 | 206 |
"""test suite for magic_search's processor chains""" |
207 |
||
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
208 |
@contextmanager |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
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
|
213 |
yield proc |
0 | 214 |
|
215 |
def test_main_preprocessor_chain(self): |
|
216 |
"""tests QUERY_PROCESSOR""" |
|
217 |
queries = [ |
|
218 |
(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
|
219 |
("Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s", {'text': u'foo'})), |
0 | 220 |
# 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
|
221 |
# and it fails |
0 | 222 |
(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
|
223 |
('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': u'Smith'})), |
0 | 224 |
(u'utilisateur nom Smith', |
1654 | 225 |
('CWUser C WHERE C surname %(text)s', {'text': u'Smith'})), |
0 | 226 |
(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
|
227 |
('Any P WHERE P is CWUser, P surname "Smith"', None)), |
0 | 228 |
] |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
229 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
230 |
for query, expected in queries: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
231 |
rset = proc.process_query(query) |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
232 |
self.assertEqual((rset.rql, rset.args), expected) |
0 | 233 |
|
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
|
234 |
def test_accentuated_fulltext(self): |
0 | 235 |
"""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
|
236 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
self.assertEqual(rset.args, {'text': u'écrire'}) |
0 | 240 |
|
241 |
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
|
242 |
with self.proc() as proc: |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
243 |
self.assertRaises(RQLSyntaxError, |
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 |
self.assertRaises(BadRQLQuery, |
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
self.assertEqual(rset.args, {'text': u'utilisateur Smith'}) |
1654 | 250 |
|
8505
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
251 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
252 |
class RQLSuggestionsBuilderTC(CubicWebTC): |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
253 |
def suggestions(self, rql): |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
258 |
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
|
259 |
self.assertListEqual([], self.suggestions('')) |
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('An')) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
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
|
267 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
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
|
271 |
if not eschema.final], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
272 |
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
|
273 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
277 |
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
|
278 |
'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
|
279 |
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
|
280 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
281 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
'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
|
285 |
'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
|
286 |
'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
|
287 |
'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
|
288 |
'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
|
289 |
'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
|
290 |
'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
|
291 |
'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
|
292 |
'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
|
293 |
'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
|
294 |
'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
|
295 |
'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
|
296 |
'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
|
297 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
'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
|
301 |
'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
|
302 |
'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
|
303 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
304 |
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
|
305 |
# try completion on selected |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
306 |
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
|
307 |
'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
|
308 |
'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
|
309 |
'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
|
310 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
311 |
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
|
312 |
# 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
|
313 |
self.assertListEqual([], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
314 |
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
|
315 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
316 |
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
|
317 |
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
|
318 |
'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
|
319 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
320 |
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
|
321 |
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
|
322 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
323 |
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
|
324 |
# "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
|
325 |
self.assertListEqual([], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
326 |
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
|
327 |
# 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
|
328 |
self.assertListEqual([], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
329 |
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
|
330 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
331 |
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
|
332 |
# 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
|
333 |
# 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
|
334 |
with self.admin_access.web_request() as req: |
10609
e2d8e81bfe68
[py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9651
diff
changeset
|
335 |
for i in range(15): |
9651
c739ebc18b79
[web/test] port unittest_magicsearch to RepoAccess API
Julien Cristau <julien.cristau@logilab.fr>
parents:
8510
diff
changeset
|
336 |
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
|
337 |
req.cnx.commit() |
8505
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
338 |
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
|
339 |
'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
|
340 |
'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
|
341 |
'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
|
342 |
'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
|
343 |
'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
|
344 |
'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
|
345 |
'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
|
346 |
'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
|
347 |
'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
|
348 |
'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
|
349 |
'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
|
350 |
'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
|
351 |
'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
|
352 |
'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
|
353 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
354 |
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
|
355 |
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
|
356 |
'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
|
357 |
'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
|
358 |
'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
|
359 |
'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
|
360 |
'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
|
361 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
362 |
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
|
363 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
364 |
|
0 | 365 |
if __name__ == '__main__': |
366 |
unittest_main() |