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))
Esempio n. 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
Esempio n. 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
Esempio n. 5
0
 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'))
Esempio n. 6
0
 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))
Esempio n. 7
0
 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)
Esempio n. 8
0
 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))
Esempio n. 9
0
 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))
Esempio n. 10
0
 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))
Esempio n. 11
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))
Esempio n. 12
0
 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'))
Esempio n. 13
0
 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'))
Esempio n. 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()