author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Mon, 12 Apr 2010 08:22:37 +0200 | |
branch | stable |
changeset 5213 | 8604000bf3b2 |
parent 4793 | fdb5476dee9a |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""unit tests for schema rql (de)serialization |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1787
diff
changeset
|
2 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 3 |
""" |
4 |
||
5 |
import sys |
|
6 |
from cStringIO import StringIO |
|
7 |
||
8 |
from logilab.common.testlib import TestCase, unittest_main |
|
9 |
||
10 |
from cubicweb.schema import CubicWebSchemaLoader |
|
11 |
from cubicweb.devtools import TestServerConfiguration |
|
12 |
||
13 |
loader = CubicWebSchemaLoader() |
|
14 |
config = TestServerConfiguration('data') |
|
15 |
config.bootstrap_cubes() |
|
16 |
schema = loader.load(config) |
|
17 |
||
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
18 |
def teardown_module(*args): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
19 |
global schema, config, loader |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
20 |
del schema, config, loader |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4763
diff
changeset
|
21 |
|
0 | 22 |
from cubicweb.server.schemaserial import * |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
23 |
from cubicweb.server.schemaserial import _erperms2rql as erperms2rql |
1787 | 24 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
25 |
cstrtypemap = {'RQLConstraint': 'RQLConstraint_eid', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
26 |
'SizeConstraint': 'SizeConstraint_eid', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
27 |
'StaticVocabularyConstraint': 'StaticVocabularyConstraint_eid', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
28 |
'FormatConstraint': 'FormatConstraint_eid', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
29 |
} |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
30 |
|
0 | 31 |
class Schema2RQLTC(TestCase): |
1787 | 32 |
|
0 | 33 |
def test_eschema2rql1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
34 |
self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))), |
0 | 35 |
[ |
2447
b83fcc2311af
fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2200
diff
changeset
|
36 |
('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s', |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2447
diff
changeset
|
37 |
{'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema', |
2447
b83fcc2311af
fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2200
diff
changeset
|
38 |
'name': u'CWAttribute', 'final': False}) |
0 | 39 |
]) |
1787 | 40 |
|
0 | 41 |
def test_eschema2rql2(self): |
42 |
self.assertListEquals(list(eschema2rql(schema.eschema('String'))), [ |
|
2447
b83fcc2311af
fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2200
diff
changeset
|
43 |
('INSERT CWEType X: X description %(description)s,X final %(final)s,X name %(name)s', |
b83fcc2311af
fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2200
diff
changeset
|
44 |
{'description': u'', 'final': True, 'name': u'String'})]) |
1787 | 45 |
|
0 | 46 |
def test_eschema2rql_specialization(self): |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
47 |
# x: None since eschema.eid are None |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
48 |
self.assertListEquals(sorted(specialize2rql(schema)), |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
49 |
[('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
50 |
{'et': None, 'x': None}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
51 |
('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
52 |
{'et': None, 'x': None}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
53 |
('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
54 |
{'et': None, 'x': None}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
55 |
# ('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
56 |
# {'et': 'File', 'x': 'Image'}), |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
57 |
('SET X specializes ET WHERE X eid %(x)s, ET eid %(et)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
58 |
{'et': None, 'x': None})]) |
1787 | 59 |
|
0 | 60 |
def test_rschema2rql1(self): |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
61 |
self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)), |
0 | 62 |
[ |
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:
4191
diff
changeset
|
63 |
('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s', |
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:
4191
diff
changeset
|
64 |
{'description': u'link a relation definition to its relation type', 'symmetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}), |
1787 | 65 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
66 |
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
67 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
68 |
'description': u'', 'composite': u'object', 'cardinality': u'1*', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
69 |
'ordernum': 1}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
70 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
71 |
{'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final TRUE\n'}), |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
72 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
73 |
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
74 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
75 |
'description': u'', 'composite': u'object', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
76 |
'ordernum': 1, 'cardinality': u'1*'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
77 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
78 |
{'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final FALSE\n'}), |
0 | 79 |
]) |
1787 | 80 |
|
0 | 81 |
def test_rschema2rql2(self): |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
82 |
self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)), |
1787 | 83 |
[ |
4680
8a6bee838464
[test] update tests broken by changes on attributes permissions handling in yams (add/delete replaced by update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
84 |
('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s', {'description': u'', 'symmetric': False, 'name': u'add_permission', 'final': False, 'fulltext_container': None, 'inlined': False}), |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
85 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
86 |
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
87 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
88 |
'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
89 |
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
90 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
91 |
'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}), |
1787 | 92 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
93 |
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
94 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
95 |
'description': u'groups allowed to add entities/relations of this type', 'composite': None, 'ordernum': 9999, 'cardinality': u'**'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
96 |
('INSERT CWRelation X: X cardinality %(cardinality)s,X composite %(composite)s,X description %(description)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
97 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
98 |
'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}), |
1787 | 99 |
]) |
100 |
||
0 | 101 |
def test_rschema2rql3(self): |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
102 |
self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)), |
0 | 103 |
[ |
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:
4191
diff
changeset
|
104 |
('INSERT CWRType X: X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s', |
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:
4191
diff
changeset
|
105 |
{'description': u'', 'symmetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}), |
0 | 106 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
107 |
('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
108 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
109 |
'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
110 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
111 |
{'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
112 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
113 |
{'x': None, 'ct': u'StaticVocabularyConstraint_eid', 'value': u"u'?1', u'11'"}), |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
114 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
115 |
('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
116 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
117 |
'description': u'subject/object cardinality', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 5, 'defaultval': None, 'indexed': False, 'cardinality': u'?1'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
118 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
119 |
{'x': None, 'ct': u'SizeConstraint_eid', 'value': u'max=2'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
120 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
121 |
{'x': None, 'ct': u'StaticVocabularyConstraint_eid', 'value': u"u'?*', u'1*', u'+*', u'**', u'?+', u'1+', u'++', u'*+', u'?1', u'11', u'+1', u'*1', u'??', u'1?', u'+?', u'*?'"}), |
1787 | 122 |
]) |
0 | 123 |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
124 |
def test_rdef2rql(self): |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
125 |
self.assertListEquals(list(rdef2rql(schema['description_format'].rdefs[('CWRType', 'String')], cstrtypemap)), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
126 |
[ |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
127 |
('INSERT CWAttribute X: X cardinality %(cardinality)s,X defaultval %(defaultval)s,X description %(description)s,X fulltextindexed %(fulltextindexed)s,X indexed %(indexed)s,X internationalizable %(internationalizable)s,X ordernum %(ordernum)s,X relation_type ER,X from_entity SE,X to_entity OE WHERE SE eid %(se)s,ER eid %(rt)s,OE eid %(oe)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
128 |
{'se': None, 'rt': None, 'oe': None, |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
129 |
'description': u'', 'internationalizable': True, 'fulltextindexed': False, 'ordernum': 7, 'defaultval': u'text/plain', 'indexed': False, 'cardinality': u'?1'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
130 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
131 |
{'x': None, 'value': u'None', 'ct': 'FormatConstraint_eid'}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
132 |
('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT eid %(ct)s, EDEF eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
133 |
{'x': None, 'value': u'max=50', 'ct': 'SizeConstraint_eid'})]) |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
134 |
|
0 | 135 |
|
136 |
def test_updateeschema2rql1(self): |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
137 |
self.assertListEquals(list(updateeschema2rql(schema.eschema('CWAttribute'), 1)), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
138 |
[('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
139 |
{'description': u'define a final relation: link a final relation type from a non final entity to a final entity type. used to build the instance schema', 'x': 1, 'final': False, 'name': u'CWAttribute'}), |
0 | 140 |
]) |
1787 | 141 |
|
0 | 142 |
def test_updateeschema2rql2(self): |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
143 |
self.assertListEquals(list(updateeschema2rql(schema.eschema('String'), 1)), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
144 |
[('SET X description %(description)s,X final %(final)s,X name %(name)s WHERE X eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
145 |
{'description': u'', 'x': 1, 'final': True, 'name': u'String'}) |
0 | 146 |
]) |
1787 | 147 |
|
0 | 148 |
def test_updaterschema2rql1(self): |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
149 |
self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'), 1)), |
0 | 150 |
[ |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
151 |
('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
152 |
{'x': 1, 'symmetric': False, |
0 | 153 |
'description': u'link a relation definition to its relation type', |
2447
b83fcc2311af
fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2200
diff
changeset
|
154 |
'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'}) |
0 | 155 |
]) |
1787 | 156 |
|
0 | 157 |
def test_updaterschema2rql2(self): |
158 |
expected = [ |
|
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
159 |
('SET X description %(description)s,X final %(final)s,X fulltext_container %(fulltext_container)s,X inlined %(inlined)s,X name %(name)s,X symmetric %(symmetric)s WHERE X eid %(x)s', |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
160 |
{'x': 1, 'symmetric': False, |
4680
8a6bee838464
[test] update tests broken by changes on attributes permissions handling in yams (add/delete replaced by update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
161 |
'description': u'', 'final': False, 'fulltext_container': None, |
8a6bee838464
[test] update tests broken by changes on attributes permissions handling in yams (add/delete replaced by update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
162 |
'inlined': False, 'name': u'add_permission'}) |
0 | 163 |
] |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
164 |
for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'), 1)): |
0 | 165 |
yield self.assertEquals, (rql, args), expected[i] |
166 |
||
167 |
class Perms2RQLTC(TestCase): |
|
168 |
GROUP_MAPPING = { |
|
169 |
'managers': 0, |
|
170 |
'users': 1, |
|
171 |
'guests': 2, |
|
172 |
'owners': 3, |
|
173 |
} |
|
1787 | 174 |
|
0 | 175 |
def test_eperms2rql1(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
176 |
self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.eschema('CWEType'), self.GROUP_MAPPING)], |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
177 |
[('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
178 |
('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
179 |
('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
180 |
('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
181 |
('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
182 |
('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
0 | 183 |
]) |
1787 | 184 |
|
0 | 185 |
def test_rperms2rql2(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
186 |
self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.rschema('read_permission').rdef('CWEType', 'CWGroup'), self.GROUP_MAPPING)], |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
187 |
[('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
188 |
('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
189 |
('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
190 |
('SET X add_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
191 |
('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
0 | 192 |
]) |
1787 | 193 |
|
0 | 194 |
def test_rperms2rql3(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
195 |
self.assertListEquals([(rql, kwargs) for rql, kwargs in erperms2rql(schema.rschema('name').rdef('CWEType', 'String'), self.GROUP_MAPPING)], |
4763
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
196 |
[('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
197 |
('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 1}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
198 |
('SET X read_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 2}), |
81b0df087375
schema serialization optimization by using eids instead of type names. Heavy refactoring/cleanup on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4680
diff
changeset
|
199 |
('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
0 | 200 |
]) |
1787 | 201 |
|
0 | 202 |
#def test_perms2rql(self): |
203 |
# self.assertListEquals(perms2rql(schema, self.GROUP_MAPPING), |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
204 |
# ['INSERT CWEType X: X name 'Societe', X final FALSE']) |
1787 | 205 |
|
0 | 206 |
|
207 |
||
208 |
if __name__ == '__main__': |
|
209 |
unittest_main() |