18 """cubicweb.server.hooks.syncschema unit and functional tests""" |
18 """cubicweb.server.hooks.syncschema unit and functional tests""" |
19 |
19 |
20 from logilab.common.testlib import TestCase, unittest_main |
20 from logilab.common.testlib import TestCase, unittest_main |
21 |
21 |
22 from cubicweb import ValidationError |
22 from cubicweb import ValidationError |
|
23 from cubicweb.schema import META_RTYPES |
23 from cubicweb.devtools.testlib import CubicWebTC |
24 from cubicweb.devtools.testlib import CubicWebTC |
24 from cubicweb.server.sqlutils import SQL_PREFIX |
25 from cubicweb.server.sqlutils import SQL_PREFIX |
25 from cubicweb.devtools.repotest import schema_eids_idx, restore_schema_eids_idx |
26 from cubicweb.devtools.repotest import schema_eids_idx, restore_schema_eids_idx |
|
27 |
26 |
28 |
27 def tearDownModule(*args): |
29 def tearDownModule(*args): |
28 del SchemaModificationHooksTC.schema_eids |
30 del SchemaModificationHooksTC.schema_eids |
29 |
31 |
30 class SchemaModificationHooksTC(CubicWebTC): |
32 class SchemaModificationHooksTC(CubicWebTC): |
114 self.assertFalse(self.index_exists('Societe2', 'name')) |
116 self.assertFalse(self.index_exists('Societe2', 'name')) |
115 self.assertFalse(schema.has_entity('Societe2')) |
117 self.assertFalse(schema.has_entity('Societe2')) |
116 self.assertFalse(schema.has_entity('concerne2')) |
118 self.assertFalse(schema.has_entity('concerne2')) |
117 self.assertFalse('concerne2' in schema['CWUser'].subject_relations()) |
119 self.assertFalse('concerne2' in schema['CWUser'].subject_relations()) |
118 |
120 |
|
121 def test_metartype_with_nordefs(self): |
|
122 META_RTYPES.add('custom_meta') |
|
123 self.execute('INSERT CWRType X: X name "custom_meta", X description "", ' |
|
124 'X final FALSE, X symmetric FALSE') |
|
125 self.commit() |
|
126 eeid = self.execute('INSERT CWEType X: X name "NEWEtype", ' |
|
127 'X description "", X final FALSE')[0][0] |
|
128 self._set_perms(eeid) |
|
129 self.commit() |
|
130 META_RTYPES.remove('custom_meta') |
|
131 |
|
132 def test_metartype_with_somerdefs(self): |
|
133 META_RTYPES.add('custom_meta') |
|
134 self.execute('INSERT CWRType X: X name "custom_meta", X description "", ' |
|
135 'X final FALSE, X symmetric FALSE') |
|
136 self.commit() |
|
137 rdefeid = self.execute('INSERT CWRelation X: X cardinality "**", X relation_type RT, ' |
|
138 ' X from_entity E, X to_entity E ' |
|
139 'WHERE RT name "custom_meta", E name "CWUser"')[0][0] |
|
140 self._set_perms(rdefeid) |
|
141 self.commit() |
|
142 eeid = self.execute('INSERT CWEType X: X name "NEWEtype", ' |
|
143 'X description "", X final FALSE')[0][0] |
|
144 self._set_perms(eeid) |
|
145 self.commit() |
|
146 META_RTYPES.remove('custom_meta') |
|
147 |
119 def test_is_instance_of_insertions(self): |
148 def test_is_instance_of_insertions(self): |
120 seid = self.execute('INSERT Transition T: T name "subdiv"')[0][0] |
149 seid = self.execute('INSERT Transition T: T name "subdiv"')[0][0] |
121 is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)] |
150 is_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is ET, ET name ETN' % seid)] |
122 self.assertEqual(is_etypes, ['Transition']) |
151 self.assertEqual(is_etypes, ['Transition']) |
123 instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)] |
152 instanceof_etypes = [etype for etype, in self.execute('Any ETN WHERE X eid %s, X is_instance_of ET, ET name ETN' % seid)] |