def test_handles_missing_config(caplog): with TemporaryDirectory() as temp_dir: user = get_user() create_home(user, root=temp_dir) with pytest.raises(SystemExit): read_config(user, root=temp_dir) assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'CRITICAL' assert 'Missing configuration' in caplog.records[0].message
def test_reads_config_correctly(): with TemporaryDirectory() as temp_dir: user = get_user() create_home(user, root=temp_dir) cfg_path = join(temp_dir, user, '.hdyndns', 'hdyndns.ini') with open(cfg_path, 'w+') as handle: handle.write('[foo.bar]\nprovider=baz') config = read_config(user, root=temp_dir) assert config is not [] assert config.sections() == ['foo.bar'] assert config['foo.bar']['provider'] == 'baz'
def test_bails_out_missing_api_secret(caplog): with TemporaryDirectory() as temp_dir: user = get_user() create_home(user, root=temp_dir) cfg_path = join(temp_dir, user, '.hdyndns', 'hdyndns.ini') with open(cfg_path, 'w+') as handle: handle.write('[bar.foo]\nprovider=gandi') config = read_config(user, root=temp_dir) with pytest.raises(SystemExit): sections = filter(lambda s: s != 'DEFAULT', config.keys()) validate_api_secrets(config, sections) assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'CRITICAL' assert 'No api_secret' in caplog.records[0].message
def cli_entrypoint() -> None: """The command line entrypoint.""" user = get_user() create_home(user) config = read_config(user) sections = [section for section in config.keys() if section != 'DEFAULT'] validate_dns_providers(config, sections) validate_api_secrets(config, sections) for section in sections: if 'gandi' == config[section]['provider']: logger.info('Processing {} with provider Gandi'.format(section)) GandiDynDNS(config[section]).update_dns() exit(EXIT_CODE_0_OK) else: logger.critical('No supported provider found') exit(EXIT_CODE_1_BAD)
def test_does_not_re_create_home_path(): with TemporaryDirectory() as temp_dir: user = get_user() create_home(user, root=temp_dir) create_home(user, root=temp_dir) assert exists(join(temp_dir, user, '.hdyndns'))