25 u'firstname' : u"prénom", |
25 u'firstname' : u"prénom", |
26 u'state' : u"état", |
26 u'state' : u"état", |
27 u'address' : u"adresse", |
27 u'address' : u"adresse", |
28 u'use_email' : u"adel", |
28 u'use_email' : u"adel", |
29 } |
29 } |
|
30 |
30 def _translate(msgid): |
31 def _translate(msgid): |
31 return translations.get(msgid, msgid) |
32 return translations.get(msgid, msgid) |
32 |
33 |
|
34 def _ctxtranslate(ctx, msgid): |
|
35 return _translate(msgid) |
33 |
36 |
34 from cubicweb.web.views.magicsearch import translate_rql_tree, QSPreProcessor, QueryTranslator |
37 from cubicweb.web.views.magicsearch import translate_rql_tree, QSPreProcessor, QueryTranslator |
35 |
38 |
36 class QueryTranslatorTC(CubicWebTC): |
39 class QueryTranslatorTC(CubicWebTC): |
37 """test suite for QueryTranslatorTC""" |
40 """test suite for QueryTranslatorTC""" |
38 |
41 |
39 def setUp(self): |
42 def setUp(self): |
40 super(QueryTranslatorTC, self).setUp() |
43 super(QueryTranslatorTC, self).setUp() |
41 self.req = self.request() |
44 self.req = self.request() |
42 self.vreg.config.translations = {'en': _translate} |
45 self.vreg.config.translations = {'en': (_translate, _ctxtranslate)} |
43 proc = self.vreg['components'].select('magicsearch', self.req) |
46 proc = self.vreg['components'].select('magicsearch', self.req) |
44 self.proc = [p for p in proc.processors if isinstance(p, QueryTranslator)][0] |
47 self.proc = [p for p in proc.processors if isinstance(p, QueryTranslator)][0] |
45 |
48 |
46 def test_basic_translations(self): |
49 def test_basic_translations(self): |
47 """tests basic translations (no ambiguities)""" |
50 """tests basic translations (no ambiguities)""" |
61 |
64 |
62 class QSPreProcessorTC(CubicWebTC): |
65 class QSPreProcessorTC(CubicWebTC): |
63 """test suite for QSPreProcessor""" |
66 """test suite for QSPreProcessor""" |
64 def setUp(self): |
67 def setUp(self): |
65 super(QSPreProcessorTC, self).setUp() |
68 super(QSPreProcessorTC, self).setUp() |
66 self.vreg.config.translations = {'en': _translate} |
69 self.vreg.config.translations = {'en': (_translate, _ctxtranslate)} |
67 self.req = self.request() |
70 self.req = self.request() |
68 proc = self.vreg['components'].select('magicsearch', self.req) |
71 proc = self.vreg['components'].select('magicsearch', self.req) |
69 self.proc = [p for p in proc.processors if isinstance(p, QSPreProcessor)][0] |
72 self.proc = [p for p in proc.processors if isinstance(p, QSPreProcessor)][0] |
70 self.proc.req = self.req |
73 self.proc.req = self.req |
71 |
74 |
177 class ProcessorChainTC(CubicWebTC): |
180 class ProcessorChainTC(CubicWebTC): |
178 """test suite for magic_search's processor chains""" |
181 """test suite for magic_search's processor chains""" |
179 |
182 |
180 def setUp(self): |
183 def setUp(self): |
181 super(ProcessorChainTC, self).setUp() |
184 super(ProcessorChainTC, self).setUp() |
182 self.vreg.config.translations = {'en': _translate} |
185 self.vreg.config.translations = {'en': (_translate, _ctxtranslate)} |
183 self.req = self.request() |
186 self.req = self.request() |
184 self.proc = self.vreg['components'].select('magicsearch', self.req) |
187 self.proc = self.vreg['components'].select('magicsearch', self.req) |
185 |
188 |
186 def test_main_preprocessor_chain(self): |
189 def test_main_preprocessor_chain(self): |
187 """tests QUERY_PROCESSOR""" |
190 """tests QUERY_PROCESSOR""" |