aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2017-12-13 14:42:56 +1300
committerGitHub <noreply@github.com>2017-12-13 14:42:56 +1300
commit79cf6d2a5d3b54a07eb8de140ab4991c9674db79 (patch)
tree110b4fb5ad970da5dd8e4823468119d0256d7a85 /test
parent1a45cf17b3b628e82e282bc3abfe14b5506e3877 (diff)
parent4cee1a4f96ef7307e422cf227c8389563323e442 (diff)
downloadmitmproxy-79cf6d2a5d3b54a07eb8de140ab4991c9674db79.tar.gz
mitmproxy-79cf6d2a5d3b54a07eb8de140ab4991c9674db79.tar.bz2
mitmproxy-79cf6d2a5d3b54a07eb8de140ab4991c9674db79.zip
Merge pull request #2668 from cortesi/commandopts
Command improvements
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/addons/test_core.py6
-rw-r--r--test/mitmproxy/test_command.py22
2 files changed, 22 insertions, 6 deletions
diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py
index c132d80a..5aa4ef37 100644
--- a/test/mitmproxy/addons/test_core.py
+++ b/test/mitmproxy/addons/test_core.py
@@ -69,9 +69,6 @@ def test_flow_set():
f = tflow.tflow(resp=True)
assert sa.flow_set_options()
- with pytest.raises(exceptions.CommandError):
- sa.flow_set([f], "flibble", "post")
-
assert f.request.method != "post"
sa.flow_set([f], "method", "post")
assert f.request.method == "POST"
@@ -126,9 +123,6 @@ def test_encoding():
sa.encode_toggle([f], "request")
assert "content-encoding" not in f.request.headers
- with pytest.raises(exceptions.CommandError):
- sa.encode([f], "request", "invalid")
-
def test_options(tmpdir):
p = str(tmpdir.join("path"))
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index 43b97742..cb9dc4ed 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -8,6 +8,10 @@ import io
import pytest
+TChoice = typing.NewType("TChoice", command.Choice)
+TChoice.options_command = "choices"
+
+
class TAddon:
def cmd1(self, foo: str) -> str:
"""cmd1 help"""
@@ -25,6 +29,12 @@ class TAddon:
def varargs(self, one: str, *var: str) -> typing.Sequence[str]:
return list(var)
+ def choices(self) -> typing.Sequence[str]:
+ return ["one", "two", "three"]
+
+ def choose(self, arg: TChoice) -> typing.Sequence[str]: # type: ignore
+ return ["one", "two", "three"]
+
class TestCommand:
def test_varargs(self):
@@ -86,6 +96,8 @@ def test_typename():
assert command.typename(flow.Flow, False) == "flow"
assert command.typename(typing.Sequence[str], False) == "[str]"
+ assert command.typename(TChoice, False) == "choice"
+
class DummyConsole:
@command.command("view.resolve")
@@ -134,6 +146,16 @@ def test_parsearg():
tctx.master.commands, "foo, bar", typing.Sequence[str]
) == ["foo", "bar"]
+ a = TAddon()
+ tctx.master.commands.add("choices", a.choices)
+ assert command.parsearg(
+ tctx.master.commands, "one", TChoice,
+ ) == "one"
+ with pytest.raises(exceptions.CommandError):
+ assert command.parsearg(
+ tctx.master.commands, "invalid", TChoice,
+ )
+
class TDec:
@command.command("cmd1")