93 def __getattr__(self, attr): |
93 def __getattr__(self, attr): |
94 return getattr(self.origdict, attr) |
94 return getattr(self.origdict, attr) |
95 def __iter__(self): |
95 def __iter__(self): |
96 return iter(sorted(self.origdict, key=self.sortkey)) |
96 return iter(sorted(self.origdict, key=self.sortkey)) |
97 |
97 |
|
98 def schema_eids_idx(schema): |
|
99 """return a dictionary mapping schema types to their eids so we can reread |
|
100 it from the fs instead of the db (too costly) between tests |
|
101 """ |
|
102 schema_eids = {} |
|
103 for x in schema.entities(): |
|
104 schema_eids[x] = x.eid |
|
105 for x in schema.relations(): |
|
106 schema_eids[x] = x.eid |
|
107 for rdef in x.rdefs.itervalues(): |
|
108 schema_eids[(rdef.subject, rdef.rtype, rdef.object)] = rdef.eid |
|
109 return schema_eids |
|
110 |
|
111 def restore_schema_eids_idx(schema, schema_eids): |
|
112 """rebuild schema eid index""" |
|
113 for x in schema.entities(): |
|
114 x.eid = schema_eids[x] |
|
115 schema._eid_index[x.eid] = x |
|
116 for x in schema.relations(): |
|
117 x.eid = schema_eids[x] |
|
118 schema._eid_index[x.eid] = x |
|
119 for rdef in x.rdefs.itervalues(): |
|
120 rdef.eid = schema_eids[(rdef.subject, rdef.rtype, rdef.object)] |
|
121 schema._eid_index[rdef.eid] = rdef |
|
122 |
98 |
123 |
99 from logilab.common.testlib import TestCase |
124 from logilab.common.testlib import TestCase |
100 from rql import RQLHelper |
125 from rql import RQLHelper |
101 from cubicweb.devtools.fake import FakeRepo, FakeSession |
126 from cubicweb.devtools.fake import FakeRepo, FakeSession |
102 from cubicweb.server import set_debug |
127 from cubicweb.server import set_debug |