aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHenrique <typoon@gmail.com>2019-11-16 20:14:38 -0500
committerHenrique <typoon@gmail.com>2019-11-16 20:14:38 -0500
commit13fe07f48f4fa191b8596aa94cbe743a3c3344fa (patch)
tree5dab104809e3d86e3c1ef4e9fefc10ca3d9eb9c8 /test
parent7779eef572e8deeae895ea6d700265e6f9b432c8 (diff)
downloadmitmproxy-13fe07f48f4fa191b8596aa94cbe743a3c3344fa.tar.gz
mitmproxy-13fe07f48f4fa191b8596aa94cbe743a3c3344fa.tar.bz2
mitmproxy-13fe07f48f4fa191b8596aa94cbe743a3c3344fa.zip
Brought coverage up to 94% on test_commander.py
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/tools/console/test_commander.py107
1 files changed, 103 insertions, 4 deletions
diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py
index 8c3e6839..9a2ec102 100644
--- a/test/mitmproxy/tools/console/test_commander.py
+++ b/test/mitmproxy/tools/console/test_commander.py
@@ -39,6 +39,100 @@ class TestCommandEdit:
except IndexError:
pytest.faied("Unexpected IndexError")
+ def test_insert(self):
+ with taddons.context() as tctx:
+ history = commander.CommandHistory(tctx.master, size=3)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ edit.keypress(1, 'a')
+ assert edit.get_edit_text() == 'a'
+
+ # Don't let users type a space before starting a command
+ # as a usability feature
+ history = commander.CommandHistory(tctx.master, size=3)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ edit.keypress(1, ' ')
+ assert edit.get_edit_text() == ''
+
+ def test_backspace(self):
+ with taddons.context() as tctx:
+ history = commander.CommandHistory(tctx.master, size=3)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ edit.keypress(1, 'a')
+ edit.keypress(1, 'b')
+ assert edit.get_edit_text() == 'ab'
+ edit.keypress(1, 'backspace')
+ assert edit.get_edit_text() == 'a'
+
+ def test_left(self):
+ with taddons.context() as tctx:
+ history = commander.CommandHistory(tctx.master, size=3)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ edit.keypress(1, 'a')
+ assert edit.cbuf.cursor == 1
+ edit.keypress(1, 'left')
+ assert edit.cbuf.cursor == 0
+
+ # Do it again to make sure it won't go negative
+ edit.keypress(1, 'left')
+ assert edit.cbuf.cursor == 0
+
+ def test_right(self):
+ with taddons.context() as tctx:
+ history = commander.CommandHistory(tctx.master, size=3)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ edit.keypress(1, 'a')
+ assert edit.cbuf.cursor == 1
+
+ # Make sure cursor won't go past the text
+ edit.keypress(1, 'right')
+ assert edit.cbuf.cursor == 1
+
+ # Make sure cursor goes left and then back right
+ edit.keypress(1, 'left')
+ assert edit.cbuf.cursor == 0
+ edit.keypress(1, 'right')
+ assert edit.cbuf.cursor == 1
+
+ def test_up_and_down(self):
+ with taddons.context() as tctx:
+ history = commander.CommandHistory(tctx.master, size=3)
+ edit = commander.CommandEdit(tctx.master, '', history)
+
+ buf = commander.CommandBuffer(tctx.master, 'cmd1')
+ history.add_command(buf)
+ buf = commander.CommandBuffer(tctx.master, 'cmd2')
+ history.add_command(buf)
+
+ edit.keypress(1, 'up')
+ assert edit.get_edit_text() == 'cmd2'
+ edit.keypress(1, 'up')
+ assert edit.get_edit_text() == 'cmd1'
+ edit.keypress(1, 'up')
+ assert edit.get_edit_text() == 'cmd1'
+
+ history = commander.CommandHistory(tctx.master, size=5)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ edit.keypress(1, 'a')
+ edit.keypress(1, 'b')
+ edit.keypress(1, 'c')
+ assert edit.get_edit_text() == 'abc'
+ edit.keypress(1, 'up')
+ assert edit.get_edit_text() == ''
+ edit.keypress(1, 'down')
+ assert edit.get_edit_text() == 'abc'
+ edit.keypress(1, 'down')
+ assert edit.get_edit_text() == 'abc'
+
+ history = commander.CommandHistory(tctx.master, size=5)
+ edit = commander.CommandEdit(tctx.master, '', history)
+ buf = commander.CommandBuffer(tctx.master, 'cmd3')
+ history.add_command(buf)
+ edit.keypress(1, 'z')
+ edit.keypress(1, 'up')
+ assert edit.get_edit_text() == 'cmd3'
+ edit.keypress(1, 'down')
+ assert edit.get_edit_text() == 'z'
+
class TestCommandHistory:
def fill_history(self, commands):
@@ -160,6 +254,15 @@ class TestCommandBuffer:
cb.cursor = len(cb.text)
cb.cycle_completion()
+ ch = commander.CommandHistory(tctx.master, 30)
+ ce = commander.CommandEdit(tctx.master, "se", ch)
+ ce.keypress(1, 'tab')
+ ce.update()
+ ret = ce.cbuf.render()
+ assert ret[0] == ('commander_command', 'set')
+ assert ret[1] == ('text', ' ')
+ assert ret[2] == ('commander_hint', 'str ')
+
def test_render(self):
with taddons.context() as tctx:
cb = commander.CommandBuffer(tctx.master)
@@ -179,7 +282,3 @@ class TestCommandBuffer:
assert ret[0] == ('commander_command', 'set')
assert ret[1] == ('text', ' ')
assert ret[2] == ('commander_hint', 'str ')
-
- # import pdb
- # pdb.set_trace()
- # print('x')