author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 03 Mar 2010 17:56:04 +0100 | |
changeset 4763 | 81b0df087375 |
parent 4680 | 8a6bee838464 |
child 4766 | 162b2b127b15 |
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 |
||
18 |
from cubicweb.server.schemaserial import * |
|
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
19 |
from cubicweb.server.schemaserial import _erperms2rql as erperms2rql |
1787 | 20 |
|
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
|
21 |
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
|
22 |
'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
|
23 |
'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
|
24 |
'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
|
25 |
} |
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 |
|
0 | 27 |
class Schema2RQLTC(TestCase): |
1787 | 28 |
|
0 | 29 |
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
|
30 |
self.assertListEquals(list(eschema2rql(schema.eschema('CWAttribute'))), |
0 | 31 |
[ |
2447
b83fcc2311af
fix schemaserial tests: meta doesn't exist anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2200
diff
changeset
|
32 |
('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
|
33 |
{'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
|
34 |
'name': u'CWAttribute', 'final': False}) |
0 | 35 |
]) |
1787 | 36 |
|
0 | 37 |
def test_eschema2rql2(self): |
38 |
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
|
39 |
('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
|
40 |
{'description': u'', 'final': True, 'name': u'String'})]) |
1787 | 41 |
|
0 | 42 |
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
|
43 |
# 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
|
44 |
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
|
45 |
[('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
|
46 |
{'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
|
47 |
('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
|
48 |
{'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
|
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', |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2730
diff
changeset
|
52 |
# {'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
|
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})]) |
1787 | 55 |
|
0 | 56 |
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
|
57 |
self.assertListEquals(list(rschema2rql(schema.rschema('relation_type'), cstrtypemap)), |
0 | 58 |
[ |
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
|
59 |
('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
|
60 |
{'description': u'link a relation definition to its relation type', 'symmetric': False, 'name': u'relation_type', 'final' : False, 'fulltext_container': None, 'inlined': True}), |
1787 | 61 |
|
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
|
62 |
('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
|
63 |
{'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
|
64 |
'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
|
65 |
'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
|
66 |
('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
|
67 |
{'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
|
68 |
|
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
|
69 |
('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
|
70 |
{'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
|
71 |
'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
|
72 |
'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
|
73 |
('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
|
74 |
{'x': None, 'ct': u'RQLConstraint_eid', 'value': u';O;O final FALSE\n'}), |
0 | 75 |
]) |
1787 | 76 |
|
0 | 77 |
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
|
78 |
self.assertListEquals(list(rschema2rql(schema.rschema('add_permission'), cstrtypemap)), |
1787 | 79 |
[ |
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
|
80 |
('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
|
81 |
|
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 |
('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
|
83 |
{'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
|
84 |
'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
|
85 |
('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
|
86 |
{'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
|
87 |
'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}), |
1787 | 88 |
|
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
|
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'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
|
92 |
('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
|
93 |
{'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
|
94 |
'description': u'rql expression allowing to add entities/relations of this type', 'composite': 'subject', 'ordernum': 9999, 'cardinality': u'*?'}), |
1787 | 95 |
]) |
96 |
||
0 | 97 |
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
|
98 |
self.assertListEquals(list(rschema2rql(schema.rschema('cardinality'), cstrtypemap)), |
0 | 99 |
[ |
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
|
100 |
('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
|
101 |
{'description': u'', 'symmetric': False, 'name': u'cardinality', 'final': True, 'fulltext_container': None, 'inlined': False}), |
0 | 102 |
|
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
|
103 |
('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
|
104 |
{'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
|
105 |
'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
|
106 |
('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
|
107 |
{'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
|
108 |
('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
|
109 |
{'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
|
110 |
|
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
|
111 |
('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
|
112 |
{'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
|
113 |
'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
|
114 |
('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
|
115 |
{'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
|
116 |
('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
|
117 |
{'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 | 118 |
]) |
0 | 119 |
|
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
|
120 |
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
|
121 |
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
|
122 |
[ |
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
|
123 |
('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
|
124 |
{'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
|
125 |
'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
|
126 |
('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
|
127 |
{'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
|
128 |
('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
|
129 |
{'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
|
130 |
|
0 | 131 |
|
132 |
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
|
133 |
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
|
134 |
[('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
|
135 |
{'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 | 136 |
]) |
1787 | 137 |
|
0 | 138 |
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
|
139 |
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
|
140 |
[('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
|
141 |
{'description': u'', 'x': 1, 'final': True, 'name': u'String'}) |
0 | 142 |
]) |
1787 | 143 |
|
0 | 144 |
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
|
145 |
self.assertListEquals(list(updaterschema2rql(schema.rschema('relation_type'), 1)), |
0 | 146 |
[ |
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
|
147 |
('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
|
148 |
{'x': 1, 'symmetric': False, |
0 | 149 |
'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
|
150 |
'final': False, 'fulltext_container': None, 'inlined': True, 'name': u'relation_type'}) |
0 | 151 |
]) |
1787 | 152 |
|
0 | 153 |
def test_updaterschema2rql2(self): |
154 |
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
|
155 |
('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
|
156 |
{'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
|
157 |
'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
|
158 |
'inlined': False, 'name': u'add_permission'}) |
0 | 159 |
] |
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
|
160 |
for i, (rql, args) in enumerate(updaterschema2rql(schema.rschema('add_permission'), 1)): |
0 | 161 |
yield self.assertEquals, (rql, args), expected[i] |
162 |
||
163 |
class Perms2RQLTC(TestCase): |
|
164 |
GROUP_MAPPING = { |
|
165 |
'managers': 0, |
|
166 |
'users': 1, |
|
167 |
'guests': 2, |
|
168 |
'owners': 3, |
|
169 |
} |
|
1787 | 170 |
|
0 | 171 |
def test_eperms2rql1(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
172 |
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
|
173 |
[('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
|
174 |
('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
|
175 |
('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
|
176 |
('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
|
177 |
('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
|
178 |
('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
0 | 179 |
]) |
1787 | 180 |
|
0 | 181 |
def test_rperms2rql2(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
182 |
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
|
183 |
[('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
|
184 |
('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
|
185 |
('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
|
186 |
('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
|
187 |
('SET X delete_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
0 | 188 |
]) |
1787 | 189 |
|
0 | 190 |
def test_rperms2rql3(self): |
4191
01638461d4b0
test update. All cw tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3978
diff
changeset
|
191 |
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
|
192 |
[('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
|
193 |
('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
|
194 |
('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
|
195 |
('SET X update_permission Y WHERE Y eid %(g)s, X eid %(x)s', {'g': 0}), |
0 | 196 |
]) |
1787 | 197 |
|
0 | 198 |
#def test_perms2rql(self): |
199 |
# 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
|
200 |
# ['INSERT CWEType X: X name 'Societe', X final FALSE']) |
1787 | 201 |
|
0 | 202 |
|
203 |
||
204 |
if __name__ == '__main__': |
|
205 |
unittest_main() |