def get_owner(self): """Return the owner object of the proper type.""" ent = Entity(self._db) ent.find(self.owner_entity_id) if ent.entity_type == self.const.entity_voip_service: result = VoipService(self._db) result.find(self.owner_entity_id) return result ent.clear() return ent.get_subclassed_object(self.owner_entity_id)
def test_get_subclassed_object(database, factory, Entity, entity_type): from Cerebrum.Entity import Entity as BaseEntity if Entity == BaseEntity: pytest.skip("Cannot test subclassed object with base class") # patch class into factory class cache factory_name = 'e3dc9cb2d58bdbda' factory.class_cache[factory_name] = Entity factory.type_component_map[str(entity_type)] = factory_name # Make entity of entity_type base = BaseEntity(database) base.populate(entity_type) base.write_db() # test entity = base.get_subclassed_object() assert type(entity) != type(base) assert type(entity) == Entity