def test_default_resolver_multiple_replies(loop): ips = ['127.0.0.1', '127.0.0.2', '127.0.0.3', '127.0.0.4'] loop.getaddrinfo = fake_addrinfo(ips) resolver = DefaultResolver(loop=loop) real = yield from resolver.resolve('www.google.com') ips = [ipaddress.ip_address(x['host']) for x in real] assert len(ips) > 3, "Expecting multiple addresses"
def go(): ips = [] loop.getaddrinfo = fake_addrinfo(ips) resolver = DefaultResolver(loop=loop) try: yield from resolver.resolve('doesnotexist.bla') assert False, "Expecting socket.gaierror" except socket.gaierror: pass
def __init__(self, fakes: Dict[str, int], *, loop: Optional[AbstractEventLoop] = None) -> None: """fakes -- dns -> port dict""" loop = loop or get_event_loop() self._fakes = fakes self._resolver = DefaultResolver(loop=loop)
def __init__(self, fakes, *, loop): """fakes -- dns -> port dict""" self._fakes = fakes self._resolver = DefaultResolver(loop=loop)
def test_default_loop_for_default_resolver(loop): asyncio.set_event_loop(loop) resolver = DefaultResolver() assert resolver._loop is loop
def test_close_for_default_resolver(loop): resolver = DefaultResolver(loop=loop) yield from resolver.close()
def test_default_negative_lookup(loop): ips = [] loop.getaddrinfo = fake_addrinfo(ips) resolver = DefaultResolver(loop=loop) with pytest.raises(socket.gaierror): yield from resolver.resolve('doesnotexist.bla')
def test_default_resolver_positive_lookup(loop): loop.getaddrinfo = fake_addrinfo(["127.0.0.1"]) resolver = DefaultResolver(loop=loop) real = yield from resolver.resolve('www.python.org') ipaddress.ip_address(real[0]['host'])
def go(): loop.getaddrinfo = fake_addrinfo(["127.0.0.1"]) resolver = DefaultResolver(loop=loop) real = yield from resolver.resolve('www.python.org') ipaddress.ip_address(real[0]['host'])
def __init__(self, fakes, loop: asyncio.AbstractEventLoop): """fakes -- dns -> port dict""" self._fakes = fakes self._resolver = DefaultResolver(loop=loop)