equal
deleted
inserted
replaced
28 from copy import copy |
28 from copy import copy |
29 from yams.schema import BASE_TYPES, RelationSchema, RelationDefinitionSchema |
29 from yams.schema import BASE_TYPES, RelationSchema, RelationDefinitionSchema |
30 from yams import buildobjs as ybo, schema2sql as y2sql |
30 from yams import buildobjs as ybo, schema2sql as y2sql |
31 |
31 |
32 from logilab.common.decorators import clear_cache |
32 from logilab.common.decorators import clear_cache |
33 from logilab.common.testlib import mock_object |
|
34 |
33 |
35 from cubicweb import ValidationError |
34 from cubicweb import ValidationError |
36 from cubicweb.selectors import is_instance |
35 from cubicweb.selectors import is_instance |
37 from cubicweb.schema import (SCHEMA_TYPES, META_RTYPES, VIRTUAL_RTYPES, |
36 from cubicweb.schema import (SCHEMA_TYPES, META_RTYPES, VIRTUAL_RTYPES, |
38 CONSTRAINTS, ETYPE_NAME_MAP, display_name) |
37 CONSTRAINTS, ETYPE_NAME_MAP, display_name) |
127 if newval != origval: |
126 if newval != origval: |
128 errors[attr] = session._("can't change the %s attribute") % \ |
127 errors[attr] = session._("can't change the %s attribute") % \ |
129 display_name(session, attr) |
128 display_name(session, attr) |
130 if errors: |
129 if errors: |
131 raise ValidationError(entity.eid, errors) |
130 raise ValidationError(entity.eid, errors) |
|
131 |
|
132 |
|
133 class _MockEntity(object): # XXX use a named tuple with python 2.6 |
|
134 def __init__(self, eid): |
|
135 self.eid = eid |
132 |
136 |
133 |
137 |
134 class SyncSchemaHook(hook.Hook): |
138 class SyncSchemaHook(hook.Hook): |
135 """abstract class for schema synchronization hooks (in the `syncschema` |
139 """abstract class for schema synchronization hooks (in the `syncschema` |
136 category) |
140 category) |
264 continue # XXX 3.10 migration |
268 continue # XXX 3.10 migration |
265 raise |
269 raise |
266 sampletype = rschema.subjects()[0] |
270 sampletype = rschema.subjects()[0] |
267 desttype = rschema.objects()[0] |
271 desttype = rschema.objects()[0] |
268 rdef = copy(rschema.rdef(sampletype, desttype)) |
272 rdef = copy(rschema.rdef(sampletype, desttype)) |
269 rdef.subject = mock_object(eid=entity.eid) |
273 rdef.subject = _MockEntity(eid=entity.eid) |
270 mock = mock_object(eid=None) |
274 mock = _MockEntity(eid=None) |
271 ss.execschemarql(session.execute, mock, ss.rdef2rql(rdef, cmap, gmap)) |
275 ss.execschemarql(session.execute, mock, ss.rdef2rql(rdef, cmap, gmap)) |
272 |
276 |
273 def revertprecommit_event(self): |
277 def revertprecommit_event(self): |
274 # revert changes on in memory schema |
278 # revert changes on in memory schema |
275 self.session.vreg.schema.del_entity_type(self.entity.name) |
279 self.session.vreg.schema.del_entity_type(self.entity.name) |