5 from cubicweb.server.sqlutils import SQL_PREFIX |
5 from cubicweb.server.sqlutils import SQL_PREFIX |
6 |
6 |
7 |
7 |
8 SCHEMA_EIDS = {} |
8 SCHEMA_EIDS = {} |
9 class SchemaModificationHooksTC(CubicWebTC): |
9 class SchemaModificationHooksTC(CubicWebTC): |
|
10 reset_schema = True |
10 |
11 |
11 @classmethod |
12 @classmethod |
12 def init_config(cls, config): |
13 def init_config(cls, config): |
13 super(SchemaModificationHooksTC, cls).init_config(config) |
14 super(SchemaModificationHooksTC, cls).init_config(config) |
|
15 # we have to read schema from the database to get eid for schema entities |
14 config._cubes = None |
16 config._cubes = None |
15 cls.repo.fill_schema() |
17 cls.repo.fill_schema() |
|
18 # remember them so we can reread it from the fs instead of the db (too |
|
19 # costly) between tests |
|
20 for x in cls.repo.schema.entities(): |
|
21 SCHEMA_EIDS[x] = x.eid |
|
22 for x in cls.repo.schema.relations(): |
|
23 SCHEMA_EIDS[x] = x.eid |
|
24 for rdef in x.rdefs.itervalues(): |
|
25 SCHEMA_EIDS[(rdef.subject, rdef.rtype, rdef.object)] = rdef.eid |
|
26 |
|
27 @classmethod |
|
28 def _refresh_repo(cls): |
|
29 super(SchemaModificationHooksTC, cls)._refresh_repo() |
|
30 # rebuild schema eid index |
|
31 schema = cls.repo.schema |
|
32 for x in schema.entities(): |
|
33 x.eid = SCHEMA_EIDS[x] |
|
34 schema._eid_index[x.eid] = x |
|
35 for x in cls.repo.schema.relations(): |
|
36 x.eid = SCHEMA_EIDS[x] |
|
37 schema._eid_index[x.eid] = x |
|
38 for rdef in x.rdefs.itervalues(): |
|
39 rdef.eid = SCHEMA_EIDS[(rdef.subject, rdef.rtype, rdef.object)] |
|
40 schema._eid_index[rdef.eid] = rdef |
16 |
41 |
17 def index_exists(self, etype, attr, unique=False): |
42 def index_exists(self, etype, attr, unique=False): |
18 self.session.set_pool() |
43 self.session.set_pool() |
19 dbhelper = self.session.pool.source('system').dbhelper |
44 dbhelper = self.session.pool.source('system').dbhelper |
20 sqlcursor = self.session.pool['system'] |
45 sqlcursor = self.session.pool['system'] |