def _initialize(self): if not is_engine_initialized(self.name): engine = self.__make_engine() set_engine(self.name, engine) else: engine = get_engine(self.name) db_name = self._config['db_name'] self.__db = operator.getitem(engine, db_name) if db_name == 'test': # Reset the test database. for coll_name in \ self.__db.collection_names(include_system_collections=False): self.__db.drop_collection(coll_name) # Set up the class registry. for rc in self.registered_resources: ent_cls = get_entity_class(rc) if not MongoClassRegistry.is_registered(ent_cls): MongoClassRegistry.register(ent_cls, self.__db)
def test_register_unregister(self): class Foo(object): pass assert isinstance(MyEntity.parent, MongoInstrumentedAttribute) with pytest.raises(ValueError): MongoClassRegistry.unregister(Foo) assert MongoClassRegistry.is_registered(MyEntity) # Registering a registered class raises a ValueError. with pytest.raises(ValueError): MongoClassRegistry.register(MyEntity, None) MongoClassRegistry.unregister(MyEntity) assert not MongoClassRegistry.is_registered(MyEntity)
def tear_down(): MongoClassRegistry.unregister_all()