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