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'
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
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'
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'
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'
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
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
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'
def test_resolve(fixture_dir): config = parse(fixture_dir('config.toml')) resolver = Resolver(config.get('resolver').get('providers'), Halo()) assert type(resolver) == Resolver
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())
def test_config_invalid_toml_syntax(fixture_dir): with pytest.raises(ConfigError, match=r'^Failed to parse .*'): parse(fixture_dir('invalid.toml'))
def test_config_path_not_exists(fixture_dir): with pytest.raises(RuntimeError, match=r'^Configuration file .*'): parse(fixture_dir('foo.toml'))