hooks/test/unittest_syncschema.py
branchstable
changeset 4691 ae468fae9965
parent 4689 4eb1f4490538
child 4766 162b2b127b15
child 4826 7eba168407c3
--- a/hooks/test/unittest_syncschema.py	Wed Feb 24 11:53:36 2010 +0100
+++ b/hooks/test/unittest_syncschema.py	Wed Feb 24 12:57:30 2010 +0100
@@ -7,12 +7,37 @@
 
 SCHEMA_EIDS = {}
 class SchemaModificationHooksTC(CubicWebTC):
+    reset_schema = True
 
     @classmethod
     def init_config(cls, config):
         super(SchemaModificationHooksTC, cls).init_config(config)
+        # we have to read schema from the database to get eid for schema entities
         config._cubes = None
         cls.repo.fill_schema()
+        # remember them so we can reread it from the fs instead of the db (too
+        # costly) between tests
+        for x in cls.repo.schema.entities():
+            SCHEMA_EIDS[x] = x.eid
+        for x in cls.repo.schema.relations():
+            SCHEMA_EIDS[x] = x.eid
+            for rdef in x.rdefs.itervalues():
+                SCHEMA_EIDS[(rdef.subject, rdef.rtype, rdef.object)] = rdef.eid
+
+    @classmethod
+    def _refresh_repo(cls):
+        super(SchemaModificationHooksTC, cls)._refresh_repo()
+        # rebuild schema eid index
+        schema = cls.repo.schema
+        for x in schema.entities():
+            x.eid = SCHEMA_EIDS[x]
+            schema._eid_index[x.eid] = x
+        for x in cls.repo.schema.relations():
+            x.eid = SCHEMA_EIDS[x]
+            schema._eid_index[x.eid] = x
+            for rdef in x.rdefs.itervalues():
+                rdef.eid = SCHEMA_EIDS[(rdef.subject, rdef.rtype, rdef.object)]
+                schema._eid_index[rdef.eid] = rdef
 
     def index_exists(self, etype, attr, unique=False):
         self.session.set_pool()