#514: improve test coverage

This commit is contained in:
Brian Warner 2008-10-21 17:52:56 -07:00
parent ad3d9207a9
commit 0f7c1fd6fd
3 changed files with 20 additions and 26 deletions

View File

@ -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]

View File

@ -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), "")

View File

@ -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):