コード例 #1
0
ファイル: test_config.py プロジェクト: asplunden/giu
def test_config(fixture_dir):
    config = parse(fixture_dir('config.toml'))

    assert 'dns' in config
    assert 'api' in config
    assert type(config['api']) == Table
    assert config['api']['url'] == 'https://dns.api.gandi.net/api/v5'
コード例 #2
0
def test_resolve_no_providers(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    resolver = Resolver(config.get('resolver').get('providers'), Halo())
    resolver._providers = []

    with pytest.raises(ResolverError):
        resolver.ip
コード例 #3
0
def test_config(fixture_dir):
    config = parse(fixture_dir('config.toml'))

    assert 'dns' in config
    assert 'api' in config
    assert type(config['api']) == Table
    assert config.get('api').get('url') == 'https://api.gandi.net/v5/livedns'
コード例 #4
0
def test_resolve_ip_request_mock(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    resolver = Resolver(config.get('resolver').get('providers'), Halo())

    with requests_mock.Mocker(real_http=True) as m:
        m.get('https://ifconfig.me/ip', text='127.0.0.1')

        assert resolver.ip == '127.0.0.1'
コード例 #5
0
def test_resolve_ip_request_mock(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    resolver = Resolver(config['resolver']['providers'], Halo())

    with requests_mock.Mocker(real_http=True) as m:
        m.register_uri('GET', 'https://ifconfig.me/ip', text='127.0.0.1')

        assert resolver.ip == '127.0.0.1'
コード例 #6
0
def test_resolve_ip_timeout(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    resolver = Resolver(config.get('resolver').get('providers'), Halo())

    with requests_mock.Mocker(real_http=True) as m:
        m.get('https://ifconfig.me/ip', exc=Timeout)

        with pytest.raises(ResolverError,
                           match='all provider failed or timeout'):
            resolver.ip
コード例 #7
0
def test_resolve_wrong_ip(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    resolver = Resolver(config['resolver']['providers'], Halo())

    with requests_mock.Mocker(real_http=True) as m:
        m.register_uri('GET', 'https://ifconfig.me/ip', text='not valid ip')

        with pytest.raises(ResolverError,
                           match='all provider failed or timeout'):
            resolver.ip
コード例 #8
0
def test_resolve_ip(fixture_dir):
    with mock.patch.object(Resolver, 'ip', '127.0.0.1'):
        config = parse(fixture_dir('config.toml'))
        resolver = Resolver(config.get('resolver').get('providers'), Halo())

        assert resolver.ip == '127.0.0.1'
コード例 #9
0
def test_resolve(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    resolver = Resolver(config.get('resolver').get('providers'), Halo())

    assert type(resolver) == Resolver
コード例 #10
0
def test_resolve_empty_provider_list(fixture_dir):
    config = parse(fixture_dir('config.toml'))
    config.get('resolver')['providers'] = []

    with pytest.raises(ResolverError, match=r'^the list of providers .*'):
        Resolver(config.get('resolver').get('providers'), Halo())
コード例 #11
0
ファイル: test_config.py プロジェクト: asplunden/giu
def test_config_invalid_toml_syntax(fixture_dir):
    with pytest.raises(ConfigError, match=r'^Failed to parse .*'):
        parse(fixture_dir('invalid.toml'))
コード例 #12
0
ファイル: test_config.py プロジェクト: asplunden/giu
def test_config_path_not_exists(fixture_dir):
    with pytest.raises(RuntimeError, match=r'^Configuration file .*'):
        parse(fixture_dir('foo.toml'))