aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-05-01 09:58:54 +1200
committerAldo Cortesi <aldo@corte.si>2018-05-02 08:36:15 +1200
commit00d790fe84ec860f1de46330cda0e73884e07e2f (patch)
treeef584911a53eb08564710fa6ca2c1349166a1e98 /test
parent09c36a8c7c8e5bd690c605e2097063b278489b66 (diff)
downloadmitmproxy-00d790fe84ec860f1de46330cda0e73884e07e2f.tar.gz
mitmproxy-00d790fe84ec860f1de46330cda0e73884e07e2f.tar.bz2
mitmproxy-00d790fe84ec860f1de46330cda0e73884e07e2f.zip
commands: clarify command call interface, fix web app replay
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_save.py2
-rw-r--r--test/mitmproxy/test_addonmanager.py2
-rw-r--r--test/mitmproxy/test_command.py19
-rw-r--r--test/mitmproxy/tools/web/test_app.py13
4 files changed, 17 insertions, 19 deletions
diff --git a/test/mitmproxy/addons/test_save.py b/test/mitmproxy/addons/test_save.py
index 616caf58..4aa1f648 100644
--- a/test/mitmproxy/addons/test_save.py
+++ b/test/mitmproxy/addons/test_save.py
@@ -73,7 +73,7 @@ def test_save_command(tmpdir):
v = view.View()
tctx.master.addons.add(v)
tctx.master.addons.add(sa)
- tctx.master.commands.call_args("save.file", ["@shown", p])
+ tctx.master.commands.call_strings("save.file", ["@shown", p])
def test_simple(tmpdir):
diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py
index 796ae1bd..1ef1521d 100644
--- a/test/mitmproxy/test_addonmanager.py
+++ b/test/mitmproxy/test_addonmanager.py
@@ -47,7 +47,7 @@ class AOption:
def test_command():
with taddons.context() as tctx:
tctx.master.addons.add(TAddon("test"))
- assert tctx.master.commands.call("test.command") == "here"
+ assert tctx.master.commands.execute("test.command") == "here"
def test_halt():
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index 3d0a43f8..ea1017e7 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -242,16 +242,19 @@ def test_simple():
a = TAddon()
c.add("one.two", a.cmd1)
assert c.commands["one.two"].help == "cmd1 help"
- assert(c.call("one.two foo") == "ret foo")
+ assert(c.execute("one.two foo") == "ret foo")
+ assert(c.call("one.two", "foo") == "ret foo")
with pytest.raises(exceptions.CommandError, match="Unknown"):
- c.call("nonexistent")
+ c.execute("nonexistent")
with pytest.raises(exceptions.CommandError, match="Invalid"):
- c.call("")
+ c.execute("")
with pytest.raises(exceptions.CommandError, match="argument mismatch"):
- c.call("one.two too many args")
+ c.execute("one.two too many args")
+ with pytest.raises(exceptions.CommandError, match="Unknown"):
+ c.call("nonexistent")
c.add("empty", a.empty)
- c.call("empty")
+ c.execute("empty")
fp = io.StringIO()
c.dump(fp)
@@ -340,13 +343,13 @@ def test_decorator():
a = TDec()
c.collect_commands(a)
assert "cmd1" in c.commands
- assert c.call("cmd1 bar") == "ret bar"
+ assert c.execute("cmd1 bar") == "ret bar"
assert "empty" in c.commands
- assert c.call("empty") is None
+ assert c.execute("empty") is None
with taddons.context() as tctx:
tctx.master.addons.add(a)
- assert tctx.master.commands.call("cmd1 bar") == "ret bar"
+ assert tctx.master.commands.execute("cmd1 bar") == "ret bar"
def test_verify_arg_signature():
diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py
index 3d18987d..668d3c07 100644
--- a/test/mitmproxy/tools/web/test_app.py
+++ b/test/mitmproxy/tools/web/test_app.py
@@ -184,15 +184,10 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
self.fetch("/flows/42/revert", method="POST")
assert not f._backup
- # FIXME
- # def test_flow_replay(self):
- # with mock.patch("mitmproxy.master.Master.replay_request") as replay_request:
- # assert self.fetch("/flows/42/replay", method="POST").code == 200
- # assert replay_request.called
- # replay_request.side_effect = exceptions.ReplayException(
- # "out of replays"
- # )
- # assert self.fetch("/flows/42/replay", method="POST").code == 400
+ def test_flow_replay(self):
+ with mock.patch("mitmproxy.command.CommandManager.call") as replay_call:
+ assert self.fetch("/flows/42/replay", method="POST").code == 200
+ assert replay_call.called
def test_flow_content(self):
f = self.view.get_by_id("42")