From: Brian Warner Date: Wed, 22 Oct 2008 00:52:56 +0000 (-0700) Subject: #514: improve test coverage X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/FOOURL?a=commitdiff_plain;h=0f7c1fd6fd89ddd3245101ceb3e45aed3718f50c;p=tahoe-lafs%2Ftahoe-lafs.git #514: improve test coverage --- diff --git a/src/allmydata/monitor.py b/src/allmydata/monitor.py index dad89b85..22de7713 100644 --- a/src/allmydata/monitor.py +++ b/src/allmydata/monitor.py @@ -100,21 +100,3 @@ class Monitor: return self.status def set_status(self, status): self.status = status - -class MonitorTable: - def __init__(self): - self.handles = {} # maps ophandle (an arbitrary string) to a Monitor - # TODO: all timeouts, handle lifetime, retain-for=, etc, goes here. - # self.handles should probably be a WeakValueDictionary, and we need - # a table of timers, and operations which have finished should be - # handled slightly differently. - - def get_monitor(self, handle): - return self.handles.get(handle) - - def add_monitor(self, handle, monitor): - self.handles[handle] = monitor - - def delete_monitor(self, handle): - if handle in self.handles: - del self.handles[handle] diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 695d9bfc..2b0c16fd 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -2150,6 +2150,21 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase): client.getPage, url, method="DELETE") return d + def test_bad_ophandle(self): + url = self.webish_url + "/operations/bogus?t=status" + d = self.shouldHTTPError2("test_bad_ophandle", 400, "400 Bad Request", + "unknown/expired handle 'bogus'", + client.getPage, url) + return d + + def test_incident(self): + d = self.POST("/report_incident", details="eek") + def _done(res): + self.failUnless("Thank you for your report!" in res, res) + d.addCallback(_done) + return d + + class Util(unittest.TestCase): def test_abbreviate_time(self): self.failUnlessEqual(common.abbreviate_time(None), "") diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index a1f33d30..79dcef39 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -721,10 +721,8 @@ class ManifestResults(rend.Page, ReloadMixin): def text(self, ctx): inevow.IRequest(ctx).setHeader("content-type", "text/plain") lines = [] - if self.monitor.is_finished(): - lines.append("finished: yes") - else: - lines.append("finished: no") + is_finished = self.monitor.is_finished() + lines.append("finished: " + {True: "yes", False: "no"}[is_finished]) for (path, cap) in self.monitor.get_status(): lines.append(self.slashify_path(path) + " " + cap) return "\n".join(lines) + "\n" @@ -773,15 +771,14 @@ class DeepSizeResults(rend.Page): if output == "json": return self.json(ctx) # plain text - if self.monitor.is_finished(): - output = "finished: true\n" + is_finished = self.monitor.is_finished() + output = "finished: " + {True: "yes", False: "no"}[is_finished] + "\n" + if is_finished: stats = self.monitor.get_status() total = (stats.get("size-immutable-files", 0) + stats.get("size-mutable-files", 0) + stats.get("size-directories", 0)) output += "size: %d\n" % total - else: - output = "finished: false\n" return output def json(self, ctx):