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