2007-04-18 17:30:08 -07:00
|
|
|
|
2007-04-18 18:33:37 -07:00
|
|
|
import re
|
2008-10-28 21:28:31 -07:00
|
|
|
from twisted.trial import unittest
|
|
|
|
from allmydata.util import iputil
|
|
|
|
import common_util as testutil
|
2007-04-18 17:30:08 -07:00
|
|
|
|
|
|
|
DOTTED_QUAD_RE=re.compile("^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$")
|
2007-03-07 18:22:30 -07:00
|
|
|
|
2007-04-23 21:15:02 -07:00
|
|
|
class ListAddresses(testutil.SignalMixin, unittest.TestCase):
|
2007-04-18 17:30:08 -07:00
|
|
|
def test_get_local_ip_for(self):
|
|
|
|
addr = iputil.get_local_ip_for('127.0.0.1')
|
|
|
|
self.failUnless(DOTTED_QUAD_RE.match(addr))
|
|
|
|
|
2007-03-07 18:43:17 -07:00
|
|
|
def test_list_async(self):
|
|
|
|
d = iputil.get_local_addresses_async()
|
2007-03-07 18:22:30 -07:00
|
|
|
def _check(addresses):
|
|
|
|
self.failUnless(len(addresses) >= 1) # always have localhost
|
2007-04-18 17:30:08 -07:00
|
|
|
self.failUnless("127.0.0.1" in addresses, addresses)
|
2007-10-13 00:38:16 -07:00
|
|
|
self.failIf("0.0.0.0" in addresses, addresses)
|
2007-03-07 18:22:30 -07:00
|
|
|
d.addCallbacks(_check)
|
|
|
|
return d
|
2007-04-18 17:30:08 -07:00
|
|
|
test_list_async.timeout=2
|