]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/test/test_node.py
Eliminate mock dependency.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_node.py
index cf7d0f57d222cf6d43ae8d50ee55a3c9d8e68b46..05c00bcec25f8e245c32427c86ea1897705c2523 100644 (file)
@@ -1,17 +1,20 @@
 
 import os, stat, sys, time
+
 from twisted.trial import unittest
 from twisted.internet import defer
 from twisted.python import log
 
-from mock import patch
-
 from foolscap.api import flushEventualQueue
+import foolscap.logging.log
+
 from twisted.application import service
 from allmydata.node import Node, formatTimeTahoeStyle, MissingConfigEntry
-from allmydata.util import fileutil
+from allmydata.util import fileutil, iputil
+from allmydata.util.namespace import Namespace
 import allmydata.test.common_util as testutil
 
+
 class LoggingMultiService(service.MultiService):
     def log(self, msg, **kw):
         pass
@@ -33,7 +36,7 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
         d.addCallback(flushEventualQueue)
         return d
 
-    def _test_location(self, basedir, expected_addresses, tub_port=None, tub_location=None):
+    def _test_location(self, basedir, expected_addresses, tub_port=None, tub_location=None, local_addresses=None):
         fileutil.make_dirs(basedir)
         f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt')
         f.write("[node]\n")
@@ -43,6 +46,9 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
             f.write("tub.location = %s\n" % (tub_location,))
         f.close()
 
+        if local_addresses:
+            self.patch(iputil, 'get_local_addresses_async', lambda target=None: defer.succeed(local_addresses))
+
         n = TestNode(basedir)
         n.setServiceParent(self.parent)
         d = n.when_tub_ready()
@@ -65,6 +71,20 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
                                    expected_addresses=["192.0.2.0:1234", "example.org:8091"],
                                    tub_location="192.0.2.0:1234,example.org:8091")
 
+    def test_location_not_set(self):
+        """Checks the autogenerated furl when tub.location is not set."""
+        return self._test_location(basedir="test_node/test_location3",
+                                   expected_addresses=["127.0.0.1:1234", "192.0.2.0:1234"],
+                                   tub_port=1234,
+                                   local_addresses=["127.0.0.1", "192.0.2.0"])
+
+    def test_location_auto_and_explicit(self):
+        """Checks the autogenerated furl when tub.location contains 'AUTO'."""
+        return self._test_location(basedir="test_node/test_location4",
+                                   expected_addresses=["127.0.0.1:1234", "192.0.2.0:1234", "example.com:4321"],
+                                   tub_port=1234,
+                                   tub_location="AUTO,example.com:4321",
+                                   local_addresses=["127.0.0.1", "192.0.2.0", "example.com:4321"])
 
     def test_tahoe_cfg_utf8(self):
         basedir = "test_node/test_tahoe_cfg_utf8"
@@ -152,14 +172,16 @@ class TestCase(testutil.SignalMixin, unittest.TestCase):
         bits = stat.S_IMODE(st[stat.ST_MODE])
         self.failUnless(bits & 0001 == 0, bits)
 
-    @patch("foolscap.logging.log.setLogDir")
-    def test_logdir_is_str(self, mock_setLogDir):
+    def test_logdir_is_str(self):
         basedir = "test_node/test_logdir_is_str"
         fileutil.make_dirs(basedir)
 
+        ns = Namespace()
+        ns.called = False
         def call_setLogDir(logdir):
+            ns.called = True
             self.failUnless(isinstance(logdir, str), logdir)
-        mock_setLogDir.side_effect = call_setLogDir
+        self.patch(foolscap.logging.log, 'setLogDir', call_setLogDir)
 
         TestNode(basedir)
-        self.failUnless(mock_setLogDir.called)
+        self.failUnless(ns.called)