From: david-sarah Date: Sun, 24 Jul 2011 21:16:59 +0000 (-0700) Subject: Add test for webopen. fixes #1149 X-Git-Tag: pre-393~22 X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/somewhere?a=commitdiff_plain;h=6c2670641e26e8ca06d6a7fcc7f32a4222d756ef;p=tahoe-lafs%2Ftahoe-lafs.git Add test for webopen. fixes #1149 --- diff --git a/src/allmydata/test/test_cli.py b/src/allmydata/test/test_cli.py index 498064f9..2578658f 100644 --- a/src/allmydata/test/test_cli.py +++ b/src/allmydata/test/test_cli.py @@ -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