Beispiel #1
0
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']
Beispiel #2
0
    def postOptions(self):
        """
        Connect to the noms database and make sure a config exists
        """
        alias = self['alias']
        assert alias in DBAlias
        connect(**DBHost[alias])
        CONFIG.load()
        
        # now we know CONFIG exists
        CONFIG.cliOptions = dict(self.items())
        CONFIG.save()

        self.opt_class(MAIN_FUNC)

        return tap.Options.postOptions(self)