]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add test for webopen. fixes #1149
authordavid-sarah <david-sarah@jacaranda.org>
Sun, 24 Jul 2011 21:16:59 +0000 (14:16 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Sun, 24 Jul 2011 21:16:59 +0000 (14:16 -0700)
src/allmydata/test/test_cli.py

index 498064f997b21bf413af3d3746f3d850c68f4d20..2578658feefa06a6588b9db99ba63122e1fc6f56 100644 (file)
@@ -3080,3 +3080,39 @@ class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase):
             self.failUnlessReallyEqual(out, "")
         d.addCallback(_check)
         return d
+
+    def test_webopen(self):
+        # TODO: replace with @patch that supports Deferreds.
+        import webbrowser
+        def call_webbrowser_open(url):
+            self.failUnlessIn(self.alias_uri.replace(':', '%3A'), url)
+            self.webbrowser_open_called = True
+        def _cleanup(res):
+            webbrowser.open = self.old_webbrowser_open
+            return res
+
+        self.old_webbrowser_open = webbrowser.open
+        try:
+            webbrowser.open = call_webbrowser_open
+
+            self.basedir = "cli/Webopen/webopen"
+            self.set_up_grid()
+            d = self.do_cli("create-alias", "alias:")
+            def _check_alias((rc, out, err)):
+                self.failUnlessReallyEqual(rc, 0, repr((rc, out, err)))
+                self.failUnlessIn("Alias 'alias' created", out)
+                self.failUnlessReallyEqual(err, "")
+                self.alias_uri = get_aliases(self.get_clientdir())["alias"]
+            d.addCallback(_check_alias)
+            d.addCallback(lambda res: self.do_cli("webopen", "alias:"))
+            def _check_webopen((rc, out, err)):
+                self.failUnlessReallyEqual(rc, 0, repr((rc, out, err)))
+                self.failUnlessReallyEqual(out, "")
+                self.failUnlessReallyEqual(err, "")
+                self.failUnless(self.webbrowser_open_called)
+            d.addCallback(_check_webopen)
+            d.addBoth(_cleanup)
+        except:
+            _cleanup(None)
+            raise
+        return d