Ejemplo n.º 1
0
def test_handles_not_able_to_read_user(mocker, caplog):
    target = 'hdyndns.config.check_output'

    with pytest.raises(SystemExit):
        with mocker.patch(target, side_effect=OSError('foobar')):
            get_user()

    assert len(caplog.records) == 1
    assert caplog.records[0].levelname == 'CRITICAL'
    assert 'foobar' in caplog.records[0].message
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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'
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
def test_can_read_user():
    assert isinstance(get_user(), str)
Ejemplo n.º 7
0
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'))