author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 02 Aug 2012 10:09:11 +0200 | |
changeset 8510 | e2913c9880a0 |
parent 8505 | dcd9bc1d1bca |
child 9651 | c739ebc18b79 |
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 |
|
22 |
||
23 |
from logilab.common.testlib import TestCase, unittest_main |
|
24 |
||
25 |
from rql import BadRQLQuery, RQLSyntaxError |
|
26 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
27 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 28 |
|
29 |
||
30 |
translations = { |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
31 |
u'CWUser' : u"Utilisateur", |
0 | 32 |
u'EmailAddress' : u"Adresse", |
33 |
u'name' : u"nom", |
|
34 |
u'alias' : u"nom", |
|
35 |
u'surname' : u"nom", |
|
36 |
u'firstname' : u"prénom", |
|
37 |
u'state' : u"état", |
|
38 |
u'address' : u"adresse", |
|
39 |
u'use_email' : u"adel", |
|
40 |
} |
|
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
|
41 |
|
0 | 42 |
def _translate(msgid): |
43 |
return translations.get(msgid, msgid) |
|
44 |
||
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
|
45 |
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
|
46 |
return _translate(msgid) |
0 | 47 |
|
48 |
from cubicweb.web.views.magicsearch import translate_rql_tree, QSPreProcessor, QueryTranslator |
|
49 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
50 |
class QueryTranslatorTC(CubicWebTC): |
0 | 51 |
"""test suite for QueryTranslatorTC""" |
1654 | 52 |
|
0 | 53 |
def setUp(self): |
54 |
super(QueryTranslatorTC, self).setUp() |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
55 |
self.req = self.request() |
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
|
56 |
self.vreg.config.translations = {'en': (_translate, _ctxtranslate)} |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
57 |
proc = self.vreg['components'].select('magicsearch', self.req) |
0 | 58 |
self.proc = [p for p in proc.processors if isinstance(p, QueryTranslator)][0] |
59 |
||
60 |
def test_basic_translations(self): |
|
61 |
"""tests basic translations (no ambiguities)""" |
|
62 |
rql = "Any C WHERE C is Adresse, P adel C, C adresse 'Logilab'" |
|
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
63 |
rql, = self.proc.preprocess_query(rql) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
64 |
self.assertEqual(rql, "Any C WHERE C is EmailAddress, P use_email C, C address 'Logilab'") |
0 | 65 |
|
66 |
def test_ambiguous_translations(self): |
|
67 |
"""tests possibly ambiguous translations""" |
|
68 |
rql = "Any P WHERE P adel C, C is EmailAddress, C nom 'Logilab'" |
|
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
69 |
rql, = self.proc.preprocess_query(rql) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
70 |
self.assertEqual(rql, "Any P WHERE P use_email C, C is EmailAddress, C alias 'Logilab'") |
0 | 71 |
rql = "Any P WHERE P is Utilisateur, P adel C, P nom 'Smith'" |
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
72 |
rql, = self.proc.preprocess_query(rql) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
73 |
self.assertEqual(rql, "Any P WHERE P is CWUser, P use_email C, P surname 'Smith'") |
0 | 74 |
|
75 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
76 |
class QSPreProcessorTC(CubicWebTC): |
0 | 77 |
"""test suite for QSPreProcessor""" |
78 |
def setUp(self): |
|
79 |
super(QSPreProcessorTC, self).setUp() |
|
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
|
80 |
self.vreg.config.translations = {'en': (_translate, _ctxtranslate)} |
0 | 81 |
self.req = self.request() |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
82 |
proc = self.vreg['components'].select('magicsearch', self.req) |
0 | 83 |
self.proc = [p for p in proc.processors if isinstance(p, QSPreProcessor)][0] |
3462
3a79fecdd2b4
[magicsearch] make tests pass again: base preprocessor must have access to vreg
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3369
diff
changeset
|
84 |
self.proc._cw = self.req |
0 | 85 |
|
86 |
def test_entity_translation(self): |
|
87 |
"""tests QSPreProcessor._get_entity_name()""" |
|
88 |
translate = self.proc._get_entity_type |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
89 |
self.assertEqual(translate(u'EmailAddress'), "EmailAddress") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
90 |
self.assertEqual(translate(u'emailaddress'), "EmailAddress") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
91 |
self.assertEqual(translate(u'Adresse'), "EmailAddress") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
92 |
self.assertEqual(translate(u'adresse'), "EmailAddress") |
0 | 93 |
self.assertRaises(BadRQLQuery, translate, 'whatever') |
94 |
||
95 |
def test_attribute_translation(self): |
|
96 |
"""tests QSPreProcessor._get_attribute_name""" |
|
97 |
translate = self.proc._get_attribute_name |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
98 |
eschema = self.schema.eschema('CWUser') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
99 |
self.assertEqual(translate(u'prénom', eschema), "firstname") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
100 |
self.assertEqual(translate(u'nom', eschema), 'surname') |
1654 | 101 |
eschema = self.schema.eschema('EmailAddress') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
102 |
self.assertEqual(translate(u'adresse', eschema), "address") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
103 |
self.assertEqual(translate(u'nom', eschema), 'alias') |
0 | 104 |
# should fail if the name is not an attribute for the given entity schema |
105 |
self.assertRaises(BadRQLQuery, translate, 'whatever', eschema) |
|
106 |
self.assertRaises(BadRQLQuery, translate, 'prénom', eschema) |
|
107 |
||
108 |
def test_one_word_query(self): |
|
109 |
"""tests the 'one word shortcut queries'""" |
|
110 |
transform = self.proc._one_word_query |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
111 |
self.assertEqual(transform('123'), |
0 | 112 |
('Any X WHERE X eid %(x)s', {'x': 123}, 'x')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
113 |
self.assertEqual(transform('CWUser'), |
1654 | 114 |
('CWUser C',)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
115 |
self.assertEqual(transform('Utilisateur'), |
1654 | 116 |
('CWUser C',)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
117 |
self.assertEqual(transform('Adresse'), |
0 | 118 |
('EmailAddress E',)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
119 |
self.assertEqual(transform('adresse'), |
0 | 120 |
('EmailAddress E',)) |
121 |
self.assertRaises(BadRQLQuery, transform, 'Workcases') |
|
122 |
||
123 |
def test_two_words_query(self): |
|
124 |
"""tests the 'two words shortcut queries'""" |
|
125 |
transform = self.proc._two_words_query |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
126 |
self.assertEqual(transform('CWUser', 'E'), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
127 |
("CWUser E",)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
128 |
self.assertEqual(transform('CWUser', '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
|
129 |
('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': 'Smith'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
130 |
self.assertEqual(transform('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
|
131 |
('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': 'Smith'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
132 |
self.assertEqual(transform(u'adresse', 'Logilab'), |
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
|
133 |
('EmailAddress E ORDERBY FTIRANK(E) DESC WHERE E has_text %(text)s', {'text': 'Logilab'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
134 |
self.assertEqual(transform(u'adresse', 'Logi%'), |
0 | 135 |
('EmailAddress E WHERE E alias LIKE %(text)s', {'text': 'Logi%'})) |
136 |
self.assertRaises(BadRQLQuery, transform, "pers", "taratata") |
|
137 |
||
138 |
def test_three_words_query(self): |
|
139 |
"""tests the 'three words shortcut queries'""" |
|
140 |
transform = self.proc._three_words_query |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
141 |
self.assertEqual(transform('utilisateur', u'prénom', 'cubicweb'), |
1654 | 142 |
('CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
143 |
self.assertEqual(transform('utilisateur', 'nom', 'cubicweb'), |
1654 | 144 |
('CWUser C WHERE C surname %(text)s', {'text': 'cubicweb'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
145 |
self.assertEqual(transform(u'adresse', 'nom', 'cubicweb'), |
0 | 146 |
('EmailAddress E WHERE E alias %(text)s', {'text': 'cubicweb'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
147 |
self.assertEqual(transform('EmailAddress', 'nom', 'cubicweb'), |
1654 | 148 |
('EmailAddress E WHERE E alias %(text)s', {'text': 'cubicweb'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
149 |
self.assertEqual(transform('utilisateur', u'prénom', 'cubicweb%'), |
1654 | 150 |
('CWUser C WHERE C firstname LIKE %(text)s', {'text': 'cubicweb%'})) |
0 | 151 |
# expanded shortcuts |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
152 |
self.assertEqual(transform('CWUser', 'use_email', 'Logilab'), |
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
|
153 |
('CWUser C ORDERBY FTIRANK(C1) DESC WHERE C use_email C1, C1 has_text %(text)s', {'text': 'Logilab'})) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
154 |
self.assertEqual(transform('CWUser', 'use_email', '%Logilab'), |
1654 | 155 |
('CWUser C WHERE C use_email C1, C1 alias LIKE %(text)s', {'text': '%Logilab'})) |
0 | 156 |
self.assertRaises(BadRQLQuery, transform, 'word1', 'word2', 'word3') |
1654 | 157 |
|
0 | 158 |
def test_quoted_queries(self): |
159 |
"""tests how quoted queries are handled""" |
|
160 |
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
|
161 |
(u'Adresse "My own EmailAddress"', ('EmailAddress E ORDERBY FTIRANK(E) DESC WHERE E has_text %(text)s', {'text': u'My own EmailAddress'})), |
1654 | 162 |
(u'Utilisateur prénom "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})), |
163 |
(u'Utilisateur firstname "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})), |
|
164 |
(u'CWUser firstname "Jean Paul"', ('CWUser C WHERE C firstname %(text)s', {'text': 'Jean Paul'})), |
|
0 | 165 |
] |
166 |
transform = self.proc._quoted_words_query |
|
167 |
for query, expected in queries: |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
168 |
self.assertEqual(transform(query), expected) |
0 | 169 |
self.assertRaises(BadRQLQuery, transform, "unquoted rql") |
170 |
self.assertRaises(BadRQLQuery, transform, 'pers "Jean Paul"') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
171 |
self.assertRaises(BadRQLQuery, transform, 'CWUser firstname other "Jean Paul"') |
1654 | 172 |
|
0 | 173 |
def test_process_query(self): |
174 |
"""tests how queries are processed""" |
|
175 |
queries = [ |
|
1654 | 176 |
(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
|
177 |
(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
|
178 |
(u'Utilisateur cubicweb', (u'CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': u'cubicweb'})), |
1654 | 179 |
(u'CWUser prénom cubicweb', (u'CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'},)), |
0 | 180 |
] |
181 |
for query, expected in queries: |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
182 |
self.assertEqual(self.proc.preprocess_query(query), expected) |
2643
9976f511003b
web test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2637
diff
changeset
|
183 |
self.assertRaises(BadRQLQuery, |
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
184 |
self.proc.preprocess_query, 'Any X WHERE X is Something') |
1654 | 185 |
|
0 | 186 |
|
187 |
||
188 |
## Processor Chains tests ############################################ |
|
1654 | 189 |
|
0 | 190 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2661
diff
changeset
|
191 |
class ProcessorChainTC(CubicWebTC): |
0 | 192 |
"""test suite for magic_search's processor chains""" |
193 |
||
194 |
def setUp(self): |
|
195 |
super(ProcessorChainTC, self).setUp() |
|
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
|
196 |
self.vreg.config.translations = {'en': (_translate, _ctxtranslate)} |
0 | 197 |
self.req = self.request() |
2661
f8df42c9da6b
[vreg api update] remove some deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2643
diff
changeset
|
198 |
self.proc = self.vreg['components'].select('magicsearch', self.req) |
0 | 199 |
|
200 |
def test_main_preprocessor_chain(self): |
|
201 |
"""tests QUERY_PROCESSOR""" |
|
202 |
queries = [ |
|
203 |
(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
|
204 |
("Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s", {'text': u'foo'})), |
0 | 205 |
# 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
|
206 |
# and it fails |
0 | 207 |
(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
|
208 |
('CWUser C ORDERBY FTIRANK(C) DESC WHERE C has_text %(text)s', {'text': u'Smith'})), |
0 | 209 |
(u'utilisateur nom Smith', |
1654 | 210 |
('CWUser C WHERE C surname %(text)s', {'text': u'Smith'})), |
0 | 211 |
(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
|
212 |
('Any P WHERE P is CWUser, P surname "Smith"', None)), |
0 | 213 |
] |
214 |
for query, expected in queries: |
|
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
215 |
rset = self.proc.process_query(query) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
216 |
self.assertEqual((rset.rql, rset.args), expected) |
0 | 217 |
|
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
|
218 |
def test_accentuated_fulltext(self): |
0 | 219 |
"""we must be able to type accentuated characters in the search field""" |
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
|
220 |
rset = self.proc.process_query(u'écrire') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
221 |
self.assertEqual(rset.rql, "Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
222 |
self.assertEqual(rset.args, {'text': u'écrire'}) |
0 | 223 |
|
224 |
def test_explicit_component(self): |
|
225 |
self.assertRaises(RQLSyntaxError, |
|
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
226 |
self.proc.process_query, u'rql: CWUser E WHERE E noattr "Smith",') |
0 | 227 |
self.assertRaises(BadRQLQuery, |
3469
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
228 |
self.proc.process_query, u'rql: CWUser E WHERE E noattr "Smith"') |
1e28876c4b55
[magicsearch] (pre_)process_query doesn't need the req argument, instances already have access to self._cw
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3462
diff
changeset
|
229 |
rset = self.proc.process_query(u'text: utilisateur Smith') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
230 |
self.assertEqual(rset.rql, 'Any X ORDERBY FTIRANK(X) DESC WHERE X has_text %(text)s') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
231 |
self.assertEqual(rset.args, {'text': u'utilisateur Smith'}) |
1654 | 232 |
|
8505
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
233 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
234 |
class RQLSuggestionsBuilderTC(CubicWebTC): |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
235 |
def suggestions(self, rql): |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
236 |
req = self.request() |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
237 |
rbs = self.vreg['components'].select('rql.suggestions', req) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
238 |
return rbs.build_suggestions(rql) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
239 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
240 |
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
|
241 |
self.assertListEqual([], self.suggestions('')) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
if not eschema.final], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
254 |
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
|
255 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
256 |
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
|
257 |
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
|
258 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
259 |
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
|
260 |
'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
|
261 |
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
|
262 |
|
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_relations_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(['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
|
266 |
'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
|
267 |
'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
|
268 |
'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
|
269 |
'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
|
270 |
'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
|
271 |
'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
|
272 |
'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
|
273 |
'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
|
274 |
'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
|
275 |
'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
|
276 |
'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
|
277 |
'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
|
278 |
'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
|
279 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
280 |
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
|
281 |
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
|
282 |
'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
|
283 |
'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
|
284 |
'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
|
285 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
286 |
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
|
287 |
# try completion on selected |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
288 |
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
|
289 |
'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
|
290 |
'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
|
291 |
'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
|
292 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
293 |
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
|
294 |
# 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
|
295 |
self.assertListEqual([], |
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 asdasd')) |
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 |
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
|
299 |
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
|
300 |
'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
|
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 promo "')) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
303 |
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
|
304 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
305 |
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
|
306 |
# "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
|
307 |
self.assertListEqual([], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
308 |
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
|
309 |
# 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
|
310 |
self.assertListEqual([], |
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, X promo "po')) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
312 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
313 |
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
|
314 |
# 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
|
315 |
# a given attribute (limited to 10) |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
316 |
req = self.request() |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
317 |
for i in xrange(15): |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
318 |
req.create_entity('Personne', nom=u'n%s' % i, prenom=u'p%s' % i) |
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 nom "n0"', |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
320 |
'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
|
321 |
'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
|
322 |
'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
|
323 |
'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
|
324 |
'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
|
325 |
'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
|
326 |
'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
|
327 |
'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
|
328 |
'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
|
329 |
'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
|
330 |
'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
|
331 |
'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
|
332 |
'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
|
333 |
'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
|
334 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
335 |
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
|
336 |
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
|
337 |
'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
|
338 |
'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
|
339 |
'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
|
340 |
'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
|
341 |
'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
|
342 |
], |
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
343 |
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
|
344 |
|
dcd9bc1d1bca
[ui] provide an autocomplete RQL bar (closes #2439846)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
6340
diff
changeset
|
345 |
|
0 | 346 |
if __name__ == '__main__': |
347 |
unittest_main() |