def test_save_overwrite(self, config_file_path):
     config = FileConfig(config_file_path=config_file_path)
     assert_that(config_file_path, is_not(equal_to('newtoken')))
     config.auth_token = 'newtoken'
     config.save()
     config_reloaded = FileConfig(config_file_path=config_file_path)
     assert_that(config_reloaded.auth_token, equal_to('newtoken'))
 def test_save(self, config_file_path):
     assert_that(path.isfile(config_file_path), is_(False))
     config = FileConfig(config_file_path=config_file_path)
     config.auth_token = 'brandnewtoken'
     config.save()
     config_reload = FileConfig(config_file_path=config_file_path)
     assert_that(path.isfile(config_file_path), is_(True))
     assert_that(config_reload.auth_token, equal_to(config.auth_token))
Exemple #3
0
def _get_instance(profile):
    instance = __instances.get(profile)
    if instance is None:
        config_param = (ChainedConfig() if profile == 'default' else
                        FileConfig(profile=profile))
        instance = DataDotWorld(config=config_param)
        __instances[profile] = instance
    return instance
Exemple #4
0
def _get_instance(profile, **kwargs):
    """

    :param profile:

    """
    instance = __instances.get(profile)

    if instance is None:
        config_param = (ChainedConfig(config_chain=[
            InlineConfig(kwargs.get('auth_token')),
            EnvConfig(),
            FileConfig()
        ]) if profile == 'default' else FileConfig(profile=profile))
        instance = DataDotWorld(config=config_param)
        __instances[profile] = instance
    return instance
 def test_save_overwrite(self, config_file_path):
     config = FileConfig(config_file_path=config_file_path)
     assert_that(config_file_path, is_not(equal_to('newtoken')))
     config.auth_token = 'newtoken'
     config.save()
     config_reloaded = FileConfig(config_file_path=config_file_path)
     assert_that(config_reloaded.auth_token, equal_to('newtoken'))
 def test_save(self, config_file_path):
     assert_that(path.isfile(config_file_path), is_(False))
     config = FileConfig(config_file_path=config_file_path)
     config.auth_token = 'brandnewtoken'
     config.save()
     config_reload = FileConfig(config_file_path=config_file_path)
     assert_that(path.isfile(config_file_path), is_(True))
     assert_that(config_reload.auth_token, equal_to(config.auth_token))
 def config_chain(self, monkeypatch, config_file_path):
     monkeypatch.setattr(os, 'environ', {'DW_CACHE_DIR': 'env_cache_dir'})
     chain = [EnvConfig(), FileConfig(config_file_path=config_file_path)]
     return ChainedConfig(config_chain=chain)
 def test_missing_token(self, config_file_path):
     assert_that(path.isfile(config_file_path), is_(True))
     config = FileConfig(profile='missingprofile',
                         config_file_path=config_file_path)
     assert_that(calling(lambda: config.auth_token), raises(RuntimeError))
 def test_missing_file_unsuitable_legacy_file(self, config_file_path):
     assert_that(path.isfile(config_file_path), is_(False))
     config = FileConfig(config_file_path=config_file_path)
     assert_that(calling(lambda: config.auth_token), raises(RuntimeError))
 def test_invalid_config_section(self, config_file_path):
     config = FileConfig(config_file_path=config_file_path)
     assert_that(config.auth_token, equal_to('lower_case_default'))
     assert_that(config._config_parser.sections(), has_length(0))
 def test_legacy_token(self, legacy_file_path, config_file_path):
     assert_that(path.isfile(config_file_path), is_(False))
     config = FileConfig(legacy_file_path=legacy_file_path,
                         config_file_path=config_file_path)
     assert_that(config.auth_token, equal_to('legacyabcd'))
     assert_that(path.isfile(config_file_path), is_(True))
 def test_alternative_token(self, config_file_path):
     config = FileConfig(profile='alternative',
                         config_file_path=config_file_path)
     assert_that(config.auth_token, equal_to('alternativeabcd'))
 def test_auth_token(self, config_file_path):
     config = FileConfig(config_file_path=config_file_path)
     assert_that(config.auth_token, equal_to('file_token'))
Exemple #14
0
def configure(obj, token):
    """Use this command to configure API tokens
    """
    config = obj.get('config') or FileConfig(obj['profile'])
    config.auth_token = token
    config.save()