aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-06-24 19:54:04 +0200
committerGitHub <noreply@github.com>2017-06-24 19:54:04 +0200
commitbde64746a91666a3ae8b693fed05bc29824b814c (patch)
treeff9899f1f61795e1299c76d36937d46b56745677 /test
parenta0abc7b748425e450a51873749d8275265991622 (diff)
parent18633262201b33fb0c36381fbc65febf21313eb7 (diff)
downloadmitmproxy-bde64746a91666a3ae8b693fed05bc29824b814c.tar.gz
mitmproxy-bde64746a91666a3ae8b693fed05bc29824b814c.tar.bz2
mitmproxy-bde64746a91666a3ae8b693fed05bc29824b814c.zip
Merge pull request #2395 from MatthewShao/mitmweb-options
[WIP] Add RESTful API for mitmweb option
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_optmanager.py5
-rw-r--r--test/mitmproxy/tools/web/test_app.py10
-rw-r--r--test/mitmproxy/utils/test_typecheck.py8
3 files changed, 23 insertions, 0 deletions
diff --git a/test/mitmproxy/test_optmanager.py b/test/mitmproxy/test_optmanager.py
index cadc5d76..0c400683 100644
--- a/test/mitmproxy/test_optmanager.py
+++ b/test/mitmproxy/test_optmanager.py
@@ -338,6 +338,11 @@ def test_dump_defaults():
assert optmanager.dump_defaults(o)
+def test_dump_dicts():
+ o = options.Options()
+ assert optmanager.dump_dicts(o)
+
+
class TTypes(optmanager.OptManager):
def __init__(self):
super().__init__()
diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py
index 5427b995..e6d563e7 100644
--- a/test/mitmproxy/tools/web/test_app.py
+++ b/test/mitmproxy/tools/web/test_app.py
@@ -253,6 +253,16 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
assert self.put_json("/settings", {"anticache": True}).code == 200
assert self.put_json("/settings", {"wtf": True}).code == 400
+ def test_options(self):
+ j = json(self.fetch("/options"))
+ assert type(j) == list
+ assert type(j[0]) == dict
+
+ def test_option_update(self):
+ assert self.put_json("/options", {"anticache": True}).code == 200
+ assert self.put_json("/options", {"wtf": True}).code == 400
+ assert self.put_json("/options", {"anticache": "foo"}).code == 400
+
def test_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f:
f.side_effect = RuntimeError
diff --git a/test/mitmproxy/utils/test_typecheck.py b/test/mitmproxy/utils/test_typecheck.py
index fe33070e..66b1884e 100644
--- a/test/mitmproxy/utils/test_typecheck.py
+++ b/test/mitmproxy/utils/test_typecheck.py
@@ -111,3 +111,11 @@ def test_check_command_type():
m.__str__ = lambda self: "typing.Union"
m.__union_params__ = (int,)
assert not typecheck.check_command_type([22], m)
+
+
+def test_typesec_to_str():
+ assert(typecheck.typespec_to_str(str)) == "str"
+ assert(typecheck.typespec_to_str(typing.Sequence[str])) == "sequence of str"
+ assert(typecheck.typespec_to_str(typing.Optional[str])) == "optional str"
+ with pytest.raises(NotImplementedError):
+ typecheck.typespec_to_str(dict)