Add unit tests for console/help.py

This commit is contained in:
Aldo Cortesi 2012-06-03 01:11:07 -07:00
parent b36e37f9da
commit 491f9bdcee
3 changed files with 44 additions and 19 deletions

View File

@ -31,18 +31,6 @@ class HelpView(urwid.ListBox):
self.helptext()
)
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "q":
self.master.statusbar = self.state[0]
self.master.body = self.state[1]
self.master.header = self.state[2]
self.master.make_view()
return None
elif key == "?":
key = None
return urwid.ListBox.keypress(self, size, key)
def helptext(self):
text = []
text.append(urwid.Text([("head", "Keys for this view:\n")]))
@ -174,3 +162,16 @@ class HelpView(urwid.ListBox):
text.extend(common.format_keyvals(examples, key="key", val="text", indent=4))
return text
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "q":
self.master.statusbar = self.state[0]
self.master.body = self.state[1]
self.master.header = self.state[2]
self.master.make_view()
return None
elif key == "?":
key = None
return urwid.ListBox.keypress(self, size, key)

View File

@ -146,14 +146,13 @@ def parse_request_line(request):
except ValueError:
raise ProxyError(400, "Can't parse request")
port = int(port)
else:
if url.startswith("/") or url == "*":
elif url.startswith("/") or url == "*":
scheme, port, host, path = None, None, None, url
else:
parts = utils.parse_url(url)
if not parts:
raise ProxyError(400, "Invalid url: %s"%url)
scheme, host, port, path = parts
else:
parts = utils.parse_url(url)
if not parts:
raise ProxyError(400, "Invalid url: %s"%url)
scheme, host, port, path = parts
if not protocol.startswith("HTTP/"):
raise ProxyError(400, "Unsupported protocol")
major,minor = protocol.split('/')[1].split('.')

25
test/test_console_help.py Normal file
View File

@ -0,0 +1,25 @@
import sys
import libpry
import libmproxy.console.help as help
from libmproxy import utils, flow, encoding
class DummyMaster:
def make_view(self):
pass
class uHelp(libpry.AutoTree):
def test_helptext(self):
h = help.HelpView(None, "foo", None)
assert h.helptext()
def test_keypress(self):
h = help.HelpView(DummyMaster(), "foo", [1, 2, 3])
assert not h.keypress((0, 0), "q")
assert not h.keypress((0, 0), "?")
assert h.keypress((0, 0), "o") == "o"
tests = [
uHelp()
]