Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'peeringdb': {
'url': 'https://test.peeringdb.com/api',
'timeout': 10,
}
}
assert config.detect_old(old_part)
# empty case
assert not config.detect_old({})
# Test conversion
conv_data = config.convert_old(old_data)
assert config.CLIENT_SCHEMA.validate(conv_data)
assert not config.detect_old(conv_data)
assert conv_data == new_data
conv_part = config.convert_old(old_part)
assert config.CLIENT_SCHEMA.validate(conv_part)
# Test detection
assert config.detect_old(old_data)
assert not config.detect_old(new_data)
# Try partial data
old_part = {
'peeringdb': {
'url': 'https://test.peeringdb.com/api',
'timeout': 10,
}
}
assert config.detect_old(old_part)
# empty case
assert not config.detect_old({})
# Test conversion
conv_data = config.convert_old(old_data)
assert config.CLIENT_SCHEMA.validate(conv_data)
assert not config.detect_old(conv_data)
assert conv_data == new_data
conv_part = config.convert_old(old_part)
assert config.CLIENT_SCHEMA.validate(conv_part)
def check_load_config(config_dir):
convert = False
loaded = config.read_config(config_dir) or {}
if config.detect_old(loaded):
print(
"Found config file with pre-0.7 schema; backing up and converting to new format"
)
convert = True
cfg = config.convert_old(loaded)
else:
cfg = config.default_config()
config.recursive_update(cfg, loaded)
if convert:
config.write_config(cfg, config_dir, backup_existing=True)
return cfg