author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 20 May 2015 15:12:58 +0200 | |
changeset 10427 | 7677c0401864 |
parent 10354 | 635cfac73d28 |
child 10467 | 73ea636a5562 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
9731
027bfc467a46
[cache] fix a cache issue with an entity created without relation cache prefill
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9432
diff
changeset
|
2 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6173 | 19 |
"""unit tests for cubicweb.web.views.entities module""" |
0 | 20 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
821
diff
changeset
|
21 |
from datetime import datetime |
8161
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
22 |
|
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
23 |
from logilab.common import tempattr |
8161
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
24 |
from logilab.common.decorators import clear_cache |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
25 |
|
9877
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
26 |
from cubicweb import Binary |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
27 |
from cubicweb.devtools.testlib import CubicWebTC |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4015
diff
changeset
|
28 |
from cubicweb.mttransforms import HAS_TAL |
9319
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
29 |
from cubicweb.entity import can_use_rest_path |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
30 |
from cubicweb.entities import fetch_config |
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6427
diff
changeset
|
31 |
from cubicweb.uilib import soup2xhtml |
9877
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
32 |
from cubicweb.schema import RRQLExpression |
0 | 33 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
34 |
class EntityTC(CubicWebTC): |
1640 | 35 |
|
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
36 |
def setUp(self): |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
37 |
super(EntityTC, self).setUp() |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
38 |
self.backup_dict = {} |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
39 |
for cls in self.vreg['etypes'].iter_classes(): |
7827
9bbf83f68bcc
[entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7798
diff
changeset
|
40 |
self.backup_dict[cls] = (cls.fetch_attrs, cls.cw_fetch_order) |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
41 |
|
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
42 |
def tearDown(self): |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
43 |
super(EntityTC, self).tearDown() |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
44 |
for cls in self.vreg['etypes'].iter_classes(): |
7827
9bbf83f68bcc
[entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7798
diff
changeset
|
45 |
cls.fetch_attrs, cls.cw_fetch_order = self.backup_dict[cls] |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
46 |
|
9731
027bfc467a46
[cache] fix a cache issue with an entity created without relation cache prefill
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9432
diff
changeset
|
47 |
def test_no_prefill_related_cache_bug(self): |
9877
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
48 |
with self.admin_access.repo_cnx() as cnx: |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
49 |
usine = cnx.create_entity('Usine', lieu=u'Montbeliard') |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
50 |
produit = cnx.create_entity('Produit') |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
51 |
# usine was prefilled in glob_add_entity |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
52 |
# let's simulate produit creation without prefill |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
53 |
produit._cw_related_cache.clear() |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
54 |
# use add_relations |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
55 |
cnx.add_relations([('fabrique_par', [(produit.eid, usine.eid)])]) |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
56 |
self.assertEqual(1, len(usine.reverse_fabrique_par)) |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
57 |
self.assertEqual(1, len(produit.fabrique_par)) |
9731
027bfc467a46
[cache] fix a cache issue with an entity created without relation cache prefill
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9432
diff
changeset
|
58 |
|
0 | 59 |
def test_boolean_value(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
60 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
61 |
e = self.vreg['etypes'].etype_class('CWUser')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
62 |
self.assertTrue(e) |
0 | 63 |
|
64 |
def test_yams_inheritance(self): |
|
748 | 65 |
from entities import Note |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
66 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
67 |
e = self.vreg['etypes'].etype_class('SubNote')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
68 |
self.assertIsInstance(e, Note) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
69 |
e2 = self.vreg['etypes'].etype_class('SubNote')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
70 |
self.assertIs(e.__class__, e2.__class__) |
0 | 71 |
|
72 |
def test_has_eid(self): |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
73 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
74 |
e = self.vreg['etypes'].etype_class('CWUser')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
75 |
self.assertEqual(e.eid, None) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
76 |
self.assertEqual(e.has_eid(), False) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
77 |
e.eid = 'X' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
78 |
self.assertEqual(e.has_eid(), False) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
79 |
e.eid = 0 |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
80 |
self.assertEqual(e.has_eid(), True) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
81 |
e.eid = 2 |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
82 |
self.assertEqual(e.has_eid(), True) |
1640 | 83 |
|
0 | 84 |
def test_copy(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
85 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
86 |
req.create_entity('Tag', name=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
87 |
p = req.create_entity('Personne', nom=u'toto') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
88 |
oe = req.create_entity('Note', type=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
89 |
req.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
90 |
{'t': oe.eid, 'u': p.eid}) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
91 |
req.execute('SET TAG tags X WHERE X eid %(x)s', {'x': oe.eid}) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
92 |
e = req.create_entity('Note', type=u'z') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
93 |
e.copy_relations(oe.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
94 |
self.assertEqual(len(e.ecrit_par), 1) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
95 |
self.assertEqual(e.ecrit_par[0].eid, p.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
96 |
self.assertEqual(len(e.reverse_tags), 1) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
97 |
# check meta-relations are not copied, set on commit |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
98 |
self.assertEqual(len(e.created_by), 0) |
1640 | 99 |
|
0 | 100 |
def test_copy_with_nonmeta_composite_inlined(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
101 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
102 |
p = req.create_entity('Personne', nom=u'toto') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
103 |
oe = req.create_entity('Note', type=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
104 |
self.schema['ecrit_par'].rdef('Note', 'Personne').composite = 'subject' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
105 |
req.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
106 |
{'t': oe.eid, 'u': p.eid}) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
107 |
e = req.create_entity('Note', type=u'z') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
108 |
e.copy_relations(oe.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
109 |
self.assertFalse(e.ecrit_par) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
110 |
self.assertTrue(oe.ecrit_par) |
1640 | 111 |
|
0 | 112 |
def test_copy_with_composite(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
113 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
114 |
adeleid = req.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
115 |
e = req.execute('Any X WHERE X eid %(x)s', {'x': req.user.eid}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
116 |
self.assertEqual(e.use_email[0].address, "toto@logilab.org") |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
117 |
self.assertEqual(e.use_email[0].eid, adeleid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
118 |
usereid = req.execute('INSERT CWUser X: X login "toto", X upassword "toto", X in_group G ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
119 |
'WHERE G name "users"')[0][0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
120 |
e = req.execute('Any X WHERE X eid %(x)s', {'x': usereid}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
121 |
e.copy_relations(req.user.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
122 |
self.assertFalse(e.use_email) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
123 |
self.assertFalse(e.primary_email) |
1640 | 124 |
|
0 | 125 |
def test_copy_with_non_initial_state(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
126 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
127 |
user = req.execute('INSERT CWUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
128 |
{'pwd': 'toto'}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
129 |
req.cnx.commit() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
130 |
user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
131 |
req.cnx.commit() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
132 |
eid2 = req.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
133 |
e = req.execute('Any X WHERE X eid %(x)s', {'x': eid2}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
134 |
e.copy_relations(user.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
135 |
req.cnx.commit() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
136 |
e.cw_clear_relation_cache('in_state', 'subject') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
137 |
self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated') |
0 | 138 |
|
139 |
def test_related_cache_both(self): |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
140 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
141 |
user = req.execute('Any X WHERE X eid %(x)s', {'x':req.user.eid}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
142 |
adeleid = req.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
10354
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
143 |
self.assertEqual({}, user._cw_related_cache) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
144 |
req.cnx.commit() |
10354
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
145 |
self.assertEqual(['primary_email_subject', 'use_email_subject', 'wf_info_for_object'], |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
146 |
sorted(user._cw_related_cache)) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
147 |
email = user.primary_email[0] |
10354
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
148 |
self.assertEqual(u'toto@logilab.org', email.address) |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
149 |
self.assertEqual(['created_by_subject', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
150 |
'cw_source_subject', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
151 |
'is_instance_of_subject', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
152 |
'is_subject', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
153 |
'owned_by_subject', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
154 |
'prefered_form_object', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
155 |
'prefered_form_subject', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
156 |
'primary_email_object', |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
157 |
'use_email_object'], |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
158 |
sorted(email._cw_related_cache)) |
635cfac73d28
[repoapi] fold ClientConnection into Connection
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10136
diff
changeset
|
159 |
self.assertEqual('admin', email._cw_related_cache['primary_email_object'][1][0].login) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
160 |
groups = user.in_group |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
161 |
for group in groups: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
162 |
self.assertNotIn('in_group_subject', group._cw_related_cache) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
163 |
user.cw_clear_all_caches() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
164 |
user.related('in_group', entities=True) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
165 |
self.assertIn('in_group_subject', user._cw_related_cache) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
166 |
user.cw_clear_all_caches() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
167 |
user.related('in_group', targettypes=('CWGroup',), entities=True) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
168 |
self.assertNotIn('in_group_subject', user._cw_related_cache) |
413
a7366dd3c33c
fix bug in entity.related_rql(): fetch_attr list / fetchorder weren't computed correctly
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
169 |
|
0 | 170 |
def test_related_limit(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
171 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
172 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
173 |
for tag in u'abcd': |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
174 |
req.create_entity('Tag', name=tag) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
175 |
req.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
176 |
self.assertEqual(len(p.related('tags', 'object', limit=2)), 2) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
177 |
self.assertEqual(len(p.related('tags', 'object')), 4) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
178 |
p.cw_clear_all_caches() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
179 |
self.assertEqual(len(p.related('tags', 'object', entities=True, limit=2)), 2) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
180 |
self.assertEqual(len(p.related('tags', 'object', entities=True)), 4) |
0 | 181 |
|
9293
723e2c586ea3
[entity] Entity.related(): add a targettypes argument (closes #2957313)
Aurelien Campeas
parents:
9283
diff
changeset
|
182 |
def test_related_targettypes(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
183 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
184 |
p = req.create_entity('Personne', nom=u'Loxodonta', prenom=u'Babar') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
185 |
n = req.create_entity('Note', type=u'scratch', ecrit_par=p) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
186 |
t = req.create_entity('Tag', name=u'a tag', tags=(p, n)) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
187 |
req.cnx.commit() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
188 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
189 |
t = req.entity_from_eid(t.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
190 |
self.assertEqual(2, t.related('tags').rowcount) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
191 |
self.assertEqual(1, t.related('tags', targettypes=('Personne',)).rowcount) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
192 |
self.assertEqual(1, t.related('tags', targettypes=('Note',)).rowcount) |
9293
723e2c586ea3
[entity] Entity.related(): add a targettypes argument (closes #2957313)
Aurelien Campeas
parents:
9283
diff
changeset
|
193 |
|
7376
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7308
diff
changeset
|
194 |
def test_cw_instantiate_relation(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
195 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
196 |
p1 = req.create_entity('Personne', nom=u'di') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
197 |
p2 = req.create_entity('Personne', nom=u'mascio') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
198 |
t = req.create_entity('Tag', name=u't0', tags=[]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
199 |
self.assertCountEqual(t.tags, []) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
200 |
t = req.create_entity('Tag', name=u't1', tags=p1) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
201 |
self.assertCountEqual(t.tags, [p1]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
202 |
t = req.create_entity('Tag', name=u't2', tags=p1.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
203 |
self.assertCountEqual(t.tags, [p1]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
204 |
t = req.create_entity('Tag', name=u't3', tags=[p1, p2.eid]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
205 |
self.assertCountEqual(t.tags, [p1, p2]) |
7376
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7308
diff
changeset
|
206 |
|
38524ca653e5
[entity] fix cw_instantiate w/ reverse_ relation crash when either multiple entities are given or an eid instead of an entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7308
diff
changeset
|
207 |
def test_cw_instantiate_reverse_relation(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
208 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
209 |
t1 = req.create_entity('Tag', name=u't1') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
210 |
t2 = req.create_entity('Tag', name=u't2') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
211 |
p = req.create_entity('Personne', nom=u'di mascio', reverse_tags=t1) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
212 |
self.assertCountEqual(p.reverse_tags, [t1]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
213 |
p = req.create_entity('Personne', nom=u'di mascio', reverse_tags=t1.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
214 |
self.assertCountEqual(p.reverse_tags, [t1]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
215 |
p = req.create_entity('Personne', nom=u'di mascio', reverse_tags=[t1, t2.eid]) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
216 |
self.assertCountEqual(p.reverse_tags, [t1, t2]) |
1640 | 217 |
|
0 | 218 |
def test_fetch_rql(self): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
219 |
Personne = self.vreg['etypes'].etype_class('Personne') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
220 |
Societe = self.vreg['etypes'].etype_class('Societe') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
221 |
Note = self.vreg['etypes'].etype_class('Note') |
0 | 222 |
peschema = Personne.e_schema |
223 |
seschema = Societe.e_schema |
|
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
224 |
torestore = [] |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
225 |
for rdef, card in [(peschema.subjrels['travaille'].rdef(peschema, seschema), '1*'), |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
226 |
(peschema.subjrels['connait'].rdef(peschema, peschema), '11'), |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
227 |
(peschema.subjrels['evaluee'].rdef(peschema, Note.e_schema), '1*'), |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
228 |
(seschema.subjrels['evaluee'].rdef(seschema, Note.e_schema), '1*')]: |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
229 |
cm = tempattr(rdef, 'cardinality', card) |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
230 |
cm.__enter__() |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
231 |
torestore.append(cm) |
0 | 232 |
try: |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
233 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
234 |
user = req.user |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
235 |
# testing basic fetch_attrs attribute |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
236 |
self.assertEqual(Personne.fetch_rql(user), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
237 |
'Any X,AA,AB,AC ORDERBY AA ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
238 |
'WHERE X is_instance_of Personne, X nom AA, X prenom AB, X modification_date AC') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
239 |
# testing unknown attributes |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
240 |
Personne.fetch_attrs = ('bloug', 'beep') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
241 |
self.assertEqual(Personne.fetch_rql(user), 'Any X WHERE X is_instance_of Personne') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
242 |
# testing one non final relation |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
243 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
244 |
self.assertEqual(Personne.fetch_rql(user), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
245 |
'Any X,AA,AB,AC,AD ORDERBY AA ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
246 |
'WHERE X is_instance_of Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
247 |
# testing two non final relations |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
248 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
249 |
self.assertEqual(Personne.fetch_rql(user), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
250 |
'Any X,AA,AB,AC,AD,AE ORDERBY AA ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
251 |
'WHERE X is_instance_of Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
252 |
'X evaluee AE?') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
253 |
# testing one non final relation with recursion |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
254 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
255 |
Societe.fetch_attrs = ('nom', 'evaluee') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
256 |
self.assertEqual(Personne.fetch_rql(user), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
257 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA,AF DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
258 |
'WHERE X is_instance_of Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
259 |
'AC evaluee AE?, AE modification_date AF' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
260 |
) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
261 |
# testing symmetric relation |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
262 |
Personne.fetch_attrs = ('nom', 'connait') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
263 |
self.assertEqual(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
264 |
'WHERE X is_instance_of Personne, X nom AA, X connait AB?') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
265 |
# testing optional relation |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
266 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '?*' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
267 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
268 |
Societe.fetch_attrs = ('nom',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
269 |
self.assertEqual(Personne.fetch_rql(user), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
270 |
'Any X,AA,AB,AC,AD ORDERBY AA WHERE X is_instance_of Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
271 |
# testing relation with cardinality > 1 |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
272 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '**' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
273 |
self.assertEqual(Personne.fetch_rql(user), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
274 |
'Any X,AA,AB ORDERBY AA WHERE X is_instance_of Personne, X nom AA, X prenom AB') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
275 |
# XXX test unauthorized attribute |
0 | 276 |
finally: |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
277 |
# fetch_attrs restored by generic tearDown |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
278 |
for cm in torestore: |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
279 |
cm.__exit__(None, None, None) |
0 | 280 |
|
4630
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
281 |
def test_related_rql_base(self): |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
282 |
Personne = self.vreg['etypes'].etype_class('Personne') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2635
diff
changeset
|
283 |
Note = self.vreg['etypes'].etype_class('Note') |
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
284 |
SubNote = self.vreg['etypes'].etype_class('SubNote') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
285 |
self.assertTrue(issubclass(self.vreg['etypes'].etype_class('SubNote'), Note)) |
7827
9bbf83f68bcc
[entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7798
diff
changeset
|
286 |
Personne.fetch_attrs, Personne.cw_fetch_order = fetch_config(('nom', 'type')) |
9bbf83f68bcc
[entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7798
diff
changeset
|
287 |
Note.fetch_attrs, Note.cw_fetch_order = fetch_config(('type',)) |
9bbf83f68bcc
[entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7798
diff
changeset
|
288 |
SubNote.fetch_attrs, SubNote.cw_fetch_order = fetch_config(('type',)) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
289 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
290 |
p = req.create_entity('Personne', nom=u'pouet') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
291 |
self.assertEqual(p.cw_related_rql('evaluee'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
292 |
'Any X,AA,AB ORDERBY AA WHERE E eid %(x)s, E evaluee X, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
293 |
'X type AA, X modification_date AB') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
294 |
n = req.create_entity('Note') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
295 |
self.assertEqual(n.cw_related_rql('evaluee', role='object', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
296 |
targettypes=('Societe', 'Personne')), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
297 |
"Any X,AA ORDERBY AB DESC WHERE E eid %(x)s, X evaluee E, " |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
298 |
"X is IN(Personne, Societe), X nom AA, " |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
299 |
"X modification_date AB") |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
300 |
Personne.fetch_attrs, Personne.cw_fetch_order = fetch_config(('nom', )) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
301 |
# XXX |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
302 |
self.assertEqual(p.cw_related_rql('evaluee'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
303 |
'Any X,AA ORDERBY AA DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
304 |
'WHERE E eid %(x)s, E evaluee X, X modification_date AA') |
3672
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
305 |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
306 |
tag = self.vreg['etypes'].etype_class('Tag')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
307 |
self.assertEqual(tag.cw_related_rql('tags', 'subject'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
308 |
'Any X,AA ORDERBY AA DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
309 |
'WHERE E eid %(x)s, E tags X, X modification_date AA') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
310 |
self.assertEqual(tag.cw_related_rql('tags', 'subject', ('Personne',)), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
311 |
'Any X,AA,AB ORDERBY AA ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
312 |
'WHERE E eid %(x)s, E tags X, X is Personne, X nom AA, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
313 |
'X modification_date AB') |
1640 | 314 |
|
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7376
diff
changeset
|
315 |
def test_related_rql_ambiguous_cant_use_fetch_order(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
316 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
317 |
tag = self.vreg['etypes'].etype_class('Tag')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
318 |
for ttype in self.schema['tags'].objects(): |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
319 |
self.vreg['etypes'].etype_class(ttype).fetch_attrs = ('modification_date',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
320 |
self.assertEqual(tag.cw_related_rql('tags', 'subject'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
321 |
'Any X,AA ORDERBY AA DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
322 |
'WHERE E eid %(x)s, E tags X, X modification_date AA') |
4630
528dee042927
fix #694445: related entity generates weird RQL which in turn generates weird SQL which fails on SQL Server
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
323 |
|
7798
8930f7a284dd
[entity fetchattrs] also fetch ambiguous rtypes even if we do not recurse on them (closes #1720823)
Florent Cayré <florent.cayre@gmail.com>
parents:
7794
diff
changeset
|
324 |
def test_related_rql_fetch_ambiguous_rtype(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
325 |
etvreg = self.vreg['etypes'] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
326 |
soc_etype = etvreg.etype_class('Societe') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
327 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
328 |
soc = soc_etype(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
329 |
soc_etype.fetch_attrs = ('fournit',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
330 |
etvreg.etype_class('Service').fetch_attrs = ('fabrique_par',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
331 |
etvreg.etype_class('Produit').fetch_attrs = ('fabrique_par',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
332 |
etvreg.etype_class('Usine').fetch_attrs = ('lieu',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
333 |
etvreg.etype_class('Personne').fetch_attrs = ('nom',) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
334 |
self.assertEqual(soc.cw_related_rql('fournit', 'subject'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
335 |
'Any X,A WHERE E eid %(x)s, E fournit X, X fabrique_par A') |
7425
7e9d1d6fcba7
[entity fetch_attrs] remove ambiguous relations on different etypes from fetched attrs or it may produce wrong related results; closes #1700896
Florent Cayré <florent.cayre@gmail.com>
parents:
7376
diff
changeset
|
336 |
|
7139
20807d3d7cf6
[rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
337 |
def test_unrelated_rql_security_1_manager(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
338 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
339 |
user = req.user |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
340 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
341 |
self.assertEqual(rql, |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
342 |
'Any O,AA,AB,AC ORDERBY AC DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
343 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
344 |
'O is_instance_of EmailAddress, O address AA, O alias AB, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
345 |
'O modification_date AC') |
7139
20807d3d7cf6
[rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
346 |
|
20807d3d7cf6
[rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
347 |
def test_unrelated_rql_security_1_user(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
348 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
349 |
self.create_user(req, 'toto') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
350 |
with self.new_access('toto').web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
351 |
user = req.user # XXX |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
352 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
353 |
self.assertEqual(rql, |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
354 |
'Any O,AA,AB,AC ORDERBY AC DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
355 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
356 |
'O is_instance_of EmailAddress, O address AA, O alias AB, O modification_date AC') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
357 |
user = req.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
358 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
359 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
360 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
361 |
'O is EmailAddress, O address AA, O alias AB, O modification_date AC, AD eid %(AE)s, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
362 |
'EXISTS(S identity AD, NOT AD in_group AF, AF name "guests", AF is CWGroup), A is CWUser') |
7139
20807d3d7cf6
[rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
363 |
|
20807d3d7cf6
[rql rewriter] to properly handle 'relation' rql expressions, rql rewriter must support multiple variables (eg S and O) at once to be given as varmap
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6685
diff
changeset
|
364 |
def test_unrelated_rql_security_1_anon(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
365 |
with self.new_access('anon').web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
366 |
user = req.user |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
367 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
368 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
369 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
370 |
'O is EmailAddress, O address AA, O alias AB, O modification_date AC, AD eid %(AE)s, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
371 |
'EXISTS(S identity AD, NOT AD in_group AF, AF name "guests", AF is CWGroup), A is CWUser') |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
372 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
373 |
def test_unrelated_rql_security_2(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
374 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
375 |
email = req.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
376 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
377 |
self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
378 |
'WHERE NOT S use_email O, O eid %(x)s, S is_instance_of CWUser, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
379 |
'S login AA, S firstname AB, S surname AC, S modification_date AD') |
9774
b7b71be569cf
deprecate get/set_shared_data API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9770
diff
changeset
|
380 |
req.cnx.commit() |
8161
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
381 |
rperms = self.schema['EmailAddress'].permissions['read'] |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
382 |
clear_cache(self.schema['EmailAddress'], 'get_groups') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
383 |
clear_cache(self.schema['EmailAddress'], 'get_rqlexprs') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
384 |
self.schema['EmailAddress'].permissions['read'] = ('managers', 'users', 'guests',) |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
385 |
try: |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
386 |
with self.new_access('anon').web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
387 |
email = req.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
388 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
389 |
self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
8161
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
390 |
'WHERE NOT S use_email O, O eid %(x)s, S is CWUser, ' |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
391 |
'S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
392 |
'AE eid %(AF)s, EXISTS(S identity AE, NOT AE in_group AG, AG name "guests", AG is CWGroup)') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
393 |
finally: |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
394 |
clear_cache(self.schema['EmailAddress'], 'get_groups') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
395 |
clear_cache(self.schema['EmailAddress'], 'get_rqlexprs') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
396 |
self.schema['EmailAddress'].permissions['read'] = rperms |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
397 |
|
9712
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
398 |
def test_cw_linkable_rql(self): |
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
399 |
with self.admin_access.web_request() as req: |
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
400 |
email = req.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
401 |
rql = email.cw_linkable_rql('use_email', 'CWUser', 'object')[0] |
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
402 |
self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
403 |
'WHERE O eid %(x)s, S is_instance_of CWUser, ' |
6c6cd8c4b256
[entity] add a new `cw_linkable_rql` method
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
9638
diff
changeset
|
404 |
'S login AA, S firstname AB, S surname AC, S modification_date AD') |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
405 |
|
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
406 |
def test_unrelated_rql_security_nonexistant(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
407 |
with self.new_access('anon').web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
408 |
email = self.vreg['etypes'].etype_class('EmailAddress')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
409 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
410 |
self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
7177
0f2905cbe443
[entity vocab] fix bug introduced in 3.12 vs/ entity vocabulary, leading to some unexpected empty vocabulary. Fix test accordingly.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7154
diff
changeset
|
411 |
'WHERE S is CWUser, ' |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
412 |
'S login AA, S firstname AB, S surname AC, S modification_date AD, ' |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
413 |
'AE eid %(AF)s, EXISTS(S identity AE, NOT AE in_group AG, AG name "guests", AG is CWGroup)') |
3826
0c0c051863cb
close #511810: bad rql generated when looking for vocabulary for a relation on an entity which doesn't exist (yet)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3771
diff
changeset
|
414 |
|
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
415 |
def test_unrelated_rql_constraints_creation_subject(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
416 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
417 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
418 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
419 |
self.assertEqual( |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
420 |
rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9340
diff
changeset
|
421 |
'O is_instance_of Personne, O nom AA, O prenom AB, O modification_date AC') |
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
422 |
|
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
423 |
def test_unrelated_rql_constraints_creation_object(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
424 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
425 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
426 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'object')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
427 |
self.assertEqual( |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
428 |
rql, 'Any S,AA,AB,AC ORDERBY AC DESC WHERE ' |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
429 |
'S is Personne, S nom AA, S prenom AB, S modification_date AC, ' |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
430 |
'NOT (S connait AD, AD nom "toto"), AD is Personne, ' |
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
431 |
'EXISTS(S travaille AE, AE nom "tutu")') |
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
432 |
|
8472
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
433 |
def test_unrelated_rql_security_rel_perms(self): |
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
434 |
'''check `connait` add permission has no effect for a new entity on the |
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
435 |
unrelated rql''' |
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
436 |
rdef = self.schema['Personne'].rdef('connait') |
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
437 |
perm_rrqle = RRQLExpression('U has_update_permission S') |
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
438 |
with self.temporary_permissions((rdef, {'add': (perm_rrqle,)})): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
439 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
440 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
441 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
442 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |
9359
31a1813d53f3
[entity/url publishing] fetch_rqlst should use 'is_instance_of' instead of 'is'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9340
diff
changeset
|
443 |
'O is_instance_of Personne, O nom AA, O prenom AB, ' |
8472
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
444 |
'O modification_date AC') |
444a8e25c940
[entity] fix unrelated_rql for creation form vocabulary for relation with specific permissions (closes #2423854)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8307
diff
changeset
|
445 |
|
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
446 |
def test_unrelated_rql_constraints_edition_subject(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
447 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
448 |
person = req.create_entity('Personne', nom=u'sylvain') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
449 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
450 |
self.assertEqual( |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
451 |
rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
452 |
'NOT S connait O, S eid %(x)s, O is Personne, ' |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
453 |
'O nom AA, O prenom AB, O modification_date AC, ' |
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
454 |
'NOT S identity O') |
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
455 |
|
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
456 |
def test_unrelated_rql_constraints_edition_object(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
457 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
458 |
person = req.create_entity('Personne', nom=u'sylvain') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
459 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'object')[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
460 |
self.assertEqual( |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
461 |
rql, 'Any S,AA,AB,AC ORDERBY AC DESC WHERE ' |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
462 |
'NOT S connait O, O eid %(x)s, S is Personne, ' |
7154
5e2f93b88d86
[entity vocabulary] refactor unrelated rql to allow usage of RQLRewriter to insert schema constraints. Closes #1561806
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7153
diff
changeset
|
463 |
'S nom AA, S prenom AB, S modification_date AC, ' |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
464 |
'NOT S identity O, NOT (S connait AD, AD nom "toto"), ' |
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7791
diff
changeset
|
465 |
'EXISTS(S travaille AE, AE nom "tutu")') |
7153
7df83a6d17c0
[entity vocabulary] fix unrelated rql generation to skip rql constraints that don't make sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7139
diff
changeset
|
466 |
|
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
467 |
def test_unrelated_rql_s_linkto_s(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
468 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
469 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
470 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
471 |
soc = req.create_entity('Societe', nom=u'logilab') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
472 |
lt_infos = {('actionnaire', 'subject'): [soc.eid]} |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
473 |
rql, args = person.cw_unrelated_rql('associe', 'Personne', 'subject', |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
474 |
lt_infos=lt_infos) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
475 |
self.assertEqual(u'Any O ORDERBY O WHERE O is Personne, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
476 |
u'EXISTS(AA eid %(SOC)s, O actionnaire AA)', rql) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
477 |
self.assertEqual({'SOC': soc.eid}, args) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
478 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
479 |
def test_unrelated_rql_s_linkto_o(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
480 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
481 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
482 |
self.vreg['etypes'].etype_class('Societe').fetch_attrs = () |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
483 |
soc = req.create_entity('Societe', nom=u'logilab') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
484 |
lt_infos = {('contrat_exclusif', 'object'): [soc.eid]} |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
485 |
rql, args = person.cw_unrelated_rql('actionnaire', 'Societe', 'subject', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
486 |
lt_infos=lt_infos) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
487 |
self.assertEqual(u'Any O ORDERBY O WHERE NOT A actionnaire O, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
488 |
u'O is_instance_of Societe, NOT EXISTS(O eid %(O)s), ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
489 |
u'A is Personne', rql) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
490 |
self.assertEqual({'O': soc.eid}, args) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
491 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
492 |
def test_unrelated_rql_o_linkto_s(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
493 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
494 |
soc = self.vreg['etypes'].etype_class('Societe')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
495 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
496 |
person = req.create_entity('Personne', nom=u'florent') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
497 |
lt_infos = {('contrat_exclusif', 'subject'): [person.eid]} |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
498 |
rql, args = soc.cw_unrelated_rql('actionnaire', 'Personne', 'object', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
499 |
lt_infos=lt_infos) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
500 |
self.assertEqual(u'Any S ORDERBY S WHERE NOT S actionnaire A, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
501 |
u'S is_instance_of Personne, NOT EXISTS(S eid %(S)s), ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
502 |
u'A is Societe', rql) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
503 |
self.assertEqual({'S': person.eid}, args) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
504 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
505 |
def test_unrelated_rql_o_linkto_o(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
506 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
507 |
soc = self.vreg['etypes'].etype_class('Societe')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
508 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
509 |
person = req.create_entity('Personne', nom=u'florent') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
510 |
lt_infos = {('actionnaire', 'object'): [person.eid]} |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
511 |
rql, args = soc.cw_unrelated_rql('dirige', 'Personne', 'object', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
512 |
lt_infos=lt_infos) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
513 |
self.assertEqual(u'Any S ORDERBY S WHERE NOT S dirige A, ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
514 |
u'S is_instance_of Personne, EXISTS(S eid %(S)s), ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
515 |
u'A is Societe', rql) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
516 |
self.assertEqual({'S': person.eid}, args) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
517 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
518 |
def test_unrelated_rql_s_linkto_s_no_info(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
519 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
520 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
521 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
522 |
soc = req.create_entity('Societe', nom=u'logilab') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
523 |
rql, args = person.cw_unrelated_rql('associe', 'Personne', 'subject') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
524 |
self.assertEqual(u'Any O ORDERBY O WHERE O is_instance_of Personne', rql) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
525 |
self.assertEqual({}, args) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
526 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
527 |
def test_unrelated_rql_s_linkto_s_unused_info(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
528 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
529 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
530 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
531 |
other_p = req.create_entity('Personne', nom=u'titi') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
532 |
lt_infos = {('dirige', 'subject'): [other_p.eid]} |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
533 |
rql, args = person.cw_unrelated_rql('associe', 'Personne', 'subject', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
534 |
lt_infos=lt_infos) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
535 |
self.assertEqual(u'Any O ORDERBY O WHERE O is_instance_of Personne', rql) |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
536 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
537 |
def test_unrelated_base(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
538 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
539 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
540 |
e = req.create_entity('Tag', name=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
541 |
related = [r.eid for r in e.tags] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
542 |
self.assertEqual(related, []) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
543 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
544 |
self.assertIn(p.eid, unrelated) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
545 |
req.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
546 |
e = req.execute('Any X WHERE X is Tag').get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
547 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
9638
3046bae3ce31
[test] replace some assert{True,False} with more specific method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9637
diff
changeset
|
548 |
self.assertNotIn(p.eid, unrelated) |
0 | 549 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
550 |
def test_unrelated_limit(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
551 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
552 |
e = req.create_entity('Tag', name=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
553 |
req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
554 |
req.create_entity('Personne', nom=u'thenault', prenom=u'sylvain') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
555 |
self.assertEqual(len(e.unrelated('tags', 'Personne', 'subject', limit=1)), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
556 |
1) |
1640 | 557 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
558 |
def test_unrelated_security(self): |
8161
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
559 |
rperms = self.schema['EmailAddress'].permissions['read'] |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
560 |
clear_cache(self.schema['EmailAddress'], 'get_groups') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
561 |
clear_cache(self.schema['EmailAddress'], 'get_rqlexprs') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
562 |
self.schema['EmailAddress'].permissions['read'] = ('managers', 'users', 'guests',) |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
563 |
try: |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
564 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
565 |
email = req.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
566 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
567 |
self.assertEqual([x.login for x in rset.entities()], [u'admin', u'anon']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
568 |
user = req.user |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
569 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
570 |
self.assertEqual([x.address for x in rset.entities()], [u'hop']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
571 |
self.create_user(req, 'toto') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
572 |
with self.new_access('toto').web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
573 |
email = req.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
574 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
575 |
self.assertEqual([x.login for x in rset.entities()], ['toto']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
576 |
user = req.user |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
577 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
578 |
self.assertEqual([x.address for x in rset.entities()], ['hop']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
579 |
user = req.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
580 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
581 |
self.assertEqual([x.address for x in rset.entities()], []) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
582 |
with self.new_access('anon').web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
583 |
email = req.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
584 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
585 |
self.assertEqual([x.login for x in rset.entities()], []) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
586 |
user = req.user |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
587 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
588 |
self.assertEqual([x.address for x in rset.entities()], []) |
8161
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
589 |
finally: |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
590 |
clear_cache(self.schema['EmailAddress'], 'get_groups') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
591 |
clear_cache(self.schema['EmailAddress'], 'get_rqlexprs') |
6f4229eb8178
[test] fix test broken by 8158:2ee254e74382 and add a test for that change
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7973
diff
changeset
|
592 |
self.schema['EmailAddress'].permissions['read'] = rperms |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
593 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
594 |
def test_unrelated_new_entity(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
595 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
596 |
e = self.vreg['etypes'].etype_class('CWUser')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
597 |
unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
598 |
# should be default groups but owners, i.e. managers, users, guests |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
599 |
self.assertEqual(len(unrelated), 3) |
0 | 600 |
|
10012
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
601 |
def test_markdown_printable_value_string(self): |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
602 |
with self.admin_access.web_request() as req: |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
603 |
e = req.create_entity('Card', title=u'rest markdown', |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
604 |
content=u'This is [an example](http://example.com/ "Title") inline link`', |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
605 |
content_format=u'text/markdown') |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
606 |
self.assertEqual( |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
607 |
u'<p>This is <a href="http://example.com/" ' |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
608 |
u'title="Title">an example</a> inline link`</p>', |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
609 |
e.printable_value('content')) |
8c2c6fdd8d56
[RichString] Add markdown support
Christophe de Vienne <christophe@unlish.com>
parents:
9978
diff
changeset
|
610 |
|
0 | 611 |
def test_printable_value_string(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
612 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
613 |
e = req.create_entity('Card', title=u'rest test', |
10116
4e9738f5c798
[test] fixes to make tests pass with recent lxml
David Douard <david.douard@logilab.fr>
parents:
9978
diff
changeset
|
614 |
content=u'du :eid:`1:*ReST*`', |
4e9738f5c798
[test] fixes to make tests pass with recent lxml
David Douard <david.douard@logilab.fr>
parents:
9978
diff
changeset
|
615 |
content_format=u'text/rest') |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
616 |
self.assertEqual(e.printable_value('content'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
617 |
'<p>du <a class="reference" href="http://testing.fr/cubicweb/cwsource/system">*ReST*</a></p>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
618 |
e.cw_attr_cache['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
619 |
e.cw_attr_cache['content_format'] = 'text/html' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
620 |
self.assertEqual(e.printable_value('content'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
621 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
622 |
e.cw_attr_cache['content'] = 'du *texte*' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
623 |
e.cw_attr_cache['content_format'] = 'text/plain' |
10116
4e9738f5c798
[test] fixes to make tests pass with recent lxml
David Douard <david.douard@logilab.fr>
parents:
9978
diff
changeset
|
624 |
self.assertEqual(e.printable_value('content').replace("\n", ""), |
4e9738f5c798
[test] fixes to make tests pass with recent lxml
David Douard <david.douard@logilab.fr>
parents:
9978
diff
changeset
|
625 |
'<p>du *texte*<br/></p>') |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
626 |
e.cw_attr_cache['title'] = 'zou' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
627 |
e.cw_attr_cache['content'] = '''\ |
0 | 628 |
a title |
629 |
======= |
|
630 |
du :eid:`1:*ReST*`''' |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
631 |
e.cw_attr_cache['content_format'] = 'text/rest' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
632 |
self.assertEqual(e.printable_value('content', format='text/plain'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
633 |
e.cw_attr_cache['content']) |
0 | 634 |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
635 |
e.cw_attr_cache['content'] = u'<b>yo (zou éà ;)</b>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
636 |
e.cw_attr_cache['content_format'] = 'text/html' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
637 |
self.assertEqual(e.printable_value('content', format='text/plain').strip(), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
638 |
u'**yo (zou éà ;)**') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
639 |
if HAS_TAL: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
640 |
e.cw_attr_cache['content'] = '<h1 tal:content="self/title">titre</h1>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
641 |
e.cw_attr_cache['content_format'] = 'text/cubicweb-page-template' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
642 |
self.assertEqual(e.printable_value('content'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
643 |
'<h1>zou</h1>') |
1640 | 644 |
|
0 | 645 |
|
646 |
def test_printable_value_bytes(self): |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
647 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
648 |
e = req.create_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
649 |
data_encoding=u'ascii', data_name=u'toto.py') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
650 |
from cubicweb import mttransforms |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
651 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
652 |
import pygments |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
653 |
if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
654 |
self.assertEqual(e.printable_value('data'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
655 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
656 |
</pre></div>''') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
657 |
else: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
658 |
self.assertEqual(e.printable_value('data'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
659 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
9432
030745ac9873
[entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9319
diff
changeset
|
660 |
</pre></div>''') |
5634
e01cf2013bf1
stop being dumb please
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5631
diff
changeset
|
661 |
else: |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
662 |
self.assertEqual(e.printable_value('data'), |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
663 |
'''<pre class="python"> |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
664 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
9432
030745ac9873
[entities] unconditionnally sanitize the html output of printable_value
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9319
diff
changeset
|
665 |
</pre>''') |
1640 | 666 |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
667 |
e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
668 |
data_encoding=u'utf-8', data_name=u'toto.txt') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
669 |
self.assertEqual(e.printable_value('data'), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
670 |
u'<p><em>héhéhé</em></p>') |
0 | 671 |
|
672 |
def test_printable_value_bad_html(self): |
|
673 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
674 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
675 |
e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
676 |
content_format=u'text/html') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
677 |
tidy = lambda x: x.replace('\n', '') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
678 |
self.assertEqual(tidy(e.printable_value('content')), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
679 |
'<div>R&D<br/></div>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
680 |
e.cw_attr_cache['content'] = u'yo !! R&D <div> pas fermé' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
681 |
self.assertEqual(tidy(e.printable_value('content')), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
682 |
u'yo !! R&D <div> pas fermé</div>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
683 |
e.cw_attr_cache['content'] = u'R&D' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
684 |
self.assertEqual(tidy(e.printable_value('content')), u'R&D') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
685 |
e.cw_attr_cache['content'] = u'R&D;' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
686 |
self.assertEqual(tidy(e.printable_value('content')), u'R&D;') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
687 |
e.cw_attr_cache['content'] = u'yo !! R&D <div> pas fermé' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
688 |
self.assertEqual(tidy(e.printable_value('content')), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
689 |
u'yo !! R&D <div> pas fermé</div>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
690 |
e.cw_attr_cache['content'] = u'été <div> été' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
691 |
self.assertEqual(tidy(e.printable_value('content')), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
692 |
u'été <div> été</div>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
693 |
e.cw_attr_cache['content'] = u'C'est un exemple sérieux' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
694 |
self.assertEqual(tidy(e.printable_value('content')), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
695 |
u"C'est un exemple sérieux") |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
696 |
# make sure valid xhtml is left untouched |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
697 |
e.cw_attr_cache['content'] = u'<div>R&D<br/></div>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
698 |
self.assertEqual(e.printable_value('content'), e.cw_attr_cache['content']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
699 |
e.cw_attr_cache['content'] = u'<div>été</div>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
700 |
self.assertEqual(e.printable_value('content'), e.cw_attr_cache['content']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
701 |
e.cw_attr_cache['content'] = u'été' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
702 |
self.assertEqual(e.printable_value('content'), e.cw_attr_cache['content']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
703 |
e.cw_attr_cache['content'] = u'hop\r\nhop\nhip\rmomo' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
704 |
self.assertEqual(e.printable_value('content'), u'hop\nhop\nhip\nmomo') |
3587 | 705 |
|
706 |
def test_printable_value_bad_html_ms(self): |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
707 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
708 |
e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
709 |
content_format=u'text/html') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
710 |
tidy = lambda x: x.replace('\n', '') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
711 |
e.cw_attr_cache['content'] = u'<div x:foo="bar">ms orifice produces weird html</div>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
712 |
# Caution! current implementation of soup2xhtml strips first div element |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
713 |
content = soup2xhtml(e.printable_value('content'), 'utf-8') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
714 |
self.assertMultiLineEqual(content, u'<div>ms orifice produces weird html</div>') |
1640 | 715 |
|
0 | 716 |
def test_fulltextindex(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
717 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
718 |
e = self.vreg['etypes'].etype_class('File')(req) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
719 |
e.cw_attr_cache['description'] = 'du <em>html</em>' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
720 |
e.cw_attr_cache['description_format'] = 'text/html' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
721 |
e.cw_attr_cache['data'] = Binary('some <em>data</em>') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
722 |
e.cw_attr_cache['data_name'] = 'an html file' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
723 |
e.cw_attr_cache['data_format'] = 'text/html' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
724 |
e.cw_attr_cache['data_encoding'] = 'ascii' |
9774
b7b71be569cf
deprecate get/set_shared_data API
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9770
diff
changeset
|
725 |
e._cw.transaction_data.clear() |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
726 |
words = e.cw_adapt_to('IFTIndexable').get_words() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
727 |
words['C'].sort() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
728 |
self.assertEqual({'C': sorted(['an', 'html', 'file', 'du', 'html', 'some', 'data'])}, |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
729 |
words) |
0 | 730 |
|
1640 | 731 |
|
0 | 732 |
def test_nonregr_relation_cache(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
733 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
734 |
p1 = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
735 |
p2 = req.create_entity('Personne', nom=u'toto') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
736 |
req.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
737 |
self.assertEqual(p1.evaluee[0].nom, "toto") |
9638
3046bae3ce31
[test] replace some assert{True,False} with more specific method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9637
diff
changeset
|
738 |
self.assertFalse(p1.reverse_evaluee) |
1640 | 739 |
|
0 | 740 |
def test_complete_relation(self): |
9877
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
741 |
with self.admin_access.repo_cnx() as cnx: |
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
742 |
eid = cnx.execute( |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
743 |
'INSERT TrInfo X: X comment "zou", X wf_info_for U, X from_state S1, X to_state S2 ' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
744 |
'WHERE U login "admin", S1 name "activated", S2 name "deactivated"')[0][0] |
9877
4a604b6e3067
[test/entities] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9774
diff
changeset
|
745 |
trinfo = cnx.execute('Any X WHERE X eid %(x)s', {'x': eid}).get_entity(0, 0) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
746 |
trinfo.complete() |
9638
3046bae3ce31
[test] replace some assert{True,False} with more specific method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9637
diff
changeset
|
747 |
self.assertIsInstance(trinfo.cw_attr_cache['creation_date'], datetime) |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
748 |
self.assertTrue(trinfo.cw_relation_cached('from_state', 'subject')) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
749 |
self.assertTrue(trinfo.cw_relation_cached('to_state', 'subject')) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
750 |
self.assertTrue(trinfo.cw_relation_cached('wf_info_for', 'subject')) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
751 |
self.assertEqual(trinfo.by_transition, ()) |
0 | 752 |
|
753 |
def test_request_cache(self): |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
754 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
755 |
user = req.execute('CWUser X WHERE X login "admin"').get_entity(0, 0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
756 |
state = user.in_state[0] |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
757 |
samestate = req.execute('State X WHERE X name "activated"').get_entity(0, 0) |
9638
3046bae3ce31
[test] replace some assert{True,False} with more specific method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9637
diff
changeset
|
758 |
self.assertIs(state, samestate) |
0 | 759 |
|
760 |
def test_rest_path(self): |
|
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
761 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
762 |
note = req.create_entity('Note', type=u'z') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
763 |
self.assertEqual(note.rest_path(), 'note/%s' % note.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
764 |
# unique attr |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
765 |
tag = req.create_entity('Tag', name=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
766 |
self.assertEqual(tag.rest_path(), 'tag/x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
767 |
# test explicit rest_attr |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
768 |
person = req.create_entity('Personne', prenom=u'john', nom=u'doe') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
769 |
self.assertEqual(person.rest_path(), 'personne/doe') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
770 |
# ambiguity test |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
771 |
person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
772 |
person.cw_clear_all_caches() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
773 |
self.assertEqual(person.rest_path(), unicode(person.eid)) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
774 |
self.assertEqual(person2.rest_path(), unicode(person2.eid)) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
775 |
# unique attr with None value (nom in this case) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
776 |
friend = req.create_entity('Ami', prenom=u'bob') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
777 |
self.assertEqual(friend.rest_path(), unicode(friend.eid)) |
9978
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9877
diff
changeset
|
778 |
# 'ref' below is created without the unique but not required |
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9877
diff
changeset
|
779 |
# attribute, make sur that the unique _and_ required 'ean' is used |
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9877
diff
changeset
|
780 |
# as the rest attribute |
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9877
diff
changeset
|
781 |
ref = req.create_entity('Reference', ean=u'42-1337-42') |
8f4b15e5b300
[entities] cw_rest_attr_info() should only consider required attributes (closes #3766717)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9877
diff
changeset
|
782 |
self.assertEqual(ref.rest_path(), 'reference/42-1337-42') |
9319
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
783 |
|
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
784 |
def test_can_use_rest_path(self): |
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
785 |
self.assertTrue(can_use_rest_path(u'zobi')) |
6099
b22a4a3895df
work around Apache's mod_proxy limitation with special chars in URLs by not using Rest urls when such a case is detected
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5768
diff
changeset
|
786 |
# don't use rest if we have /, ? or & in the path (breaks mod_proxy) |
9319
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
787 |
self.assertFalse(can_use_rest_path(u'zo/bi')) |
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
788 |
self.assertFalse(can_use_rest_path(u'zo&bi')) |
a68b8f423a8b
[test] test can_use_rest_path directly
Julien Cristau <julien.cristau@logilab.fr>
parents:
9273
diff
changeset
|
789 |
self.assertFalse(can_use_rest_path(u'zo?bi')) |
0 | 790 |
|
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8307
diff
changeset
|
791 |
def test_cw_set_attributes(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
792 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
793 |
person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
794 |
self.assertEqual(person.prenom, u'adrien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
795 |
self.assertEqual(person.nom, u'di mascio') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
796 |
person.cw_set(prenom=u'sylvain', nom=u'thénault') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
797 |
person = req.execute('Personne P').get_entity(0, 0) # XXX retreival needed ? |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
798 |
self.assertEqual(person.prenom, u'sylvain') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
799 |
self.assertEqual(person.nom, u'thénault') |
0 | 800 |
|
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8307
diff
changeset
|
801 |
def test_cw_set_relations(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
802 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
803 |
person = req.create_entity('Personne', nom=u'chauvat', prenom=u'nicolas') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
804 |
note = req.create_entity('Note', type=u'x') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
805 |
note.cw_set(ecrit_par=person) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
806 |
note = req.create_entity('Note', type=u'y') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
807 |
note.cw_set(ecrit_par=person.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
808 |
self.assertEqual(len(person.reverse_ecrit_par), 2) |
7308
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
809 |
|
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
810 |
def test_metainformation_and_external_absolute_url(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
811 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
812 |
note = req.create_entity('Note', type=u'z') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
813 |
metainf = note.cw_metainformation() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
814 |
self.assertEqual(metainf, {'source': {'type': 'native', 'uri': 'system', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
815 |
'use-cwuri-as-url': False}, |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
816 |
'type': u'Note', 'extid': None}) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
817 |
self.assertEqual(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
818 |
metainf['source'] = metainf['source'].copy() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
819 |
metainf['source']['base-url'] = 'http://cubicweb2.com/' |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
820 |
metainf['extid'] = 1234 |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
821 |
self.assertEqual(note.absolute_url(), 'http://cubicweb2.com/note/1234') |
1640 | 822 |
|
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
823 |
def test_absolute_url_empty_field(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
824 |
with self.admin_access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
825 |
card = req.create_entity('Card', wikiid=u'', title=u'test') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
826 |
self.assertEqual(card.absolute_url(), |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
827 |
'http://testing.fr/cubicweb/%s' % card.eid) |
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
828 |
|
9261
1dfe62a9da50
[entity] give a default reasonnable __eq__ and __hash__ to Entity
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9214
diff
changeset
|
829 |
def test_create_and_compare_entity(self): |
9637
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
830 |
access = self.admin_access |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
831 |
with access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
832 |
p1 = req.create_entity('Personne', nom=u'fayolle', prenom=u'alexandre') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
833 |
p2 = req.create_entity('Personne', nom=u'campeas', prenom=u'aurelien') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
834 |
note = req.create_entity('Note', type=u'z') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
835 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien', |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
836 |
connait=p1, evaluee=[p1, p2], |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
837 |
reverse_ecrit_par=note) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
838 |
self.assertEqual(p.nom, 'di mascio') |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
839 |
self.assertEqual([c.nom for c in p.connait], ['fayolle']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
840 |
self.assertEqual(sorted([c.nom for c in p.evaluee]), ['campeas', 'fayolle']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
841 |
self.assertEqual([c.type for c in p.reverse_ecrit_par], ['z']) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
842 |
req.cnx.commit() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
843 |
with access.web_request() as req: |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
844 |
auc = req.execute('Personne P WHERE P prenom "aurelien"').get_entity(0,0) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
845 |
persons = set() |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
846 |
persons.add(p1) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
847 |
persons.add(p2) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
848 |
persons.add(auc) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
849 |
self.assertEqual(2, len(persons)) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
850 |
self.assertNotEqual(p1, p2) |
c6132d36e55d
[test] silence warnings for unittest_entity by upgrading to new 3.19 API
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9629
diff
changeset
|
851 |
self.assertEqual(p2, auc) |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
852 |
|
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
853 |
|
0 | 854 |
if __name__ == '__main__': |
855 |
from logilab.common.testlib import unittest_main |
|
856 |
unittest_main() |
|
857 |