def mockConfig(**configFields): """ Define database connections for code that needs mongo """ with mockDatabase() as db: try: cols = db.collection_names() docs = sum(db[c].count() for c in cols) assert docs == 0 from noms.config import Config cfg = Config(**configFields) cfg.save() from noms import secret secret.put('auth0', 'abc123', 'ABC!@#') # in tests, we replace the global CONFIG without patching it from noms import CONFIG CONFIG.load() yield CONFIG finally: # despite dropping the database we have to do this, because it's # still an object in memory cfg.delete() del CONFIG.__dict__['_realConfig']
def load(self): """ Initialize from the database """ from noms.config import Config cfg = Config.objects().first() assert cfg is not None, "Couldn't load a config from the database" self.__dict__["_realConfig"] = cfg return self