author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Tue, 19 Mar 2013 16:54:32 +0100 | |
changeset 8739 | 30c262eb0841 |
parent 8735 | 5567a5117aeb |
child 9160 | 7db0c75acf1c |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
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
|
2 |
# copyright 2003-2012 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 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
26 |
from cubicweb import Binary, Unauthorized |
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 |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
29 |
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
|
30 |
from cubicweb.uilib import soup2xhtml |
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
|
31 |
from cubicweb.schema import RQLVocabularyConstraint, RRQLExpression |
0 | 32 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
33 |
class EntityTC(CubicWebTC): |
1640 | 34 |
|
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
|
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 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
|
0 | 46 |
def test_boolean_value(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
47 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
48 |
self.assertTrue(e) |
0 | 49 |
|
50 |
def test_yams_inheritance(self): |
|
748 | 51 |
from entities import Note |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
52 |
e = self.vreg['etypes'].etype_class('SubNote')(self.request()) |
748 | 53 |
self.assertIsInstance(e, Note) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
54 |
e2 = self.vreg['etypes'].etype_class('SubNote')(self.request()) |
0 | 55 |
self.assertIs(e.__class__, e2.__class__) |
56 |
||
57 |
def test_has_eid(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
58 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
59 |
self.assertEqual(e.eid, None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
60 |
self.assertEqual(e.has_eid(), False) |
0 | 61 |
e.eid = 'X' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
62 |
self.assertEqual(e.has_eid(), False) |
0 | 63 |
e.eid = 0 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
64 |
self.assertEqual(e.has_eid(), True) |
0 | 65 |
e.eid = 2 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
66 |
self.assertEqual(e.has_eid(), True) |
1640 | 67 |
|
0 | 68 |
def test_copy(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
69 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
70 |
req.create_entity('Tag', name=u'x') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
71 |
p = req.create_entity('Personne', nom=u'toto') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
72 |
oe = req.create_entity('Note', type=u'x') |
0 | 73 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
74 |
{'t': oe.eid, 'u': p.eid}) |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
75 |
self.execute('SET TAG tags X WHERE X eid %(x)s', {'x': oe.eid}) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
76 |
e = req.create_entity('Note', type=u'z') |
0 | 77 |
e.copy_relations(oe.eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
78 |
self.assertEqual(len(e.ecrit_par), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
79 |
self.assertEqual(e.ecrit_par[0].eid, p.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
80 |
self.assertEqual(len(e.reverse_tags), 1) |
2635
c94df21f7ab2
F [cw.test] OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2208
diff
changeset
|
81 |
# check meta-relations are not copied, set on commit |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
82 |
self.assertEqual(len(e.created_by), 0) |
1640 | 83 |
|
0 | 84 |
def test_copy_with_nonmeta_composite_inlined(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
85 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
86 |
p = req.create_entity('Personne', nom=u'toto') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
87 |
oe = req.create_entity('Note', type=u'x') |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
88 |
self.schema['ecrit_par'].rdef('Note', 'Personne').composite = 'subject' |
0 | 89 |
self.execute('SET T ecrit_par U WHERE T eid %(t)s, U eid %(u)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
90 |
{'t': oe.eid, 'u': p.eid}) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
91 |
e = req.create_entity('Note', type=u'z') |
0 | 92 |
e.copy_relations(oe.eid) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
93 |
self.assertFalse(e.ecrit_par) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
94 |
self.assertTrue(oe.ecrit_par) |
1640 | 95 |
|
0 | 96 |
def test_copy_with_composite(self): |
97 |
user = self.user() |
|
98 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
99 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': user.eid}).get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
100 |
self.assertEqual(e.use_email[0].address, "toto@logilab.org") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
101 |
self.assertEqual(e.use_email[0].eid, adeleid) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
102 |
usereid = self.execute('INSERT CWUser X: X login "toto", X upassword "toto", X in_group G ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
103 |
'WHERE G name "users"')[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
104 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': usereid}).get_entity(0, 0) |
0 | 105 |
e.copy_relations(user.eid) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
106 |
self.assertFalse(e.use_email) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
107 |
self.assertFalse(e.primary_email) |
1640 | 108 |
|
0 | 109 |
def test_copy_with_non_initial_state(self): |
110 |
user = self.user() |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
111 |
user = self.execute('INSERT CWUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
112 |
{'pwd': 'toto'}).get_entity(0, 0) |
0 | 113 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
114 |
user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
0 | 115 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
116 |
eid2 = self.execute('INSERT CWUser X: X login "tutu", X upassword %(pwd)s', {'pwd': 'toto'})[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
117 |
e = self.execute('Any X WHERE X eid %(x)s', {'x': eid2}).get_entity(0, 0) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
118 |
e.copy_relations(user.eid) |
0 | 119 |
self.commit() |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
120 |
e.cw_clear_relation_cache('in_state', 'subject') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
121 |
self.assertEqual(e.cw_adapt_to('IWorkflowable').state, 'activated') |
0 | 122 |
|
123 |
def test_related_cache_both(self): |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
124 |
user = self.execute('Any X WHERE X eid %(x)s', {'x':self.user().eid}).get_entity(0, 0) |
0 | 125 |
adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0] |
126 |
self.commit() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
127 |
self.assertEqual(user._cw_related_cache, {}) |
0 | 128 |
email = user.primary_email[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
129 |
self.assertEqual(sorted(user._cw_related_cache), ['primary_email_subject']) |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
130 |
self.assertEqual(list(email._cw_related_cache), ['primary_email_object']) |
0 | 131 |
groups = user.in_group |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
132 |
self.assertEqual(sorted(user._cw_related_cache), ['in_group_subject', 'primary_email_subject']) |
0 | 133 |
for group in groups: |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
134 |
self.assertFalse('in_group_subject' in group._cw_related_cache, list(group._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
|
135 |
|
0 | 136 |
def test_related_limit(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
137 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
138 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
0 | 139 |
for tag in u'abcd': |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
140 |
req.create_entity('Tag', name=tag) |
0 | 141 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
142 |
self.assertEqual(len(p.related('tags', 'object', limit=2)), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
143 |
self.assertEqual(len(p.related('tags', 'object')), 4) |
8735
5567a5117aeb
[entity] ensure the .related(entities=False) parameter is honored all the way down (closes #2755994)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
144 |
p.cw_clear_all_caches() |
5567a5117aeb
[entity] ensure the .related(entities=False) parameter is honored all the way down (closes #2755994)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
145 |
self.assertEqual(len(p.related('tags', 'object', entities=True, limit=2)), 2) |
5567a5117aeb
[entity] ensure the .related(entities=False) parameter is honored all the way down (closes #2755994)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8696
diff
changeset
|
146 |
self.assertEqual(len(p.related('tags', 'object', entities=True)), 4) |
0 | 147 |
|
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
|
148 |
def test_cw_instantiate_relation(self): |
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
|
149 |
req = self.request() |
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
|
150 |
p1 = req.create_entity('Personne', nom=u'di') |
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
|
151 |
p2 = req.create_entity('Personne', nom=u'mascio') |
8199
fb5c0e60a615
[entity] fix crash when using cw_instantiate with empty related entity list; closes #2094462
Florent Cayré <florent.cayre@gmail.com>
parents:
7973
diff
changeset
|
152 |
t = req.create_entity('Tag', name=u't0', tags=[]) |
fb5c0e60a615
[entity] fix crash when using cw_instantiate with empty related entity list; closes #2094462
Florent Cayré <florent.cayre@gmail.com>
parents:
7973
diff
changeset
|
153 |
self.assertItemsEqual(t.tags, []) |
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
|
154 |
t = req.create_entity('Tag', name=u't1', tags=p1) |
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
|
155 |
self.assertItemsEqual(t.tags, [p1]) |
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
|
156 |
t = req.create_entity('Tag', name=u't2', tags=p1.eid) |
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
|
157 |
self.assertItemsEqual(t.tags, [p1]) |
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
|
158 |
t = req.create_entity('Tag', name=u't3', tags=[p1, p2.eid]) |
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
|
159 |
self.assertItemsEqual(t.tags, [p1, p2]) |
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
|
160 |
|
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
|
161 |
def test_cw_instantiate_reverse_relation(self): |
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
|
162 |
req = self.request() |
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
|
163 |
t1 = req.create_entity('Tag', name=u't1') |
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
|
164 |
t2 = req.create_entity('Tag', name=u't2') |
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
|
165 |
p = req.create_entity('Personne', nom=u'di mascio', reverse_tags=t1) |
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
|
166 |
self.assertItemsEqual(p.reverse_tags, [t1]) |
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
|
167 |
p = req.create_entity('Personne', nom=u'di mascio', reverse_tags=t1.eid) |
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
|
168 |
self.assertItemsEqual(p.reverse_tags, [t1]) |
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
|
169 |
p = req.create_entity('Personne', nom=u'di mascio', reverse_tags=[t1, t2.eid]) |
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
|
170 |
self.assertItemsEqual(p.reverse_tags, [t1, t2]) |
1640 | 171 |
|
0 | 172 |
def test_fetch_rql(self): |
173 |
user = self.user() |
|
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
|
174 |
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
|
175 |
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
|
176 |
Note = self.vreg['etypes'].etype_class('Note') |
0 | 177 |
peschema = Personne.e_schema |
178 |
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
|
179 |
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
|
180 |
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
|
181 |
(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
|
182 |
(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
|
183 |
(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
|
184 |
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
|
185 |
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
|
186 |
torestore.append(cm) |
0 | 187 |
try: |
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
|
188 |
# testing basic fetch_attrs attribute |
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
|
189 |
self.assertEqual(Personne.fetch_rql(user), |
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
|
190 |
'Any X,AA,AB,AC ORDERBY AA ' |
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
|
191 |
'WHERE X is Personne, X nom AA, X prenom AB, X modification_date AC') |
0 | 192 |
# testing unknown attributes |
193 |
Personne.fetch_attrs = ('bloug', 'beep') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
194 |
self.assertEqual(Personne.fetch_rql(user), 'Any X WHERE X is Personne') |
0 | 195 |
# testing one non final relation |
196 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
197 |
self.assertEqual(Personne.fetch_rql(user), |
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
|
198 |
'Any X,AA,AB,AC,AD ORDERBY AA ' |
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
199 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
0 | 200 |
# testing two non final relations |
201 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille', 'evaluee') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
202 |
self.assertEqual(Personne.fetch_rql(user), |
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
|
203 |
'Any X,AA,AB,AC,AD,AE ORDERBY AA ' |
7302
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
204 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
c281afe35b8b
[entity] fix entity fetch_rql when fetch_attrs contains a rtype with multiple destination etypes which do not have the same fetched attributes themselves (closes #1631282)
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
205 |
'X evaluee AE?') |
0 | 206 |
# testing one non final relation with recursion |
207 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
|
208 |
Societe.fetch_attrs = ('nom', 'evaluee') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
209 |
self.assertEqual(Personne.fetch_rql(user), |
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
|
210 |
'Any X,AA,AB,AC,AD,AE,AF ORDERBY AA,AF DESC ' |
3135
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
211 |
'WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD, ' |
996c1ec7376c
test fixes and enhancement
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2930
diff
changeset
|
212 |
'AC evaluee AE?, AE modification_date AF' |
0 | 213 |
) |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4460
diff
changeset
|
214 |
# testing symmetric relation |
0 | 215 |
Personne.fetch_attrs = ('nom', 'connait') |
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
|
216 |
self.assertEqual(Personne.fetch_rql(user), 'Any X,AA,AB ORDERBY AA ' |
2930
d7c23b2c7538
some test fixes, more in the 3.5 branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
217 |
'WHERE X is Personne, X nom AA, X connait AB?') |
0 | 218 |
# testing optional relation |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
219 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '?*' |
0 | 220 |
Personne.fetch_attrs = ('nom', 'prenom', 'travaille') |
221 |
Societe.fetch_attrs = ('nom',) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
222 |
self.assertEqual(Personne.fetch_rql(user), |
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
|
223 |
'Any X,AA,AB,AC,AD ORDERBY AA WHERE X is Personne, X nom AA, X prenom AB, X travaille AC?, AC nom AD') |
0 | 224 |
# testing relation with cardinality > 1 |
3877
7ca53fc72a0a
reldefsecurity branch :
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3826
diff
changeset
|
225 |
peschema.subjrels['travaille'].rdef(peschema, seschema).cardinality = '**' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
226 |
self.assertEqual(Personne.fetch_rql(user), |
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
|
227 |
'Any X,AA,AB ORDERBY AA WHERE X is Personne, X nom AA, X prenom AB') |
0 | 228 |
# XXX test unauthorized attribute |
229 |
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
|
230 |
# 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
|
231 |
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
|
232 |
cm.__exit__(None, None, None) |
0 | 233 |
|
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
|
234 |
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
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
SubNote.fetch_attrs, SubNote.cw_fetch_order = fetch_config(('type',)) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
242 |
p = self.request().create_entity('Personne', nom=u'pouet') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
243 |
self.assertEqual(p.cw_related_rql('evaluee'), |
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
|
244 |
'Any X,AA,AB ORDERBY AA WHERE E eid %(x)s, E evaluee X, ' |
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
|
245 |
'X type AA, X modification_date AB') |
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
|
246 |
n = self.request().create_entity('Note') |
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
|
247 |
self.assertEqual(n.cw_related_rql('evaluee', role='object', |
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
|
248 |
targettypes=('Societe', '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
|
249 |
"Any X,AA ORDERBY AB DESC WHERE E eid %(x)s, X evaluee E, " |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
250 |
"X is IN(Personne, Societe), X nom AA, " |
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
|
251 |
"X modification_date AB") |
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
|
252 |
Personne.fetch_attrs, Personne.cw_fetch_order = fetch_config(('nom', )) |
744 | 253 |
# XXX |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
254 |
self.assertEqual(p.cw_related_rql('evaluee'), |
4672 | 255 |
'Any X,AA ORDERBY AA DESC ' |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4672
diff
changeset
|
256 |
'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
|
257 |
|
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
258 |
tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
259 |
self.assertEqual(tag.cw_related_rql('tags', 'subject'), |
4672 | 260 |
'Any X,AA ORDERBY AA DESC ' |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4672
diff
changeset
|
261 |
'WHERE E eid %(x)s, E tags X, X modification_date AA') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
262 |
self.assertEqual(tag.cw_related_rql('tags', 'subject', ('Personne',)), |
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
|
263 |
'Any X,AA,AB ORDERBY AA ' |
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
|
264 |
'WHERE E eid %(x)s, E tags X, X is Personne, X nom AA, ' |
3672
554a588ffaea
[entity] make related_rql honors its targettypes argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3670
diff
changeset
|
265 |
'X modification_date AB') |
1640 | 266 |
|
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
|
267 |
def test_related_rql_ambiguous_cant_use_fetch_order(self): |
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
|
268 |
tag = self.vreg['etypes'].etype_class('Tag')(self.request()) |
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
|
269 |
for ttype in self.schema['tags'].objects(): |
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
|
270 |
self.vreg['etypes'].etype_class(ttype).fetch_attrs = ('modification_date',) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
271 |
self.assertEqual(tag.cw_related_rql('tags', 'subject'), |
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
|
272 |
'Any X,AA ORDERBY AA DESC ' |
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
|
273 |
'WHERE E eid %(x)s, E tags X, X modification_date AA') |
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
|
274 |
|
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
|
275 |
def test_related_rql_fetch_ambiguous_rtype(self): |
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
|
276 |
soc_etype = self.vreg['etypes'].etype_class('Societe') |
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
|
277 |
soc = soc_etype(self.request()) |
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
|
278 |
soc_etype.fetch_attrs = ('fournit',) |
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
|
279 |
self.vreg['etypes'].etype_class('Service').fetch_attrs = ('fabrique_par',) |
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
|
280 |
self.vreg['etypes'].etype_class('Produit').fetch_attrs = ('fabrique_par',) |
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
|
281 |
self.vreg['etypes'].etype_class('Usine').fetch_attrs = ('lieu',) |
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
|
282 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = ('nom',) |
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
|
283 |
self.assertEqual(soc.cw_related_rql('fournit', 'subject'), |
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
|
284 |
'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
|
285 |
|
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
|
286 |
def test_unrelated_rql_security_1_manager(self): |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
287 |
user = self.request().user |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
288 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
289 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
290 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
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
|
291 |
'O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
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
|
292 |
|
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
|
293 |
def test_unrelated_rql_security_1_user(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7177
diff
changeset
|
294 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7177
diff
changeset
|
295 |
self.create_user(req, 'toto') |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
296 |
self.login('toto') |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7177
diff
changeset
|
297 |
user = req.user |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
298 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
299 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
300 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
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
|
301 |
'O is EmailAddress, O address AA, O alias AB, O modification_date AC') |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
302 |
user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
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
|
303 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
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
|
304 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
305 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
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
|
306 |
'O is EmailAddress, O address AA, O alias AB, O modification_date AC, AD eid %(AE)s, ' |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
307 |
'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
|
308 |
|
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
|
309 |
def test_unrelated_rql_security_1_anon(self): |
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
310 |
self.login('anon') |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
311 |
user = self.request().user |
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
|
312 |
rql = user.cw_unrelated_rql('use_email', 'EmailAddress', 'subject')[0] |
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
|
313 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC ' |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
314 |
'WHERE NOT A use_email O, S eid %(x)s, ' |
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
|
315 |
'O is EmailAddress, O address AA, O alias AB, O modification_date AC, AD eid %(AE)s, ' |
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
316 |
'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
|
317 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
318 |
def test_unrelated_rql_security_2(self): |
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
319 |
email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
320 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
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
|
321 |
self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
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
|
322 |
'WHERE NOT S use_email O, O eid %(x)s, 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
|
323 |
'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
|
324 |
self.login('anon') |
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
try: |
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
|
330 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
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
|
331 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
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
|
332 |
self.assertEqual(rql, 'Any S,AA,AB,AC,AD ORDERBY AA ' |
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
|
333 |
'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
|
334 |
'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
|
335 |
'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
|
336 |
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
|
337 |
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
|
338 |
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
|
339 |
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
|
340 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
341 |
|
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
|
342 |
def test_unrelated_rql_security_nonexistant(self): |
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
|
343 |
self.login('anon') |
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
|
344 |
email = self.vreg['etypes'].etype_class('EmailAddress')(self.request()) |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
345 |
rql = email.cw_unrelated_rql('use_email', 'CWUser', 'object')[0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
346 |
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
|
347 |
'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
|
348 |
'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
|
349 |
'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
|
350 |
|
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
|
351 |
def test_unrelated_rql_constraints_creation_subject(self): |
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
|
352 |
person = self.vreg['etypes'].etype_class('Personne')(self.request()) |
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
|
353 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
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
|
354 |
self.assertEqual( |
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
|
355 |
rql, 'Any O,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
|
356 |
'O is 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
|
357 |
|
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
|
358 |
def test_unrelated_rql_constraints_creation_object(self): |
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
|
359 |
person = self.vreg['etypes'].etype_class('Personne')(self.request()) |
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
|
360 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'object')[0] |
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
|
361 |
self.assertEqual( |
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
|
362 |
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
|
363 |
'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
|
364 |
'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
|
365 |
'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
|
366 |
|
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
|
367 |
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
|
368 |
'''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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
with self.temporary_permissions((rdef, {'add': (perm_rrqle,)})): |
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
|
373 |
person = self.vreg['etypes'].etype_class('Personne')(self.request()) |
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
|
374 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
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
|
375 |
self.assertEqual(rql, 'Any O,AA,AB,AC ORDERBY AC DESC WHERE ' |
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
|
376 |
'O is Personne, O nom AA, O prenom AB, ' |
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
|
377 |
'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
|
378 |
|
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
|
379 |
def test_unrelated_rql_constraints_edition_subject(self): |
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
|
380 |
person = self.request().create_entity('Personne', nom=u'sylvain') |
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
|
381 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'subject')[0] |
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
|
382 |
self.assertEqual( |
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
|
383 |
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
|
384 |
'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
|
385 |
'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
|
386 |
'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
|
387 |
|
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
|
388 |
def test_unrelated_rql_constraints_edition_object(self): |
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
|
389 |
person = self.request().create_entity('Personne', nom=u'sylvain') |
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
|
390 |
rql = person.cw_unrelated_rql('connait', 'Personne', 'object')[0] |
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
|
391 |
self.assertEqual( |
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
|
392 |
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
|
393 |
'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
|
394 |
'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
|
395 |
'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
|
396 |
'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
|
397 |
|
7973
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
398 |
def test_unrelated_rql_s_linkto_s(self): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
399 |
req = self.request() |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
400 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
401 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
402 |
soc = req.create_entity('Societe', nom=u'logilab') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
403 |
lt_infos = {('actionnaire', 'subject'): [soc.eid]} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
404 |
rql, args = person.cw_unrelated_rql('associe', 'Personne', 'subject', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
405 |
lt_infos=lt_infos) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
406 |
self.assertEqual(u'Any O ORDERBY O WHERE O is Personne, ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
407 |
u'EXISTS(AA eid %(SOC)s, O actionnaire AA)', rql) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
408 |
self.assertEqual({'SOC': soc.eid}, args) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
409 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
410 |
def test_unrelated_rql_s_linkto_o(self): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
411 |
req = self.request() |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
412 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
413 |
self.vreg['etypes'].etype_class('Societe').fetch_attrs = () |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
414 |
soc = req.create_entity('Societe', nom=u'logilab') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
415 |
lt_infos = {('contrat_exclusif', 'object'): [soc.eid]} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
416 |
rql, args = person.cw_unrelated_rql('actionnaire', 'Societe', 'subject', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
417 |
lt_infos=lt_infos) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
418 |
self.assertEqual(u'Any O ORDERBY O WHERE NOT A actionnaire O, ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
419 |
u'O is Societe, NOT EXISTS(O eid %(O)s), ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
420 |
u'A is Personne', rql) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
421 |
self.assertEqual({'O': soc.eid}, args) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
422 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
423 |
def test_unrelated_rql_o_linkto_s(self): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
424 |
req = self.request() |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
425 |
soc = self.vreg['etypes'].etype_class('Societe')(req) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
426 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
427 |
person = req.create_entity('Personne', nom=u'florent') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
428 |
lt_infos = {('contrat_exclusif', 'subject'): [person.eid]} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
429 |
rql, args = soc.cw_unrelated_rql('actionnaire', 'Personne', 'object', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
430 |
lt_infos=lt_infos) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
431 |
self.assertEqual(u'Any S ORDERBY S WHERE NOT S actionnaire A, ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
432 |
u'S is Personne, NOT EXISTS(S eid %(S)s), ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
433 |
u'A is Societe', rql) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
434 |
self.assertEqual({'S': person.eid}, args) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
435 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
436 |
def test_unrelated_rql_o_linkto_o(self): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
437 |
req = self.request() |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
438 |
soc = self.vreg['etypes'].etype_class('Societe')(req) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
439 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
440 |
person = req.create_entity('Personne', nom=u'florent') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
441 |
lt_infos = {('actionnaire', 'object'): [person.eid]} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
442 |
rql, args = soc.cw_unrelated_rql('dirige', 'Personne', 'object', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
443 |
lt_infos=lt_infos) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
444 |
self.assertEqual(u'Any S ORDERBY S WHERE NOT S dirige A, ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
445 |
u'S is Personne, EXISTS(S eid %(S)s), ' |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
446 |
u'A is Societe', rql) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
447 |
self.assertEqual({'S': person.eid}, args) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
448 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
449 |
def test_unrelated_rql_s_linkto_s_no_info(self): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
450 |
req = self.request() |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
451 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
452 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
453 |
soc = req.create_entity('Societe', nom=u'logilab') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
454 |
rql, args = person.cw_unrelated_rql('associe', 'Personne', 'subject') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
455 |
self.assertEqual(u'Any O ORDERBY O WHERE O is Personne', rql) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
456 |
self.assertEqual({}, args) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
457 |
|
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
458 |
def test_unrelated_rql_s_linkto_s_unused_info(self): |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
459 |
req = self.request() |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
460 |
person = self.vreg['etypes'].etype_class('Personne')(req) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
461 |
self.vreg['etypes'].etype_class('Personne').fetch_attrs = () |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
462 |
other_p = req.create_entity('Personne', nom=u'titi') |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
463 |
lt_infos = {('dirige', 'subject'): [other_p.eid]} |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
464 |
rql, args = person.cw_unrelated_rql('associe', 'Personne', 'subject', |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
465 |
lt_infos=lt_infos) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
466 |
self.assertEqual(u'Any O ORDERBY O WHERE O is Personne', rql) |
64639bc94e25
[entity] restrict creation form field vocabulary using __linkto information (closes #1799997)
Florent Cayré <florent.cayre@gmail.com>
parents:
7827
diff
changeset
|
467 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
468 |
def test_unrelated_base(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
469 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
470 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
471 |
e = req.create_entity('Tag', name=u'x') |
0 | 472 |
related = [r.eid for r in e.tags] |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
473 |
self.assertEqual(related, []) |
1341 | 474 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
475 |
self.assertTrue(p.eid in unrelated) |
0 | 476 |
self.execute('SET X tags Y WHERE X is Tag, Y is Personne') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
477 |
e = self.execute('Any X WHERE X is Tag').get_entity(0, 0) |
1341 | 478 |
unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')] |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
479 |
self.assertFalse(p.eid in unrelated) |
0 | 480 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
481 |
def test_unrelated_limit(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
482 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
483 |
e = req.create_entity('Tag', name=u'x') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
484 |
req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
485 |
req.create_entity('Personne', nom=u'thenault', prenom=u'sylvain') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
486 |
self.assertEqual(len(e.unrelated('tags', 'Personne', 'subject', limit=1)), |
0 | 487 |
1) |
1640 | 488 |
|
3241
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
489 |
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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
try: |
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
|
495 |
email = self.execute('INSERT EmailAddress X: X address "hop"').get_entity(0, 0) |
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
|
496 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
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
|
497 |
self.assertEqual([x.login for x in rset.entities()], [u'admin', u'anon']) |
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
|
498 |
user = self.request().user |
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
|
499 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
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
|
500 |
self.assertEqual([x.address for x in rset.entities()], [u'hop']) |
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
|
501 |
req = self.request() |
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
|
502 |
self.create_user(req, 'toto') |
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
|
503 |
self.login('toto') |
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
|
504 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
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
|
505 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
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
|
506 |
self.assertEqual([x.login for x in rset.entities()], ['toto']) |
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
|
507 |
user = self.request().user |
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
|
508 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
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
|
509 |
self.assertEqual([x.address for x in rset.entities()], ['hop']) |
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
|
510 |
user = self.execute('Any X WHERE X login "admin"').get_entity(0, 0) |
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
|
511 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
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
|
512 |
self.assertEqual([x.address for x in rset.entities()], []) |
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
|
513 |
self.login('anon') |
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
|
514 |
email = self.execute('Any X WHERE X eid %(x)s', {'x': email.eid}).get_entity(0, 0) |
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
|
515 |
rset = email.unrelated('use_email', 'CWUser', 'object') |
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
|
516 |
self.assertEqual([x.login for x in rset.entities()], []) |
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
|
517 |
user = self.request().user |
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
|
518 |
rset = user.unrelated('use_email', 'EmailAddress', 'subject') |
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
|
519 |
self.assertEqual([x.address for x in rset.entities()], []) |
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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
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
|
524 |
|
1a6f7a0e7dbd
unrelated_rql now considers relation's add perm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3136
diff
changeset
|
525 |
def test_unrelated_new_entity(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
526 |
e = self.vreg['etypes'].etype_class('CWUser')(self.request()) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
527 |
unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')] |
0 | 528 |
# should be default groups but owners, i.e. managers, users, guests |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
529 |
self.assertEqual(len(unrelated), 3) |
0 | 530 |
|
531 |
def test_printable_value_string(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
532 |
e = self.request().create_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`', |
6415 | 533 |
content_format=u'text/rest') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
534 |
self.assertEqual(e.printable_value('content'), |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6416
diff
changeset
|
535 |
'<p>du <a class="reference" href="http://testing.fr/cubicweb/cwsource/system">*ReST*</a></p>\n') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
536 |
e.cw_attr_cache['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
537 |
e.cw_attr_cache['content_format'] = 'text/html' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
538 |
self.assertEqual(e.printable_value('content'), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1341
diff
changeset
|
539 |
'du <em>html</em> <a href="http://testing.fr/cubicweb/view?rql=CWUser%20X">users</a>') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
540 |
e.cw_attr_cache['content'] = 'du *texte*' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
541 |
e.cw_attr_cache['content_format'] = 'text/plain' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
542 |
self.assertEqual(e.printable_value('content'), |
6168
a52ea49434c8
[test/entity] fix test (following mtconverter 0.8+ plain text transform change)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6099
diff
changeset
|
543 |
'<p>\ndu *texte*<br/>\n</p>') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
544 |
e.cw_attr_cache['title'] = 'zou' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
545 |
e.cw_attr_cache['content'] = '''\ |
0 | 546 |
a title |
547 |
======= |
|
548 |
du :eid:`1:*ReST*`''' |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
549 |
e.cw_attr_cache['content_format'] = 'text/rest' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
550 |
self.assertEqual(e.printable_value('content', format='text/plain'), |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
551 |
e.cw_attr_cache['content']) |
0 | 552 |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
553 |
e.cw_attr_cache['content'] = u'<b>yo (zou éà ;)</b>' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
554 |
e.cw_attr_cache['content_format'] = 'text/html' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
555 |
self.assertEqual(e.printable_value('content', format='text/plain').strip(), |
6416
2ca48e45522e
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
556 |
u'**yo (zou éà ;)**') |
821
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
557 |
if HAS_TAL: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
558 |
e.cw_attr_cache['content'] = '<h1 tal:content="self/title">titre</h1>' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
559 |
e.cw_attr_cache['content_format'] = 'text/cubicweb-page-template' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
560 |
self.assertEqual(e.printable_value('content'), |
821
78cc1682c3a4
fix test on systems that don't have simpleTAL installed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
748
diff
changeset
|
561 |
'<h1>zou</h1>') |
1640 | 562 |
|
0 | 563 |
|
564 |
def test_printable_value_bytes(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
565 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
566 |
e = req.create_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python', |
3587 | 567 |
data_encoding=u'ascii', data_name=u'toto.py') |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4015
diff
changeset
|
568 |
from cubicweb import mttransforms |
0 | 569 |
if mttransforms.HAS_PYGMENTS_TRANSFORMS: |
5631
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
570 |
import pygments |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
571 |
if tuple(int(i) for i in pygments.__version__.split('.')[:2]) >= (1, 3): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
572 |
self.assertEqual(e.printable_value('data'), |
5631
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
573 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">1</span> |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
574 |
</pre></div> |
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
575 |
''') |
5634
e01cf2013bf1
stop being dumb please
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5631
diff
changeset
|
576 |
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
|
577 |
self.assertEqual(e.printable_value('data'), |
5631
e2e99cdf0899
[test] generated html differs w/ pygments version
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5582
diff
changeset
|
578 |
'''<div class="highlight"><pre><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">1</span> |
0 | 579 |
</pre></div> |
580 |
''') |
|
581 |
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
|
582 |
self.assertEqual(e.printable_value('data'), |
0 | 583 |
'''<pre class="python"> |
584 |
<span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span> |
|
585 |
</pre> |
|
586 |
''') |
|
1640 | 587 |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
588 |
e = req.create_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest', |
3587 | 589 |
data_encoding=u'utf-8', data_name=u'toto.txt') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
590 |
self.assertEqual(e.printable_value('data'), |
0 | 591 |
u'<p><em>héhéhé</em></p>\n') |
592 |
||
593 |
def test_printable_value_bad_html(self): |
|
594 |
"""make sure we don't crash if we try to render invalid XHTML strings""" |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
595 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
596 |
e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
0 | 597 |
content_format=u'text/html') |
598 |
tidy = lambda x: x.replace('\n', '') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
599 |
self.assertEqual(tidy(e.printable_value('content')), |
0 | 600 |
'<div>R&D<br/></div>') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
601 |
e.cw_attr_cache['content'] = u'yo !! R&D <div> pas fermé' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
602 |
self.assertEqual(tidy(e.printable_value('content')), |
0 | 603 |
u'yo !! R&D <div> pas fermé</div>') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
604 |
e.cw_attr_cache['content'] = u'R&D' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
605 |
self.assertEqual(tidy(e.printable_value('content')), u'R&D') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
606 |
e.cw_attr_cache['content'] = u'R&D;' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
607 |
self.assertEqual(tidy(e.printable_value('content')), u'R&D;') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
608 |
e.cw_attr_cache['content'] = u'yo !! R&D <div> pas fermé' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
609 |
self.assertEqual(tidy(e.printable_value('content')), |
6415 | 610 |
u'yo !! R&D <div> pas fermé</div>') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
611 |
e.cw_attr_cache['content'] = u'été <div> été' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
612 |
self.assertEqual(tidy(e.printable_value('content')), |
6416
2ca48e45522e
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
613 |
u'été <div> été</div>') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
614 |
e.cw_attr_cache['content'] = u'C'est un exemple sérieux' |
6366 | 615 |
self.assertEqual(tidy(e.printable_value('content')), |
6416
2ca48e45522e
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
616 |
u"C'est un exemple sérieux") |
3587 | 617 |
# make sure valid xhtml is left untouched |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
618 |
e.cw_attr_cache['content'] = u'<div>R&D<br/></div>' |
6366 | 619 |
self.assertEqual(e.printable_value('content'), e.cw_attr_cache['content']) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
620 |
e.cw_attr_cache['content'] = u'<div>été</div>' |
6366 | 621 |
self.assertEqual(e.printable_value('content'), e.cw_attr_cache['content']) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
622 |
e.cw_attr_cache['content'] = u'été' |
6366 | 623 |
self.assertEqual(e.printable_value('content'), e.cw_attr_cache['content']) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
624 |
e.cw_attr_cache['content'] = u'hop\r\nhop\nhip\rmomo' |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
625 |
self.assertEqual(e.printable_value('content'), u'hop\nhop\nhip\nmomo') |
3587 | 626 |
|
627 |
def test_printable_value_bad_html_ms(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
628 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
629 |
e = req.create_entity('Card', title=u'bad html', content=u'<div>R&D<br>', |
3587 | 630 |
content_format=u'text/html') |
631 |
tidy = lambda x: x.replace('\n', '') |
|
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
632 |
e.cw_attr_cache['content'] = u'<div x:foo="bar">ms orifice produces weird html</div>' |
6685
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6427
diff
changeset
|
633 |
# Caution! current implementation of soup2xhtml strips first div element |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6427
diff
changeset
|
634 |
content = soup2xhtml(e.printable_value('content'), 'utf-8') |
eeedb3575d25
[uilib] soup2xhtml uses now lxml.html.Cleaner
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6427
diff
changeset
|
635 |
self.assertMultiLineEqual(content, u'<div>ms orifice produces weird html</div>') |
1640 | 636 |
|
0 | 637 |
def test_fulltextindex(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
638 |
e = self.vreg['etypes'].etype_class('File')(self.request()) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
639 |
e.cw_attr_cache['description'] = 'du <em>html</em>' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
640 |
e.cw_attr_cache['description_format'] = 'text/html' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
641 |
e.cw_attr_cache['data'] = Binary('some <em>data</em>') |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
642 |
e.cw_attr_cache['data_name'] = 'an html file' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
643 |
e.cw_attr_cache['data_format'] = 'text/html' |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6099
diff
changeset
|
644 |
e.cw_attr_cache['data_encoding'] = 'ascii' |
4015
4f8235204dda
some cw 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
645 |
e._cw.transaction_data = {} # XXX req should be a session |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
646 |
self.assertEqual(e.cw_adapt_to('IFTIndexable').get_words(), |
6416
2ca48e45522e
fix bad merge
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
647 |
{'C': ['an', 'html', 'file', 'du', 'html', 'some', 'data']}) |
0 | 648 |
|
1640 | 649 |
|
0 | 650 |
def test_nonregr_relation_cache(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
651 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
652 |
p1 = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
653 |
p2 = req.create_entity('Personne', nom=u'toto') |
0 | 654 |
self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
655 |
self.assertEqual(p1.evaluee[0].nom, "toto") |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
656 |
self.assertTrue(not p1.reverse_evaluee) |
1640 | 657 |
|
0 | 658 |
def test_complete_relation(self): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
659 |
session = self.session |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
660 |
eid = session.execute( |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
661 |
'INSERT TrInfo X: X comment "zou", X wf_info_for U, X from_state S1, X to_state S2 ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
662 |
'WHERE U login "admin", S1 name "activated", S2 name "deactivated"')[0][0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
663 |
trinfo = self.execute('Any X WHERE X eid %(x)s', {'x': eid}).get_entity(0, 0) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
664 |
trinfo.complete() |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
665 |
self.assertTrue(isinstance(trinfo.cw_attr_cache['creation_date'], datetime)) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
666 |
self.assertTrue(trinfo.cw_relation_cached('from_state', 'subject')) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
667 |
self.assertTrue(trinfo.cw_relation_cached('to_state', 'subject')) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
668 |
self.assertTrue(trinfo.cw_relation_cached('wf_info_for', 'subject')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
669 |
self.assertEqual(trinfo.by_transition, ()) |
0 | 670 |
|
671 |
def test_request_cache(self): |
|
672 |
req = self.request() |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
673 |
user = self.execute('CWUser X WHERE X login "admin"', req=req).get_entity(0, 0) |
0 | 674 |
state = user.in_state[0] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
675 |
samestate = self.execute('State X WHERE X name "activated"', req=req).get_entity(0, 0) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7554
diff
changeset
|
676 |
self.assertTrue(state is samestate) |
0 | 677 |
|
678 |
def test_rest_path(self): |
|
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
679 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
680 |
note = req.create_entity('Note', type=u'z') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
681 |
self.assertEqual(note.rest_path(), 'note/%s' % note.eid) |
0 | 682 |
# unique attr |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
683 |
tag = req.create_entity('Tag', name=u'x') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
684 |
self.assertEqual(tag.rest_path(), 'tag/x') |
0 | 685 |
# test explicit rest_attr |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
686 |
person = req.create_entity('Personne', prenom=u'john', nom=u'doe') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
687 |
self.assertEqual(person.rest_path(), 'personne/doe') |
0 | 688 |
# ambiguity test |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
689 |
person2 = req.create_entity('Personne', prenom=u'remi', nom=u'doe') |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
690 |
person.cw_clear_all_caches() |
8286
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
691 |
self.assertEqual(person.rest_path(), unicode(person.eid)) |
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
692 |
self.assertEqual(person2.rest_path(), unicode(person2.eid)) |
0 | 693 |
# unique attr with None value (wikiid in this case) |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
694 |
card1 = req.create_entity('Card', title=u'hop') |
8286
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
695 |
self.assertEqual(card1.rest_path(), unicode(card1.eid)) |
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
|
696 |
# don't use rest if we have /, ? or & in the path (breaks mod_proxy) |
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
|
697 |
card2 = req.create_entity('Card', title=u'pod', wikiid=u'zo/bi') |
8286
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
698 |
self.assertEqual(card2.rest_path(), unicode(card2.eid)) |
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
|
699 |
card3 = req.create_entity('Card', title=u'pod', wikiid=u'zo&bi') |
8286
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
700 |
self.assertEqual(card3.rest_path(), unicode(card3.eid)) |
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
|
701 |
card4 = req.create_entity('Card', title=u'pod', wikiid=u'zo?bi') |
8286
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
702 |
self.assertEqual(card4.rest_path(), unicode(card4.eid)) |
6415 | 703 |
|
0 | 704 |
|
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
|
705 |
def test_cw_set_attributes(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
706 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
707 |
person = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
708 |
self.assertEqual(person.prenom, u'adrien') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
709 |
self.assertEqual(person.nom, u'di mascio') |
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
|
710 |
person.cw_set(prenom=u'sylvain', nom=u'thénault') |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
711 |
person = self.execute('Personne P').get_entity(0, 0) # XXX retreival needed ? |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
712 |
self.assertEqual(person.prenom, u'sylvain') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
713 |
self.assertEqual(person.nom, u'thénault') |
0 | 714 |
|
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
|
715 |
def test_cw_set_relations(self): |
7308
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
716 |
req = self.request() |
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
717 |
person = req.create_entity('Personne', nom=u'chauvat', prenom=u'nicolas') |
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
718 |
note = req.create_entity('Note', type=u'x') |
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
|
719 |
note.cw_set(ecrit_par=person) |
7308
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
720 |
note = req.create_entity('Note', type=u'y') |
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
|
721 |
note.cw_set(ecrit_par=person.eid) |
7308
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
722 |
self.assertEqual(len(person.reverse_ecrit_par), 2) |
ff8d6ae076c4
[entity] make set_relations() accept entities and eids (closes #1631391)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7302
diff
changeset
|
723 |
|
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
724 |
def test_metainformation_and_external_absolute_url(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
725 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
726 |
note = req.create_entity('Note', type=u'z') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
727 |
metainf = note.cw_metainformation() |
7554 | 728 |
self.assertEqual(metainf, {'source': {'type': 'native', 'uri': 'system', |
729 |
'use-cwuri-as-url': False}, |
|
730 |
'type': u'Note', 'extid': None}) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
731 |
self.assertEqual(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid) |
0 | 732 |
metainf['source'] = metainf['source'].copy() |
733 |
metainf['source']['base-url'] = 'http://cubicweb2.com/' |
|
1905
9c96dd7cc624
[tests] fix test after absolute_url got changed for external entities
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1640
diff
changeset
|
734 |
metainf['extid'] = 1234 |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
735 |
self.assertEqual(note.absolute_url(), 'http://cubicweb2.com/note/1234') |
1640 | 736 |
|
2125
19861294506f
https://www.logilab.net/cwo/ticket/343724
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
737 |
def test_absolute_url_empty_field(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
738 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
739 |
card = req.create_entity('Card', wikiid=u'', title=u'test') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
740 |
self.assertEqual(card.absolute_url(), |
8286
8b0146e31baa
[entity url] rest path fallback should be the url used as cwuri. Closes #2186039
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8199
diff
changeset
|
741 |
'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
|
742 |
|
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
743 |
def test_create_entity(self): |
4031
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
744 |
req = self.request() |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
745 |
p1 = req.create_entity('Personne', nom=u'fayolle', prenom=u'alexandre') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
746 |
p2 = req.create_entity('Personne', nom=u'campeas', prenom=u'aurelien') |
56f4d4f7f86f
test api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
747 |
note = req.create_entity('Note', type=u'z') |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
748 |
req = self.request() |
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
749 |
p = req.create_entity('Personne', nom=u'di mascio', prenom=u'adrien', |
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
750 |
connait=p1, evaluee=[p1, p2], |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
751 |
reverse_ecrit_par=note) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
752 |
self.assertEqual(p.nom, 'di mascio') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
753 |
self.assertEqual([c.nom for c in p.connait], ['fayolle']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
754 |
self.assertEqual(sorted([c.nom for c in p.evaluee]), ['campeas', 'fayolle']) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6168
diff
changeset
|
755 |
self.assertEqual([c.type for c in p.reverse_ecrit_par], ['z']) |
3669
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
756 |
|
4eb33ee29c84
nicer create_entity implementation (and test)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3587
diff
changeset
|
757 |
|
3670
b7ec030a5e10
allow to link to multiple entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3669
diff
changeset
|
758 |
|
0 | 759 |
if __name__ == '__main__': |
760 |
from logilab.common.testlib import unittest_main |
|
761 |
unittest_main() |
|
762 |