示例#1
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['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
def test_config_invalid_toml_syntax(fixture_dir):
    with pytest.raises(ConfigError, match=r'^Failed to parse .*'):
        parse(fixture_dir('invalid.toml'))
示例#12
0
def test_config_path_not_exists(fixture_dir):
    with pytest.raises(RuntimeError, match=r'^Configuration file .*'):
        parse(fixture_dir('foo.toml'))