Ejemplo n.º 1
0
def config(monkeypatch, tmpdir):
    """
    Injects nsone.Config instance.

    :param pytest.monkeypatch
    :param pytest.tmpdir
    :return: nsone.Config instance in which os.path.expanduser is \
        patched with '/tmp' subdir that is unique per test.
    """
    def mockreturn(path):
        tmp_cfg_path = str(tmpdir.join('nsone_test'))
        return tmp_cfg_path

    monkeypatch.setattr(os.path, 'expanduser', mockreturn)

    cfg = Config()
    return cfg
Ejemplo n.º 2
0
nsone = NSONE()

# to specify an apikey here instead, use:
nsone = NSONE(apiKey='qACMD09OJXBxT7XOuRs8')

# to load an alternate configuration file:
nsone = NSONE(configFile='/etc/nsone/api.json')

# to load a specific keyID inside of your config file (see config format
# in docs), use this. this only makes sense for config file loads, not
# apiKey loads:
nsone = NSONE(keyID='all-access')

# if you have special needs, build your own Config object and pass it to
# NSONE:
config = Config()
config.createFromAPIKey('qACMD09OJXBxT7XOwv9v')
config['verbosity'] = 5
config['transport'] = 'twisted'
nsone = NSONE(config=config)

#  you can get the current config object NSONE is using via
config = nsone.config

# change config variables
config['verbosity'] = 5

# write out new config files
config.write('/tmp/newconfig.json')

# the config file format supports different apiKeys (see docs) using keyID
Ejemplo n.º 3
0
 def _build_nsone(self):
     config = Config()
     config[self._transport_key] = self._transport
     config.createFromAPIKey(self._api_key)
     self._nsone = NSONE(config=config)
     return self._nsone