aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-06-13 23:03:07 +0800
committerMatthew Shao <me@matshao.com>2017-06-13 23:03:07 +0800
commit2c0f6c202321a9d332dbe0181d319a3be4fd2614 (patch)
tree346f0c4c9102b0c0ec6f4af4e241bc683fe7dcc5
parent03bb0a09b95d1942a62435545d867b0888de75fa (diff)
downloadmitmproxy-2c0f6c202321a9d332dbe0181d319a3be4fd2614.tar.gz
mitmproxy-2c0f6c202321a9d332dbe0181d319a3be4fd2614.tar.bz2
mitmproxy-2c0f6c202321a9d332dbe0181d319a3be4fd2614.zip
Minor Update and add test.
-rw-r--r--mitmproxy/optmanager.py19
-rw-r--r--test/mitmproxy/tools/web/test_app.py5
2 files changed, 22 insertions, 2 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index 3685c003..b67949e0 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -420,12 +420,27 @@ def dump_dicts(opts):
"""
Dumps the options into a list of dict object.
- Return: A list like: [ { name: "anticahce", type: "bool", default: false, value: true, help: "help text"}]
+ Return: A list like: [ { name: "anticache", type: "bool", default: false, value: true, help: "help text"} ]
"""
options_list = []
for k in sorted(opts.keys()):
o = opts._options[k]
- option = {'name': k, 'type': o.typespec.__name__, 'default': o.default, 'value': o.current(), 'help': o.help.strip()}
+ if o.typespec in (str, int, bool):
+ t = o.typespec.__name__
+ elif o.typespec == typing.Optional[str]:
+ t = 'Union'
+ elif o.typespec == typing.Sequence[str]:
+ t = 'Sequence'
+ else:
+ raise NotImplementedError
+ option = {
+ 'name': k,
+ 'type': t,
+ 'default': o.default,
+ 'value': o.current(),
+ 'help': o.help,
+ 'choices': o.choices
+ }
options_list.append(option)
return options_list
diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py
index 5427b995..d47b1af0 100644
--- a/test/mitmproxy/tools/web/test_app.py
+++ b/test/mitmproxy/tools/web/test_app.py
@@ -253,6 +253,11 @@ 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_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f:
f.side_effect = RuntimeError