aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMiroslav <ttahabatt@gmail.com>2018-07-19 16:56:34 +0300
committerMiroslav <ttahabatt@gmail.com>2018-07-19 16:56:34 +0300
commitdcb3de40b12bafd07979052647e71a172d55b360 (patch)
tree0b98fac9ed0c51d406999e24a5d85864938e76c6 /test
parentffbd7c20e56ad65dc93de93129344a6e51d79344 (diff)
downloadmitmproxy-dcb3de40b12bafd07979052647e71a172d55b360.tar.gz
mitmproxy-dcb3de40b12bafd07979052647e71a172d55b360.tar.bz2
mitmproxy-dcb3de40b12bafd07979052647e71a172d55b360.zip
Some refactoring. New test case.
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/tools/console/test_commander.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/test/mitmproxy/tools/console/test_commander.py b/test/mitmproxy/tools/console/test_commander.py
index d9daa673..b5e226fe 100644
--- a/test/mitmproxy/tools/console/test_commander.py
+++ b/test/mitmproxy/tools/console/test_commander.py
@@ -41,20 +41,31 @@ class TestCommandHistory:
commands = ["command1", "command2"]
history, tctx_master = self.fill_history(commands)
- history_commands = [buf.text for buf in history.history]
- assert history_commands == [""] + commands
+ saved_commands = [buf.text for buf in history.saved_commands]
+ assert saved_commands == [""] + commands
- # The history size is only 3. So, we forget the first one command,
- # when adding fourth command
+ # The history size is only 3. So, we forget the first
+ # one command, when adding fourth command
cbuf = commander.CommandBuffer(tctx_master, "command3")
history.add_command(cbuf)
- history_commands = [buf.text for buf in history.history]
- assert history_commands == commands + ["command3"]
+ saved_commands = [buf.text for buf in history.saved_commands]
+ assert saved_commands == commands + ["command3"]
# Commands with the same text are not repeated in the history one by one
history.add_command(cbuf)
- history_commands = [buf.text for buf in history.history]
- assert history_commands == commands + ["command3"]
+ saved_commands = [buf.text for buf in history.saved_commands]
+ assert saved_commands == commands + ["command3"]
+
+ # adding command in execution mode sets index at the beginning of the history
+ # and replace the last command buffer if it is empty or has the same text
+ cbuf = commander.CommandBuffer(tctx_master, "")
+ history.add_command(cbuf)
+ history.index = 0
+ cbuf = commander.CommandBuffer(tctx_master, "command4")
+ history.add_command(cbuf, True)
+ assert history.index == history.last_index
+ saved_commands = [buf.text for buf in history.saved_commands]
+ assert saved_commands == ["command2", "command3", "command4"]
def test_get_next(self):
commands = ["command1", "command2"]