author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 01 Jun 2010 14:26:50 +0200 | |
branch | stable |
changeset 5620 | 8bff6aae4623 |
parent 5424 | 8ecbcbff9777 |
child 5557 | 1a534c596bff |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
1 |
# 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:
4212
diff
changeset
|
2 |
# 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:
4212
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
4 |
# 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:
4212
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
6 |
# 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:
4212
diff
changeset
|
7 |
# 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:
4212
diff
changeset
|
8 |
# 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:
4212
diff
changeset
|
9 |
# 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:
4212
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# 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:
4212
diff
changeset
|
12 |
# 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:
4212
diff
changeset
|
13 |
# 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:
4212
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4212
diff
changeset
|
16 |
# 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:
4212
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
18 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
19 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1802
diff
changeset
|
20 |
""" |
0 | 21 |
from cubicweb.goa.testlib import * |
22 |
||
23 |
from cubicweb import Binary |
|
24 |
||
25 |
from logilab.common.testlib import unittest_main |
|
26 |
from mx.DateTime import now, today, DateTimeType |
|
27 |
import rql |
|
28 |
||
29 |
from google.appengine.api.datastore_types import Blob, Text |
|
30 |
||
31 |
# stored procedure definition ################################################# |
|
32 |
||
33 |
from rql.utils import register_function, FunctionDescr |
|
34 |
||
35 |
class itemtype_sort_value(FunctionDescr): |
|
36 |
supported_backends = ('sqlite',) |
|
37 |
rtype = 'Int' |
|
38 |
||
39 |
try: |
|
40 |
register_function(itemtype_sort_value) |
|
41 |
except AssertionError: |
|
42 |
pass |
|
43 |
||
44 |
def init_sqlite_connexion(cnx): |
|
45 |
def itemtype_sort_value(text): |
|
46 |
return {"personal":2, "business":1}[text] |
|
47 |
cnx.create_function("ITEMTYPE_SORT_VALUE", 1, itemtype_sort_value) |
|
48 |
||
49 |
from cubicweb.server import SQL_CONNECT_HOOKS |
|
50 |
sqlite_hooks = SQL_CONNECT_HOOKS.setdefault('sqlite', []) |
|
51 |
sqlite_hooks.append(init_sqlite_connexion) |
|
52 |
||
53 |
# end stored procedure definition ############################################# |
|
54 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
55 |
class Article(db.Model): |
0 | 56 |
content = db.TextProperty() |
57 |
synopsis = db.StringProperty(default=u'hello') |
|
58 |
||
59 |
class Blog(db.Model): |
|
60 |
diem = db.DateProperty(required=True, auto_now_add=True) |
|
61 |
content = db.TextProperty() |
|
62 |
itemtype = db.StringProperty(required=True, choices=(u'personal', u'business')) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
63 |
talks_about = db.ReferenceProperty(Article) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
64 |
cites = db.SelfReferenceProperty() |
0 | 65 |
data = db.BlobProperty() |
66 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
67 |
|
0 | 68 |
class RQLTest(GAEBasedTC): |
69 |
MODEL_CLASSES = (Article, Blog) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
70 |
|
0 | 71 |
def setUp(self): |
72 |
GAEBasedTC.setUp(self) |
|
73 |
# hack to make talks_about cardinality to ** instead of ?* |
|
74 |
self.schema.rschema('talks_about').set_rproperty('Blog', 'Article', |
|
75 |
'cardinality', '**') |
|
76 |
self.req = self.request() |
|
77 |
self.article = self.add_entity('Article', content=u'very interesting') |
|
78 |
self.blog = self.add_entity('Blog', itemtype=u'personal', content=u'hop') |
|
79 |
self.execute('SET X talks_about Y WHERE X eid %(x)s, Y eid %(y)s', |
|
80 |
{'x': self.blog.eid, 'y': self.article.eid}) |
|
81 |
self.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
82 |
|
0 | 83 |
def _check_rset_size(self, rset, row, col): |
84 |
self.assertEquals(len(rset), row) |
|
85 |
self.assertEquals(len(rset[0]), col) |
|
86 |
self.assertEquals(len(rset.description), row) |
|
87 |
self.assertEquals(len(rset.description[0]), col) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
88 |
|
0 | 89 |
def _check_blog_rset(self, rset): |
90 |
self._check_rset_size(rset, 1, 1) |
|
91 |
self.assertEquals(rset.description[0][0], 'Blog') |
|
92 |
self.assertEquals(rset[0][0], self.blog.eid) |
|
93 |
self.assertEquals(rset.get_entity(0, 0).eid, self.blog.eid) |
|
94 |
||
95 |
def test_0_const(self): |
|
96 |
rset = self.req.execute('Any 1') |
|
97 |
self._check_rset_size(rset, 1, 1) |
|
98 |
self.assertEquals(rset[0][0], 1) |
|
99 |
self.assertEquals(rset.description[0][0], 'Int') |
|
100 |
||
101 |
def test_0_now_const(self): |
|
102 |
rset = self.req.execute('Any NOW') |
|
103 |
self._check_rset_size(rset, 1, 1) |
|
104 |
self.assertIsInstance(rset[0][0], DateTimeType) |
|
105 |
self.assertEquals(rset.description[0][0], 'Datetime') |
|
106 |
||
107 |
def test_0_today_const(self): |
|
108 |
rset = self.req.execute('Any TODAY') |
|
109 |
self._check_rset_size(rset, 1, 1) |
|
110 |
self.assertIsInstance(rset[0][0], DateTimeType) |
|
111 |
self.assertEquals(rset[0][0], today()) |
|
112 |
self.assertEquals(rset.description[0][0], 'Date') |
|
113 |
||
114 |
||
115 |
def test_1_eid(self): |
|
116 |
rset = self.req.execute('Any X WHERE X eid %(x)s', {'x': self.blog.eid}) |
|
117 |
self._check_blog_rset(rset) |
|
118 |
rset = self.req.execute('Any X WHERE X eid "%s"' % self.blog.eid) |
|
119 |
self._check_blog_rset(rset) |
|
120 |
||
121 |
def test_1_eid_eid(self): |
|
122 |
rset = self.req.execute('Any X,Y WHERE X eid %(x)s, Y eid %(y)s', {'x': self.blog.eid, |
|
123 |
'y': self.article.eid}) |
|
124 |
self._check_rset_size(rset, 1, 2) |
|
125 |
self.assertEquals(rset.description[0], ('Blog', 'Article')) |
|
126 |
self.assertEquals(rset[0][0], self.blog.eid) |
|
127 |
self.assertEquals(rset[0][1], self.article.eid) |
|
128 |
||
129 |
def test_1_eid_with_is(self): |
|
130 |
self.assertRaises(rql.TypeResolverException, |
|
131 |
self.req.execute, 'Any X WHERE X eid %(x)s, X is Article', {'x': self.blog.eid}) |
|
132 |
rset = self.req.execute('Any X WHERE X eid %(x)s, X is Blog', {'x': self.blog.eid}) |
|
133 |
self._check_blog_rset(rset) |
|
134 |
||
135 |
def test_1_is(self): |
|
136 |
rset = self.req.execute('Any X WHERE X is Blog') |
|
137 |
self._check_blog_rset(rset) |
|
138 |
blog2 = Blog(itemtype=u'personal', content=u'hop') |
|
139 |
blog2.put() |
|
140 |
rset = self.req.execute('Any X WHERE X is Blog') |
|
141 |
self.assertEquals(len(rset), 2) |
|
142 |
self.assertEquals(rset.description, [('Blog',), ('Blog',)]) |
|
143 |
||
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
144 |
|
0 | 145 |
def test_2_attribute_selection_1(self): |
146 |
rset = self.req.execute('Any X,D,C WHERE X is Blog, X diem D, X content C') |
|
147 |
self._check_rset_size(rset, 1, 3) |
|
148 |
self.assertEquals(rset[0], [self.blog.eid, today(), u'hop']) |
|
149 |
self.assertEquals(rset.description[0], ('Blog', 'Date', 'String')) |
|
150 |
self.assertIsInstance(rset[0][1], DateTimeType) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
151 |
|
0 | 152 |
def test_2_attribute_selection_2(self): |
153 |
rset = self.req.execute('Any D,C WHERE X is Blog, X diem D, X content C') |
|
154 |
self._check_rset_size(rset, 1, 2) |
|
155 |
self.assertEquals(rset[0], [today(), u'hop']) |
|
156 |
self.assertEquals(rset.description[0], ('Date', 'String')) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
157 |
|
0 | 158 |
def test_2_attribute_selection_binary(self): |
159 |
rset = self.req.execute('Any D WHERE X is Blog, X data D') |
|
160 |
self._check_rset_size(rset, 1, 1) |
|
161 |
self.assertEquals(rset[0], [None]) |
|
162 |
self.assertEquals(rset.description[0], ('Bytes',)) |
|
163 |
self.blog['data'] = Binary('raw data') |
|
164 |
self.blog.put() |
|
165 |
rset = self.req.execute('Any D WHERE X is Blog, X data D') |
|
166 |
self._check_rset_size(rset, 1, 1) |
|
167 |
self.assertIsInstance(rset[0][0], Binary) |
|
168 |
value = rset[0][0].getvalue() |
|
169 |
self.assertIsInstance(value, str) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
170 |
self.failIf(isinstance(value, Blob)) |
0 | 171 |
self.assertEquals(value, 'raw data') |
172 |
self.assertEquals(rset.description[0], ('Bytes',)) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
173 |
|
0 | 174 |
def test_2_attribute_selection_long_text(self): |
175 |
self.blog['content'] = text = 'a'*501 |
|
176 |
self.blog.put() |
|
177 |
rset = self.req.execute('Any C WHERE X is Blog, X content C') |
|
178 |
self._check_rset_size(rset, 1, 1) |
|
179 |
self.assertIsInstance(rset[0][0], unicode) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
180 |
self.failIf(isinstance(rset[0][0], Text)) |
0 | 181 |
self.assertEquals(rset[0][0], text) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
182 |
|
0 | 183 |
def test_2_attribute_selection_transformation(self): |
184 |
rset = self.req.execute('Any X,UPPER(C) WHERE X is Blog, X content C') |
|
185 |
self._check_rset_size(rset, 1, 2) |
|
186 |
self.assertEquals(rset[0], [self.blog.eid, u'HOP']) |
|
187 |
self.assertEquals(rset.description[0], ('Blog', 'String',)) |
|
188 |
||
189 |
||
190 |
def test_3_attribute_restriction(self): |
|
191 |
rset = self.req.execute('Any X WHERE X itemtype "personal"') |
|
192 |
self._check_blog_rset(rset) |
|
193 |
rset = self.req.execute('Any X WHERE X itemtype "business"') |
|
194 |
self.assertEquals(len(rset), 0) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
195 |
|
0 | 196 |
def test_3_ambigous_attribute_restriction_1(self): |
197 |
rset = self.req.execute('Any X WHERE X content "hello"') |
|
198 |
self.assertEquals(len(rset), 0) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
199 |
|
0 | 200 |
def test_3_ambigous_attribute_restriction_2(self): |
201 |
rset = self.req.execute('Any X WHERE X content "hop"') |
|
202 |
self._check_blog_rset(rset) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
203 |
|
0 | 204 |
def test_3_ambigous_attribute_restriction_3(self): |
205 |
article = Article(content=u'hop') |
|
206 |
article.put() |
|
207 |
rset = self.req.execute('Any X WHERE X content "hop"') |
|
208 |
self._check_rset_size(rset, 2, 1) |
|
209 |
self.assertUnorderedIterableEquals([r[0] for r in rset], [self.blog.eid, article.eid]) |
|
210 |
self.assertUnorderedIterableEquals([r[0] for r in rset.description], ['Blog', 'Article']) |
|
211 |
||
212 |
def test_3_incoherant_attribute_restriction(self): |
|
213 |
rset = self.req.execute('Any X WHERE X eid %(x)s, X content "hola"', |
|
214 |
{'x': self.blog.eid}) |
|
215 |
self.assertEquals(len(rset), 0) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
216 |
|
0 | 217 |
def test_3_multiple_attribute_restriction(self): |
218 |
rset = self.req.execute('Any X WHERE X content "hop", X itemtype "personal"') |
|
219 |
self._check_blog_rset(rset) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
220 |
|
0 | 221 |
def test_3_incoherant_multiple_attribute_restriction(self): |
222 |
rset = self.req.execute('Any X WHERE X content "hip", X itemtype "personal"') |
|
223 |
self.assertEquals(len(rset), 0) |
|
224 |
||
225 |
def test_3_today_attribute_restriction(self): |
|
226 |
rset = self.req.execute('Any X WHERE X diem < TODAY') |
|
227 |
self.assertEquals(len(rset), 0) |
|
228 |
rset = self.req.execute('Any X WHERE X diem <= TODAY') |
|
229 |
self._check_blog_rset(rset) |
|
230 |
rset = self.req.execute('Any X WHERE X diem > TODAY') |
|
231 |
self.assertEquals(len(rset), 0) |
|
232 |
rset = self.req.execute('Any X WHERE X diem >= TODAY') |
|
233 |
self._check_blog_rset(rset) |
|
234 |
||
235 |
def test_3_now_attribute_restriction(self): |
|
236 |
rset = self.req.execute('Any X WHERE X diem < NOW') |
|
237 |
self._check_blog_rset(rset) |
|
238 |
rset = self.req.execute('Any X WHERE X diem <= NOW') |
|
239 |
self._check_blog_rset(rset) |
|
240 |
rset = self.req.execute('Any X WHERE X diem > NOW') |
|
241 |
self.assertEquals(len(rset), 0) |
|
242 |
rset = self.req.execute('Any X WHERE X diem >= NOW') |
|
243 |
self.assertEquals(len(rset), 0) |
|
244 |
||
245 |
def test_3_in_attribute_restriction(self): |
|
246 |
self.skip('missing actual gae support, retry latter') |
|
247 |
article2 = Article(content=u'hip') |
|
248 |
rset = self.req.execute('Any X WHERE X content IN ("hop", "hip")') |
|
249 |
self._check_rset_size(rset, 2, 1) |
|
250 |
self.assertUnorderedIterableEquals([r[0] for r in rset], [self.blog.eid, article.eid]) |
|
251 |
self.assertUnorderedIterableEquals([r[0] for r in rset.description], ['Blog', 'Article']) |
|
252 |
||
253 |
def test_3_like(self): |
|
254 |
repo = self.config.repository() |
|
255 |
versions = repo.get_versions() |
|
256 |
self.assertEquals(versions.keys(), ['cubicweb']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
257 |
|
0 | 258 |
def _setup_relation_description(self): |
259 |
self.article2 = self.add_entity('Article', content=u'hop') |
|
260 |
self.blog2 = self.add_entity('Blog', itemtype=u'personal', content=u'hip') |
|
261 |
self.execute('SET X talks_about Y WHERE X eid %(x)s, Y eid %(y)s', |
|
262 |
{'x': self.blog2.eid, 'y': self.article2.eid}) |
|
263 |
self.blog3 = self.add_entity('Blog', itemtype=u'business', content=u'hep') |
|
264 |
self.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
265 |
|
0 | 266 |
def test_4_relation_restriction_1(self): |
267 |
self._setup_relation_description() |
|
268 |
rset = self.req.execute('Any X WHERE X talks_about Y') |
|
269 |
self._check_rset_size(rset, 2, 1) |
|
270 |
self.assertUnorderedIterableEquals([r[0] for r in rset], |
|
271 |
[self.blog.eid, self.blog2.eid]) |
|
272 |
self.assertUnorderedIterableEquals([r[0] for r in rset.description], ['Blog', 'Blog']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
273 |
|
0 | 274 |
def test_4_relation_restriction_2(self): |
275 |
self._setup_relation_description() |
|
276 |
rset = self.req.execute('Any Y WHERE X talks_about Y') |
|
277 |
self._check_rset_size(rset, 2, 1) |
|
278 |
self.assertUnorderedIterableEquals([r[0] for r in rset], |
|
279 |
[self.article.eid, self.article2.eid]) |
|
280 |
self.assertUnorderedIterableEquals([r[0] for r in rset.description], |
|
281 |
['Article', 'Article']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
282 |
|
0 | 283 |
def test_4_relation_restriction_3(self): |
284 |
self._setup_relation_description() |
|
285 |
rset = self.req.execute('Any X,Y WHERE X talks_about Y') |
|
286 |
self._check_rset_size(rset, 2, 2) |
|
287 |
self.assertUnorderedIterableEquals([tuple(r) for r in rset], |
|
288 |
[(self.blog.eid, self.article.eid), |
|
289 |
(self.blog2.eid, self.article2.eid)]) |
|
290 |
self.assertUnorderedIterableEquals([tuple(r) for r in rset.description], |
|
291 |
[('Blog', 'Article'), |
|
292 |
('Blog', 'Article')]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
293 |
|
0 | 294 |
def test_4_relation_restriction_4(self): |
295 |
self._setup_relation_description() |
|
296 |
rset = self.req.execute('Any X,Y WHERE X talks_about Y, X eid %(x)s', |
|
297 |
{'x': self.blog.eid}) |
|
298 |
self._check_rset_size(rset, 1, 2) |
|
299 |
self.assertEquals(rset[0], [self.blog.eid, self.article.eid]) |
|
300 |
self.assertUnorderedIterableEquals(rset.description[0], ['Blog', 'Article']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
301 |
|
0 | 302 |
def test_4_relation_restriction_5(self): |
303 |
self._setup_relation_description() |
|
304 |
rset = self.req.execute('Any X,Y WHERE X talks_about Y, Y eid %(x)s', |
|
305 |
{'x': self.article.eid}) |
|
306 |
self._check_rset_size(rset, 1, 2) |
|
307 |
self.assertEquals(rset[0], [self.blog.eid, self.article.eid]) |
|
308 |
self.assertUnorderedIterableEquals(rset.description[0], ['Blog', 'Article']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
309 |
|
0 | 310 |
def test_4_relation_subject_restriction(self): |
311 |
self._setup_relation_description() |
|
312 |
rset = self.req.execute('Any X,Y WHERE X talks_about Y, X content %(c)s', |
|
313 |
{'c': 'hop'}) |
|
314 |
self._check_rset_size(rset, 1, 2) |
|
315 |
self.assertEquals(rset[0], [self.blog.eid, self.article.eid]) |
|
316 |
self.assertUnorderedIterableEquals(rset.description[0], ['Blog', 'Article']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
317 |
|
0 | 318 |
def test_4_relation_object_restriction(self): |
319 |
self._setup_relation_description() |
|
320 |
rset = self.req.execute('Any X WHERE X is Blog, X talks_about Y, Y content %(c)s', |
|
321 |
{'c': 'very interesting'}) |
|
322 |
self._check_rset_size(rset, 1, 1) |
|
323 |
self.assertEquals(rset[0], [self.blog.eid]) |
|
324 |
self.assertUnorderedIterableEquals(rset.description[0], ['Blog']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
325 |
|
0 | 326 |
def test_4_relation_subject_object_restriction(self): |
327 |
article2 = self.add_entity('Article', content=u'very interesting') |
|
328 |
rset = self.req.execute('Any X,XC WHERE X is Blog, X content XC, X content %(xc)s, ' |
|
329 |
'X talks_about Y, Y content %(c)s', |
|
330 |
{'xc': 'hop', 'c': 'very interesting'}) |
|
331 |
self._check_rset_size(rset, 1, 2) |
|
332 |
self.assertEquals(rset[0], [self.blog.eid, self.blog.content]) |
|
333 |
self.assertUnorderedIterableEquals(rset.description[0], ['Blog', 'String']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
334 |
|
0 | 335 |
def test_4_relation_subject_object_restriction_no_res(self): |
336 |
article2 = self.add_entity('Article', content=u'very interesting') |
|
337 |
rset = self.req.execute('Any X,XC WHERE X is Blog, X content XC, X content %(xc)s, ' |
|
338 |
'X talks_about Y, Y content %(c)s', |
|
339 |
{'xc': 'hip', 'c': 'very interesting'}) |
|
340 |
self.assertEquals(len(rset), 0) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
341 |
|
0 | 342 |
def test_4_relation_subject_object_restriction_no_res_2(self): |
343 |
rset = self.req.execute('Any X,XC WHERE X is Blog, X content XC, X content %(xc)s, ' |
|
344 |
'X talks_about Y, Y content %(c)s', |
|
345 |
{'xc': 'hop', 'c': 'not interesting'}) |
|
346 |
self.assertEquals(len(rset), 0) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
347 |
|
0 | 348 |
def test_4_relation_restriction_7(self): |
349 |
self._setup_relation_description() |
|
350 |
rset = self.req.execute('Any XC,XD,YC WHERE X talks_about Y, Y eid %(x)s,' |
|
351 |
'X content XC, X diem XD, Y content YC', |
|
352 |
{'x': self.article.eid}) |
|
353 |
self._check_rset_size(rset, 1, 3) |
|
354 |
self.assertEquals(rset[0], [self.blog.content, self.blog.diem, self.article.content]) |
|
355 |
self.assertUnorderedIterableEquals(rset.description[0], ['String', 'Date', 'String']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
356 |
|
0 | 357 |
def test_4_relation_restriction_8(self): |
358 |
self._setup_relation_description() |
|
359 |
rset = self.req.execute('Any X,Y WHERE X cites Y, Y eid %(x)s', {'x': self.blog.eid}) |
|
360 |
self.assertEquals(len(rset), 0) |
|
361 |
||
362 |
def test_4_relation_restriction_9(self): |
|
363 |
article2 = self.add_entity('Article', content=u'hop') |
|
364 |
self.req.execute('SET X talks_about Y WHERE X eid %(x)s, Y eid %(y)s', |
|
365 |
{'x': self.blog.eid, 'y': article2.eid}) |
|
366 |
rset = self.req.execute('Any X,Y WHERE X talks_about Y, X eid %(x)s, Y eid %(y)s', |
|
367 |
{'x': self.blog.eid, 'y': article2.eid}) |
|
368 |
self._check_rset_size(rset, 1, 2) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
369 |
|
0 | 370 |
def test_4_ambiguous_subject_relation(self): |
371 |
ye = self.add_entity('YamsEntity') |
|
372 |
self.req.execute('SET X ambiguous_relation Y WHERE X eid %(x)s, Y eid %(y)s', |
|
373 |
{'x': ye.eid, 'y': self.blog.eid}) |
|
374 |
self.req.execute('SET X ambiguous_relation Y WHERE X eid %(x)s, Y eid %(y)s', |
|
375 |
{'x': ye.eid, 'y': self.article.eid}) |
|
376 |
self.commit() |
|
377 |
#ye = self.vreg.etype_class('YamsEntity ')(req, None) |
|
378 |
#ye.to_gae_model()['s_ambiguous_relation'] = [self.blog.key(), self.article.key()] |
|
379 |
#ye.put() |
|
380 |
rset = self.req.execute('Any X WHERE Y ambiguous_relation X') |
|
381 |
self._check_rset_size(rset, 2, 1) |
|
382 |
self.assertUnorderedIterableEquals([r[0] for r in rset], [self.blog.eid, self.article.eid]) |
|
383 |
self.assertUnorderedIterableEquals([r[0] for r in rset.description], ['Blog', 'Article']) |
|
384 |
rset = self.req.execute('Any X WHERE Y ambiguous_relation X, Y eid %(x)s', {'x': ye.eid}) |
|
385 |
self._check_rset_size(rset, 2, 1) |
|
386 |
self.assertUnorderedIterableEquals([r[0] for r in rset], [self.blog.eid, self.article.eid]) |
|
387 |
self.assertUnorderedIterableEquals([r[0] for r in rset.description], ['Blog', 'Article']) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
388 |
|
0 | 389 |
def test_4_relation_selection(self): |
390 |
req = self.request() |
|
391 |
rset = req.execute('Any N WHERE G content N, U talks_about G, U eid %(u)s', {'u': self.blog.eid}) |
|
392 |
self._check_rset_size(rset, 1, 1) |
|
393 |
self.assertEquals(rset[0][0], 'very interesting') |
|
394 |
||
395 |
||
396 |
def test_5_orderby(self): |
|
397 |
self._setup_relation_description() |
|
398 |
rset = self.req.execute('Any X,XC ORDERBY XC WHERE X is Blog, X content XC') |
|
399 |
self._check_rset_size(rset, 3, 2) |
|
400 |
self.assertEquals(rset.rows, |
|
401 |
[[self.blog3.eid, 'hep'], |
|
402 |
[self.blog2.eid, 'hip'], |
|
403 |
[self.blog.eid, 'hop']]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
404 |
|
0 | 405 |
def test_5_orderby_desc(self): |
406 |
self._setup_relation_description() |
|
407 |
rset = self.req.execute('Any X,XC ORDERBY XC DESC WHERE X is Blog, X content XC') |
|
408 |
self._check_rset_size(rset, 3, 2) |
|
409 |
self.assertEquals(rset.rows, |
|
410 |
[[self.blog.eid, 'hop'], |
|
411 |
[self.blog2.eid, 'hip'], |
|
412 |
[self.blog3.eid, 'hep']]) |
|
413 |
||
414 |
def test_5_orderby_several_terms(self): |
|
415 |
self._setup_relation_description() |
|
416 |
rset = self.req.execute('Any X,XC,XI ORDERBY XI,XC WHERE X is Blog, X content XC, X itemtype XI') |
|
417 |
self._check_rset_size(rset, 3, 3) |
|
418 |
self.assertEquals(rset.rows, |
|
419 |
[[self.blog3.eid, 'hep', 'business'], |
|
420 |
[self.blog2.eid, 'hip', 'personal'], |
|
421 |
[self.blog.eid, 'hop', 'personal']]) |
|
422 |
||
423 |
def test_5_orderby_several_terms_mixed_implicit(self): |
|
424 |
self._setup_relation_description() |
|
425 |
rset = self.req.execute('Any X,XC,XI ORDERBY XI,XC DESC WHERE X is Blog, X content XC, X itemtype XI') |
|
426 |
self._check_rset_size(rset, 3, 3) |
|
427 |
self.assertEquals(rset.rows, |
|
428 |
[[self.blog3.eid, 'hep', 'business'], |
|
429 |
[self.blog.eid, 'hop', 'personal'], |
|
430 |
[self.blog2.eid, 'hip', 'personal']]) |
|
431 |
||
432 |
def test_5_orderby_several_terms_explicit_order(self): |
|
433 |
self._setup_relation_description() |
|
434 |
rset = self.req.execute('Any X,XC,XI ORDERBY XI DESC,XC DESC WHERE X is Blog, X content XC, X itemtype XI') |
|
435 |
self._check_rset_size(rset, 3, 3) |
|
436 |
self.assertEquals(rset.rows, |
|
437 |
[[self.blog.eid, 'hop', 'personal'], |
|
438 |
[self.blog2.eid, 'hip', 'personal'], |
|
439 |
[self.blog3.eid, 'hep', 'business']]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
440 |
|
0 | 441 |
def test_5_orderby_several_terms_mixed_order(self): |
442 |
self._setup_relation_description() |
|
443 |
rset = self.req.execute('Any X,XC,XI ORDERBY XI ASC,XC DESC WHERE X is Blog, X content XC, X itemtype XI') |
|
444 |
self._check_rset_size(rset, 3, 3) |
|
445 |
self.assertEquals(rset.rows, |
|
446 |
[[self.blog3.eid, 'hep', 'business'], |
|
447 |
[self.blog.eid, 'hop', 'personal'], |
|
448 |
[self.blog2.eid, 'hip', 'personal']]) |
|
449 |
||
450 |
||
451 |
def test_5_orderby_lower(self): |
|
452 |
blog2 = self.add_entity('Blog', itemtype=u'business', content=u'Hup') |
|
453 |
rset = self.req.execute('Any X ORDERBY LOWER(XC) ' |
|
454 |
'WHERE X is Blog, X content XC') |
|
455 |
self._check_rset_size(rset, 2, 1) |
|
456 |
self.assertEquals(rset.rows, [[self.blog.eid], [blog2.eid]]) |
|
457 |
rset = self.req.execute('Any X ORDERBY LOWER(XC) DESC' |
|
458 |
'WHERE X is Blog, X content XC') |
|
459 |
self._check_rset_size(rset, 2, 1) |
|
460 |
self.assertEquals(rset.rows, [[blog2.eid], [self.blog.eid]]) |
|
461 |
||
462 |
def test_5_orderby_stored_proc(self): |
|
463 |
blog2 = self.add_entity('Blog', itemtype=u'business', content=u'hop') |
|
464 |
rset = self.req.execute('Any X ORDERBY ITEMTYPE_SORT_VALUE(XIT) ' |
|
465 |
'WHERE X is Blog, X itemtype XIT') |
|
466 |
self._check_rset_size(rset, 2, 1) |
|
467 |
self.assertEquals(rset.rows, [[blog2.eid], [self.blog.eid]]) |
|
468 |
rset = self.req.execute('Any X ORDERBY ITEMTYPE_SORT_VALUE(XIT) DESC' |
|
469 |
'WHERE X is Blog, X itemtype XIT') |
|
470 |
self._check_rset_size(rset, 2, 1) |
|
471 |
self.assertEquals(rset.rows, [[self.blog.eid], [blog2.eid]]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
472 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
473 |
|
0 | 474 |
def test_6_limit(self): |
475 |
self._setup_relation_description() |
|
476 |
rset = self.req.execute('Any X LIMIT 2 WHERE X is Blog') |
|
477 |
self._check_rset_size(rset, 2, 1) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
478 |
|
0 | 479 |
def test_6_offset(self): |
480 |
self._setup_relation_description() |
|
481 |
rset = self.req.execute('Any XC ORDERBY XC DESC OFFSET 1 WHERE X is Blog, X content XC') |
|
482 |
self._check_rset_size(rset, 2, 1) |
|
483 |
self.assertEquals(rset.rows, [['hip'], ['hep']]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
484 |
|
0 | 485 |
def test_6_limit_and_orderby(self): |
486 |
self._setup_relation_description() |
|
487 |
rset = self.req.execute('Any XC ORDERBY XC LIMIT 2 WHERE X is Blog, X content XC') |
|
488 |
self._check_rset_size(rset, 2, 1) |
|
489 |
self.assertEquals(rset.rows, [['hep'], ['hip']]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
490 |
|
0 | 491 |
def test_6_limit_offset_and_orderby(self): |
492 |
self._setup_relation_description() |
|
493 |
rset = self.req.execute('Any XC ORDERBY XC LIMIT 2 OFFSET 0 WHERE X is Blog, X content XC') |
|
494 |
self._check_rset_size(rset, 2, 1) |
|
495 |
self.assertEquals(rset.rows, [['hep'], ['hip']]) |
|
496 |
rset = self.req.execute('Any XC ORDERBY XC LIMIT 2 OFFSET 1 WHERE X is Blog, X content XC') |
|
497 |
self._check_rset_size(rset, 2, 1) |
|
498 |
self.assertEquals(rset.rows, [['hip'], ['hop']]) |
|
499 |
rset = self.req.execute('Any XC ORDERBY XC LIMIT 2 OFFSET 2 WHERE X is Blog, X content XC') |
|
500 |
self._check_rset_size(rset, 1, 1) |
|
501 |
self.assertEquals(rset.rows, [['hop']]) |
|
502 |
rset = self.req.execute('Any XC ORDERBY XC LIMIT 2 OFFSET 3 WHERE X is Blog, X content XC') |
|
503 |
self.failIf(rset) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
504 |
|
0 | 505 |
|
506 |
def test_7_simple_datetimecast(self): |
|
507 |
self._setup_relation_description() |
|
508 |
_today = today() |
|
509 |
_tomorrow = _today + 1 |
|
510 |
rset = self.req.execute('Any X WHERE X is Blog, X creation_date >= "%s"' |
|
511 |
% _tomorrow.strftime('%Y-%m-%d')) |
|
512 |
self.failUnless(len(rset) == 0) |
|
513 |
rset = self.req.execute('Any X WHERE X is Blog, X creation_date >= "%s"' |
|
514 |
% _today.strftime('%Y-%m-%d')) |
|
515 |
self._check_rset_size(rset, 3, 1) |
|
516 |
rset = self.req.execute('Any X WHERE X is Blog, X creation_date <= "%s"' |
|
517 |
% _tomorrow.strftime('%Y-%m-%d')) |
|
518 |
self._check_rset_size(rset, 3, 1) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
519 |
|
0 | 520 |
def test_7_identity_relation(self): |
521 |
rset = self.req.execute('Any X WHERE X identity Y, X eid %(x)s, Y eid %(y)s', |
|
522 |
{'x': self.user.eid, 'y': self.user.eid}) |
|
523 |
self._check_rset_size(rset, 1, 1) |
|
524 |
rset = self.req.execute('Any Y WHERE X identity Y, X eid %(x)s', |
|
525 |
{'x': self.user.eid}) |
|
526 |
self._check_rset_size(rset, 1, 1) |
|
527 |
self.assertEquals(rset.rows, [[self.user.eid]]) |
|
528 |
blog2 = self.add_entity('Blog', itemtype=u'personal', content=u'hip') |
|
529 |
rset = self.req.execute('Any X WHERE X identity Y, X eid %(x)s, Y eid %(y)s', |
|
530 |
{'x': self.blog.eid, 'y': blog2.eid}) |
|
531 |
self.failIf(rset) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
532 |
|
0 | 533 |
def test_8_not_relation_1(self): |
534 |
rset = self.req.execute('Any X WHERE X identity U, NOT U in_group G, ' |
|
535 |
'G name "guests", X eid %(x)s, U eid %(u)s', |
|
536 |
{'x': self.user.eid, 'u': self.user.eid}) |
|
537 |
self._check_rset_size(rset, 1, 1) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
538 |
self.assertEquals(rset.rows, [[self.user.eid]]) |
0 | 539 |
|
540 |
def test_8_not_relation_linked_subject(self): |
|
541 |
rset = self.req.execute('Any X WHERE NOT X talks_about Y, Y eid %(y)s', |
|
542 |
{'y': self.article.eid}) |
|
543 |
self.failIf(rset) |
|
544 |
blog2 = self.add_entity('Blog', content=u'hop', itemtype=u'personal') |
|
545 |
self.commit() |
|
546 |
rset = self.req.execute('Any X WHERE NOT X talks_about Y, Y eid %(y)s', |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
547 |
{'y': self.article.eid}) |
0 | 548 |
self._check_rset_size(rset, 1, 1) |
549 |
self.assertEquals(rset.rows, [[blog2.eid]]) |
|
550 |
||
551 |
def test_8_not_relation_linked_object(self): |
|
552 |
rset = self.req.execute('Any Y WHERE NOT X talks_about Y, X eid %(x)s', |
|
553 |
{'x': self.blog.eid}) |
|
554 |
self.failIf(rset) |
|
555 |
article2 = self.add_entity('Article', content=u'hop') |
|
556 |
self.commit() |
|
557 |
rset = self.req.execute('Any Y WHERE NOT X talks_about Y, X eid %(x)s', |
|
558 |
{'x': self.blog.eid}) |
|
559 |
self._check_rset_size(rset, 1, 1) |
|
560 |
self.assertEquals(rset.rows, [[article2.eid]]) |
|
561 |
||
562 |
def test_8_not_relation_linked_attr(self): |
|
563 |
self.skip('not yet implemented') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
564 |
# TODO: this should generated |
0 | 565 |
# Query(X)[s_talks_about] > "hop" || Query(X)[s_talks_about] < "hop" |
566 |
article2 = self.add_entity('Article', content=u'hop') |
|
567 |
self.req.execute('SET X talks_about Y WHERE X eid %(x)s, Y eid %(y)s', |
|
568 |
{'x': self.blog.eid, 'y': article2.eid}) |
|
569 |
self.commit() |
|
570 |
rset = self.req.execute('Any X WHERE NOT X talks_about Y, Y content "hop"') |
|
571 |
self._check_rset_size(rset, 1, 2) |
|
572 |
self.assertEquals(rset.rows, [[self.blog.eid, self.article.eid]]) |
|
573 |
||
574 |
def test_8_not_relation_unlinked_subject(self): |
|
575 |
blog2 = self.add_entity('Blog', content=u'hop', itemtype=u'personal') |
|
576 |
self.commit() |
|
577 |
rset = self.req.execute('Any X WHERE NOT X talks_about Y') |
|
578 |
self._check_rset_size(rset, 1, 1) |
|
579 |
self.assertEquals(rset.rows, [[blog2.eid]]) |
|
580 |
||
581 |
def test_8_not_relation_unlinked_object(self): |
|
582 |
article2 = self.add_entity('Article', content=u'hop') |
|
583 |
self.commit() |
|
584 |
rset = self.req.execute('Any Y WHERE NOT X talks_about Y') |
|
585 |
self._check_rset_size(rset, 1, 1) |
|
586 |
self.assertEquals(rset.rows, [[article2.eid]]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
587 |
|
0 | 588 |
def test_8_not_relation_final_1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
589 |
rset = self.req.execute('Any G WHERE G is CWGroup, NOT G name "guests"') |
0 | 590 |
self._check_rset_size(rset, 2, 1) |
591 |
self.assertUnorderedIterableEquals([g.name for g in rset.entities()], |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
592 |
['users', 'managers']) |
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
593 |
|
0 | 594 |
def test_8_not_relation_final_2(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
595 |
rset = self.req.execute('Any GN WHERE G is CWGroup, NOT G name "guests", G name GN') |
0 | 596 |
self._check_rset_size(rset, 2, 1) |
597 |
self.assertUnorderedIterableEquals([gn for gn, in rset.rows], |
|
598 |
['users', 'managers']) |
|
599 |
||
600 |
||
601 |
def test_9_exists(self): |
|
602 |
blog2 = self.add_entity('Article', content=u'hop') |
|
603 |
article2 = self.add_entity('Article', content=u'hop') |
|
604 |
self.req.execute('SET X talks_about Y WHERE X eid %(x)s, Y eid %(y)s', |
|
605 |
{'x': self.blog.eid, 'y': article2.eid}) |
|
606 |
self.commit() |
|
607 |
rset = self.req.execute('Any X WHERE X is Blog, EXISTS(X talks_about Y)') |
|
608 |
self._check_rset_size(rset, 1, 1) |
|
609 |
self.assertEquals(rset.rows, [[self.blog.eid]]) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
610 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
611 |
|
0 | 612 |
def test_error_unknown_eid(self): |
613 |
rset = self.req.execute('Any X WHERE X eid %(x)s', {'x': '1234'}) |
|
614 |
self.assertEquals(len(rset), 0) |
|
615 |
self.blog.delete() |
|
616 |
rset = self.req.execute('Any X WHERE X eid %(x)s', {'x': self.blog.eid}) |
|
617 |
self.assertEquals(len(rset), 0) |
|
618 |
||
619 |
def test_nonregr_inlined_relation(self): |
|
620 |
eid = self.execute('INSERT YamsEntity X: X inlined_relation Y WHERE Y eid %(y)s', |
|
621 |
{'y': self.blog.eid})[0][0] |
|
622 |
self.commit() |
|
623 |
rset = self.execute('Any X WHERE Y inlined_relation X, Y eid %(y)s', {'y': eid}) |
|
624 |
self._check_rset_size(rset, 1, 1) |
|
625 |
self.assertEquals(rset[0][0], self.blog.eid) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
626 |
|
0 | 627 |
if __name__ == '__main__': |
628 |
unittest_main() |