47 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] |
48 |
48 |
49 def test_basic_translations(self): |
49 def test_basic_translations(self): |
50 """tests basic translations (no ambiguities)""" |
50 """tests basic translations (no ambiguities)""" |
51 rql = "Any C WHERE C is Adresse, P adel C, C adresse 'Logilab'" |
51 rql = "Any C WHERE C is Adresse, P adel C, C adresse 'Logilab'" |
52 rql, = self.proc.preprocess_query(rql, self.req) |
52 rql, = self.proc.preprocess_query(rql) |
53 self.assertEquals(rql, "Any C WHERE C is EmailAddress, P use_email C, C address 'Logilab'") |
53 self.assertEquals(rql, "Any C WHERE C is EmailAddress, P use_email C, C address 'Logilab'") |
54 |
54 |
55 def test_ambiguous_translations(self): |
55 def test_ambiguous_translations(self): |
56 """tests possibly ambiguous translations""" |
56 """tests possibly ambiguous translations""" |
57 rql = "Any P WHERE P adel C, C is EmailAddress, C nom 'Logilab'" |
57 rql = "Any P WHERE P adel C, C is EmailAddress, C nom 'Logilab'" |
58 rql, = self.proc.preprocess_query(rql, self.req) |
58 rql, = self.proc.preprocess_query(rql) |
59 self.assertEquals(rql, "Any P WHERE P use_email C, C is EmailAddress, C alias 'Logilab'") |
59 self.assertEquals(rql, "Any P WHERE P use_email C, C is EmailAddress, C alias 'Logilab'") |
60 rql = "Any P WHERE P is Utilisateur, P adel C, P nom 'Smith'" |
60 rql = "Any P WHERE P is Utilisateur, P adel C, P nom 'Smith'" |
61 rql, = self.proc.preprocess_query(rql, self.req) |
61 rql, = self.proc.preprocess_query(rql) |
62 self.assertEquals(rql, "Any P WHERE P is CWUser, P use_email C, P surname 'Smith'") |
62 self.assertEquals(rql, "Any P WHERE P is CWUser, P use_email C, P surname 'Smith'") |
63 |
63 |
64 |
64 |
65 class QSPreProcessorTC(CubicWebTC): |
65 class QSPreProcessorTC(CubicWebTC): |
66 """test suite for QSPreProcessor""" |
66 """test suite for QSPreProcessor""" |
166 (u'Utilisateur P', (u"CWUser P",)), |
166 (u'Utilisateur P', (u"CWUser P",)), |
167 (u'Utilisateur cubicweb', (u'CWUser C WHERE C has_text %(text)s', {'text': u'cubicweb'})), |
167 (u'Utilisateur cubicweb', (u'CWUser C WHERE C has_text %(text)s', {'text': u'cubicweb'})), |
168 (u'CWUser prénom cubicweb', (u'CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'},)), |
168 (u'CWUser prénom cubicweb', (u'CWUser C WHERE C firstname %(text)s', {'text': 'cubicweb'},)), |
169 ] |
169 ] |
170 for query, expected in queries: |
170 for query, expected in queries: |
171 self.assertEquals(self.proc.preprocess_query(query, self.req), expected) |
171 self.assertEquals(self.proc.preprocess_query(query), expected) |
172 self.assertRaises(BadRQLQuery, |
172 self.assertRaises(BadRQLQuery, |
173 self.proc.preprocess_query, 'Any X WHERE X is Something', self.req) |
173 self.proc.preprocess_query, 'Any X WHERE X is Something') |
174 |
174 |
175 |
175 |
176 |
176 |
177 ## Processor Chains tests ############################################ |
177 ## Processor Chains tests ############################################ |
178 |
178 |
199 ('CWUser C WHERE C surname %(text)s', {'text': u'Smith'})), |
199 ('CWUser C WHERE C surname %(text)s', {'text': u'Smith'})), |
200 (u'Any P WHERE P is Utilisateur, P nom "Smith"', |
200 (u'Any P WHERE P is Utilisateur, P nom "Smith"', |
201 ('Any P WHERE P is CWUser, P surname "Smith"', None)), |
201 ('Any P WHERE P is CWUser, P surname "Smith"', None)), |
202 ] |
202 ] |
203 for query, expected in queries: |
203 for query, expected in queries: |
204 rset = self.proc.process_query(query, self.req) |
204 rset = self.proc.process_query(query) |
205 self.assertEquals((rset.rql, rset.args), expected) |
205 self.assertEquals((rset.rql, rset.args), expected) |
206 |
206 |
207 def test_iso88591_fulltext(self): |
207 def test_iso88591_fulltext(self): |
208 """we must be able to type accentuated characters in the search field""" |
208 """we must be able to type accentuated characters in the search field""" |
209 rset = self.proc.process_query(u'écrire', self.req) |
209 rset = self.proc.process_query(u'écrire') |
210 self.assertEquals(rset.rql, "Any X WHERE X has_text %(text)s") |
210 self.assertEquals(rset.rql, "Any X WHERE X has_text %(text)s") |
211 self.assertEquals(rset.args, {'text': u'écrire'}) |
211 self.assertEquals(rset.args, {'text': u'écrire'}) |
212 |
212 |
213 def test_explicit_component(self): |
213 def test_explicit_component(self): |
214 self.assertRaises(RQLSyntaxError, |
214 self.assertRaises(RQLSyntaxError, |
215 self.proc.process_query, u'rql: CWUser E WHERE E noattr "Smith",', self.req) |
215 self.proc.process_query, u'rql: CWUser E WHERE E noattr "Smith",') |
216 self.assertRaises(BadRQLQuery, |
216 self.assertRaises(BadRQLQuery, |
217 self.proc.process_query, u'rql: CWUser E WHERE E noattr "Smith"', self.req) |
217 self.proc.process_query, u'rql: CWUser E WHERE E noattr "Smith"') |
218 rset = self.proc.process_query(u'text: utilisateur Smith', self.req) |
218 rset = self.proc.process_query(u'text: utilisateur Smith') |
219 self.assertEquals(rset.rql, 'Any X WHERE X has_text %(text)s') |
219 self.assertEquals(rset.rql, 'Any X WHERE X has_text %(text)s') |
220 self.assertEquals(rset.args, {'text': u'utilisateur Smith'}) |
220 self.assertEquals(rset.args, {'text': u'utilisateur Smith'}) |
221 |
221 |
222 if __name__ == '__main__': |
222 if __name__ == '__main__': |
223 unittest_main() |
223 unittest_main() |