author | Julien Cristau <julien.cristau@logilab.fr> |
Thu, 15 Jan 2015 19:17:32 +0100 | |
changeset 10205 | 737271ffe407 |
parent 10192 | 365e5a0287d6 |
child 10662 | 10942ed172de |
permissions | -rw-r--r-- |
9967
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
1 |
# copyright 2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
3 |
# |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
4 |
# This file is part of CubicWeb. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
5 |
# |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
9 |
# any later version. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
10 |
# |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
14 |
# details. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
15 |
# |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
18 |
"""unit tests for computed attributes/relations hooks""" |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
19 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
20 |
from unittest import TestCase |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
21 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
22 |
from yams.buildobjs import EntityType, String, Int, SubjectRelation |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
23 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
24 |
from cubicweb.devtools.testlib import CubicWebTC |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
25 |
from cubicweb.schema import build_schema_from_namespace |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
26 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
27 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
28 |
class FormulaDependenciesMatrixTC(TestCase): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
29 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
30 |
def simple_schema(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
31 |
THISYEAR = 2014 |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
32 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
33 |
class Person(EntityType): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
34 |
name = String() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
35 |
salary = Int() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
36 |
birth_year = Int(required=True) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
37 |
works_for = SubjectRelation('Company') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
38 |
age = Int(formula='Any %d - D WHERE X birth_year D' % THISYEAR) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
39 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
40 |
class Company(EntityType): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
41 |
name = String() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
42 |
total_salary = Int(formula='Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
43 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
44 |
schema = build_schema_from_namespace(vars().items()) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
45 |
return schema |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
46 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
47 |
def setUp(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
48 |
from cubicweb.hooks.synccomputed import _FormulaDependenciesMatrix |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
49 |
self.schema = self.simple_schema() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
50 |
self.dependencies = _FormulaDependenciesMatrix(self.schema) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
51 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
52 |
def test_computed_attributes_by_etype(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
53 |
comp_by_etype = self.dependencies.computed_attribute_by_etype |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
54 |
self.assertEqual(len(comp_by_etype), 2) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
55 |
values = comp_by_etype['Person'] |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
56 |
self.assertEqual(len(values), 1) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
57 |
self.assertEqual(values[0].rtype, 'age') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
58 |
values = comp_by_etype['Company'] |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
59 |
self.assertEqual(len(values), 1) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
60 |
self.assertEqual(values[0].rtype, 'total_salary') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
61 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
62 |
def test_computed_attribute_by_relation(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
63 |
comp_by_rdef = self.dependencies.computed_attribute_by_relation |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
64 |
self.assertEqual(len(comp_by_rdef), 1) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
65 |
key, values = iter(comp_by_rdef.iteritems()).next() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
66 |
self.assertEqual(key.rtype, 'works_for') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
67 |
self.assertEqual(len(values), 1) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
68 |
self.assertEqual(values[0].rtype, 'total_salary') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
69 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
70 |
def test_computed_attribute_by_etype_attrs(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
71 |
comp_by_attr = self.dependencies.computed_attribute_by_etype_attrs |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
72 |
self.assertEqual(len(comp_by_attr), 1) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
73 |
values = comp_by_attr['Person'] |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
74 |
self.assertEqual(len(values), 2) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
75 |
values = set((rdef.formula, tuple(v)) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
76 |
for rdef, v in values.iteritems()) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
77 |
self.assertEquals(values, |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
78 |
set((('Any 2014 - D WHERE X birth_year D', tuple(('birth_year',))), |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
79 |
('Any SUM(SA) GROUPBY X WHERE P works_for X, P salary SA', tuple(('salary',))))) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
80 |
) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
81 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
82 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
83 |
class ComputedAttributeTC(CubicWebTC): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
84 |
appid = 'data-computed' |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
85 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
86 |
def setup_entities(self, req): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
87 |
self.societe = req.create_entity('Societe', nom=u'Foo') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
88 |
req.create_entity('Person', name=u'Titi', salaire=1000, |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
89 |
travaille=self.societe, birth_year=2001) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
90 |
self.tata = req.create_entity('Person', name=u'Tata', salaire=2000, |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
91 |
travaille=self.societe, birth_year=1990) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
92 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
93 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
94 |
def test_update_on_add_remove_relation(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
95 |
"""check the rewriting of a computed attribute""" |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
96 |
with self.admin_access.web_request() as req: |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
97 |
self.setup_entities(req) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
98 |
req.cnx.commit() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
99 |
rset = req.execute('Any S WHERE X salaire_total S, X nom "Foo"') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
100 |
self.assertEqual(rset[0][0], 3000) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
101 |
# Add relation. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
102 |
toto = req.create_entity('Person', name=u'Toto', salaire=1500, |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
103 |
travaille=self.societe, birth_year=1988) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
104 |
req.cnx.commit() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
105 |
rset = req.execute('Any S WHERE X salaire_total S, X nom "Foo"') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
106 |
self.assertEqual(rset[0][0], 4500) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
107 |
# Delete relation. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
108 |
toto.cw_set(travaille=None) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
109 |
req.cnx.commit() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
110 |
rset = req.execute('Any S WHERE X salaire_total S, X nom "Foo"') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
111 |
self.assertEqual(rset[0][0], 3000) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
112 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
113 |
def test_recompute_on_attribute_update(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
114 |
"""check the modification of an attribute triggers the update of the |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
115 |
computed attributes that depend on it""" |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
116 |
with self.admin_access.web_request() as req: |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
117 |
self.setup_entities(req) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
118 |
req.cnx.commit() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
119 |
rset = req.execute('Any S WHERE X salaire_total S, X nom "Foo"') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
120 |
self.assertEqual(rset[0][0], 3000) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
121 |
# Update attribute. |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
122 |
self.tata.cw_set(salaire=1000) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
123 |
req.cnx.commit() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
124 |
rset = req.execute('Any S WHERE X salaire_total S, X nom "Foo"') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
125 |
self.assertEqual(rset[0][0], 2000) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
126 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
127 |
def test_init_on_entity_creation(self): |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
128 |
"""check the computed attribute is initialized on entity creation""" |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
129 |
with self.admin_access.web_request() as req: |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
130 |
p = req.create_entity('Person', name=u'Tata', salaire=2000, |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
131 |
birth_year=1990) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
132 |
req.cnx.commit() |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
133 |
rset = req.execute('Any A, X WHERE X age A, X name "Tata"') |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
134 |
self.assertEqual(rset[0][0], 2014 - 1990) |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
135 |
|
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
136 |
|
10192
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
137 |
def test_recompute_on_ambiguous_relation(self): |
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
138 |
# check we don't end up with TypeResolverException as in #4901163 |
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
139 |
with self.admin_access.client_cnx() as cnx: |
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
140 |
societe = cnx.create_entity('Societe', nom=u'Foo') |
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
141 |
cnx.create_entity('MirrorEntity', mirror_of=societe, extid=u'1') |
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
142 |
cnx.commit() |
365e5a0287d6
[computed attribute] ensure attribute's formula apply only to the correct type. Closes #4901163
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9967
diff
changeset
|
143 |
|
9967
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
144 |
if __name__ == '__main__': |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
145 |
from logilab.common.testlib import unittest_main |
e65873ad0371
[CWEP002] Add support for computed attribute synchronization
Sylvain Thénault
parents:
diff
changeset
|
146 |
unittest_main() |