test_system.py: test for 'tahoe mv' with the http_proxy and HTTP_PROXY variables...
authordavid-sarah <david-sarah@jacaranda.org>
Wed, 10 Nov 2010 03:36:49 +0000 (19:36 -0800)
committerdavid-sarah <david-sarah@jacaranda.org>
Wed, 10 Nov 2010 03:36:49 +0000 (19:36 -0800)
src/allmydata/test/test_system.py

index 7ebafeb83026e04073b94d770f2422f8ccec9b31..f2770bba31a892338ea1bb799b4d929a2917f460 100644 (file)
@@ -4,6 +4,8 @@ from cStringIO import StringIO
 from twisted.trial import unittest
 from twisted.internet import defer
 from twisted.internet import threads # CLI tests use deferToThread
+from twisted.internet import utils
+
 import allmydata
 from allmydata import uri
 from allmydata.storage.mutable import MutableShareFile
@@ -29,6 +31,9 @@ from twisted.web.error import Error
 
 from allmydata.test.common import SystemTestMixin
 
+# TODO: move these to common or common_util
+from allmydata.test.test_runner import bintahoe, SkipMixin
+
 LARGE_DATA = """
 This is some data to publish to the remote grid.., which needs to be large
 enough to not fit inside a LIT uri.
@@ -47,7 +52,7 @@ class CountingDataUploadable(upload.Data):
                 self.interrupt_after_d.callback(self)
         return upload.Data.read(self, length)
 
-class SystemTest(SystemTestMixin, unittest.TestCase):
+class SystemTest(SystemTestMixin, SkipMixin, unittest.TestCase):
     timeout = 3600 # It takes longer than 960 seconds on Zandr's ARM box.
 
     def test_connections(self):
@@ -1589,9 +1594,23 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
         d.addCallback(_check_ls_rouri)
 
 
-        d.addCallback(run, "mv", "tahoe-file-stdin", "tahoe-moved")
+        d.addCallback(run, "mv", "tahoe-file-stdin", "tahoe-moved-first-time")
         d.addCallback(run, "ls")
-        d.addCallback(_check_ls, ["tahoe-moved"], ["tahoe-file-stdin"])
+        d.addCallback(_check_ls, ["tahoe-moved-first-time"], ["tahoe-file-stdin"])
+
+        def _mv_with_http_proxy(ign):
+            env = os.environ
+            env['http_proxy'] = env['HTTP_PROXY'] = "http://127.0.0.0:12345"  # invalid address
+            return self._run_cli_in_subprocess(["mv"] + nodeargs + ["tahoe-moved-first-time", "tahoe-moved"], env=env)
+        d.addCallback(_mv_with_http_proxy)
+
+        def _check_mv_with_http_proxy(res):
+            out, err, rc_or_sig = res
+            self.failUnlessEqual(rc_or_sig, 0, str(res))
+        d.addCallback(_check_mv_with_http_proxy)
+
+        d.addCallback(run, "ls")
+        d.addCallback(_check_ls, ["tahoe-moved"], ["tahoe-moved-firsttime"])
 
         d.addCallback(run, "ln", "tahoe-moved", "newlink")
         d.addCallback(run, "ls")
@@ -1745,6 +1764,15 @@ class SystemTest(SystemTestMixin, unittest.TestCase):
         d.addCallback(_done)
         return d
 
+    def _run_cli_in_subprocess(self, argv, env=None):
+        self.skip_if_cannot_run_bintahoe()
+
+        if env is None:
+            env = os.environ
+        d = utils.getProcessOutputAndValue(sys.executable, args=[bintahoe] + argv,
+                                           env=env)
+        return d
+
     def _test_checker(self, res):
         ut = upload.Data("too big to be literal" * 200, convergence=None)
         d = self._personal_node.add_file(u"big file", ut)