add an easy way to remove an entity type in test and then restore it
In our back-end tests of one project with have added an entity type (Thing
) for convenience. But in one test, we want to have the real schema (= without our added entity type for tests).
There is self.schema.del_entity_type("Thing")
that does the job and could be put in setUp
. But some other tests need the entity type. In consequence, we have to restore it (through tearDown
). self.schema.add_entity_type
could seem to do the job, but it takes yams_types.EntityType
and not str
.
It seems to be logic, because it can not add an entity type with only its name, as it is not anymore in self.schema
. In consequence, the entity type has to be stored as yams_types.EntityType
before removal and then given to self.schema.add_entity_type
. Unfortunately, CubicWeb is not fully typed, so it is not easy to find how to get the entity type as yams_types.EntityType
before the removal. Moreover, having to cache it is not handy.
In consequence, we propose 2 things:
- make
del_entity_type
returnsyams_types.EntityType
of the removed entity type instead of nothing- thanks to this the "no-operation"
self.schema.add_entity_type(self.schema.del_entity_type("Thing"))
would be possible
- thanks to this the "no-operation"
- add
restore_entity_type
that would only take a string as parameter likedel_entity_type
- its behavior could be to reload the schema in a dedicated variable (because multiple entity types may have been removed and only one or some of them may have to be restored), then get from it
yams_types.EntityType
from the given entity type name, and finally calladd_entity_type
with the result of the previous step
- its behavior could be to reload the schema in a dedicated variable (because multiple entity types may have been removed and only one or some of them may have to be restored), then get from it