Guest User

Untitled

a guest
Jul 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. diff --git a/src/allmydata/test/test_node.py b/src/allmydata/test/test_node.py
  2. index 24ec571..f3d9f6c 100644
  3. --- a/src/allmydata/test/test_node.py
  4. +++ b/src/allmydata/test/test_node.py
  5. @@ -7,7 +7,7 @@ from twisted.python import log
  6. from foolscap.api import flushEventualQueue
  7. from twisted.application import service
  8. from allmydata.node import Node, formatTimeTahoeStyle
  9. -from allmydata.util import fileutil
  10. +from allmydata.util import fileutil, iputil
  11. import allmydata.test.common_util as testutil
  12.  
  13. class LoggingMultiService(service.MultiService):
  14. @@ -31,6 +31,36 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
  15. d.addCallback(flushEventualQueue)
  16. return d
  17.  
  18. + def _mock_get_local_addresses_async(self):
  19. + self._get_local_addresses_async = iputil.get_local_addresses_async
  20. + iputil.get_local_addresses_async = lambda : ["1.2.3.4"]
  21. +
  22. + def _unmock_get_local_addresses_async(self):
  23. + iputil.get_local_addresses_async = self._get_local_addresses_async
  24. +
  25. + def test_anonymous_location(self):
  26. + self._mock_get_local_addresses_async()
  27. +
  28. + basedir = "test_node/test_anonymous_location"
  29. + fileutil.make_dirs(basedir)
  30. + f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt')
  31. + f.write("[node]\n")
  32. + f.write("tub.location = \n")
  33. + f.close()
  34. +
  35. + n = TestNode(basedir)
  36. + n.setServiceParent(self.parent)
  37. + d = n.when_tub_ready()
  38. +
  39. + def _check_addresses(ignored_result):
  40. + furl = n.tub.registerReference(n)
  41. + self.failIf("1.2.3.4" in furl, furl)
  42. + self.failUnless("127.0.0.1" in furl, furl)
  43. +
  44. + d.addCallback(_check_addresses)
  45. + d.addCallback(lambda res: self._unmock_get_local_addresses_async())
  46. + return d
  47. +
  48. def test_location(self):
  49. basedir = "test_node/test_location"
  50. fileutil.make_dirs(basedir)
Add Comment
Please, Sign In to add comment