diff options
| author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-03 01:11:07 -0700 | 
|---|---|---|
| committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-03 01:11:07 -0700 | 
| commit | 491f9bdceef039ec641e6e77d0d1e7e5fef1e50b (patch) | |
| tree | da35910615e9ce53f0118b8f9b6b9352b8f61f66 | |
| parent | b36e37f9dad880f3071c6e65bce13e78988f3dba (diff) | |
| download | mitmproxy-491f9bdceef039ec641e6e77d0d1e7e5fef1e50b.tar.gz mitmproxy-491f9bdceef039ec641e6e77d0d1e7e5fef1e50b.tar.bz2 mitmproxy-491f9bdceef039ec641e6e77d0d1e7e5fef1e50b.zip | |
Add unit tests for console/help.py
| -rw-r--r-- | libmproxy/console/help.py | 25 | ||||
| -rw-r--r-- | libmproxy/proxy.py | 13 | ||||
| -rw-r--r-- | test/test_console_help.py | 25 | 
3 files changed, 44 insertions, 19 deletions
| diff --git a/libmproxy/console/help.py b/libmproxy/console/help.py index c75d2ae2..64428fcc 100644 --- a/libmproxy/console/help.py +++ b/libmproxy/console/help.py @@ -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) + + diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 912f3f31..92bdf5f4 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -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('.') diff --git a/test/test_console_help.py b/test/test_console_help.py new file mode 100644 index 00000000..e747635f --- /dev/null +++ b/test/test_console_help.py @@ -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() +] | 
