Пример #1
0
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"
Пример #2
0
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"
Пример #3
0
 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
Пример #4
0
 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
Пример #5
0
 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)
Пример #7
0
def test_default_loop_for_default_resolver(loop):
    asyncio.set_event_loop(loop)
    resolver = DefaultResolver()
    assert resolver._loop is loop
Пример #8
0
def test_close_for_default_resolver(loop):
    resolver = DefaultResolver(loop=loop)
    yield from resolver.close()
Пример #9
0
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')
Пример #10
0
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'])
Пример #11
0
 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'])
Пример #12
0
def test_close_for_default_resolver(loop):
    resolver = DefaultResolver(loop=loop)
    yield from resolver.close()
Пример #13
0
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')
Пример #14
0
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'])
Пример #15
0
 def __init__(self, fakes, loop: asyncio.AbstractEventLoop):
     """fakes -- dns -> port dict"""
     self._fakes = fakes
     self._resolver = DefaultResolver(loop=loop)
Пример #16
0
 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'])