Clean up un-necessary arguments to taddons.context

Also test coverage ++
This commit is contained in:
Aldo Cortesi 2018-02-24 12:33:48 +13:00 committed by Aldo Cortesi
parent af39e022ef
commit 42094b29ff
5 changed files with 15 additions and 16 deletions

View File

@ -4,12 +4,11 @@ import click
from mitmproxy.addons import dumper from mitmproxy.addons import dumper
from mitmproxy.test import tflow from mitmproxy.test import tflow
from mitmproxy.test import taddons from mitmproxy.test import taddons
from mitmproxy.tools import options
def show(flow_detail, flows): def show(flow_detail, flows):
d = dumper.Dumper() d = dumper.Dumper()
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=flow_detail) ctx.configure(d, flow_detail=flow_detail)
for f in flows: for f in flows:
ctx.cycle(d, f) ctx.cycle(d, f)

View File

@ -10,12 +10,11 @@ from mitmproxy.test import tutils
from mitmproxy.addons import dumper from mitmproxy.addons import dumper
from mitmproxy import exceptions from mitmproxy import exceptions
from mitmproxy import http from mitmproxy import http
from mitmproxy import options
def test_configure(): def test_configure():
d = dumper.Dumper() d = dumper.Dumper()
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, view_filter="~b foo") ctx.configure(d, view_filter="~b foo")
assert d.filter assert d.filter
@ -34,7 +33,7 @@ def test_configure():
def test_simple(): def test_simple():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=0) ctx.configure(d, flow_detail=0)
d.response(tflow.tflow(resp=True)) d.response(tflow.tflow(resp=True))
assert not sio.getvalue() assert not sio.getvalue()
@ -102,7 +101,7 @@ def test_echo_body():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=3) ctx.configure(d, flow_detail=3)
d._echo_message(f.response) d._echo_message(f.response)
t = sio.getvalue() t = sio.getvalue()
@ -112,7 +111,7 @@ def test_echo_body():
def test_echo_request_line(): def test_echo_request_line():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=3, showhost=True) ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.tflow(client_conn=None, server_conn=True, resp=True) f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
f.request.is_replay = True f.request.is_replay = True
@ -147,7 +146,7 @@ class TestContentView:
view_auto.side_effect = exceptions.ContentViewException("") view_auto.side_effect = exceptions.ContentViewException("")
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=4, verbosity='debug') ctx.configure(d, flow_detail=4, verbosity='debug')
d.response(tflow.tflow()) d.response(tflow.tflow())
assert ctx.master.has_log("content viewer failed") assert ctx.master.has_log("content viewer failed")
@ -156,7 +155,7 @@ class TestContentView:
def test_tcp(): def test_tcp():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=3, showhost=True) ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.ttcpflow() f = tflow.ttcpflow()
d.tcp_message(f) d.tcp_message(f)
@ -171,7 +170,7 @@ def test_tcp():
def test_websocket(): def test_websocket():
sio = io.StringIO() sio = io.StringIO()
d = dumper.Dumper(sio) d = dumper.Dumper(sio)
with taddons.context(options=options.Options()) as ctx: with taddons.context() as ctx:
ctx.configure(d, flow_detail=3, showhost=True) ctx.configure(d, flow_detail=3, showhost=True)
f = tflow.twebsocketflow() f = tflow.twebsocketflow()
d.websocket_message(f) d.websocket_message(f)

View File

@ -1,7 +1,6 @@
import pytest import pytest
from mitmproxy.addons import intercept from mitmproxy.addons import intercept
from mitmproxy import options
from mitmproxy import exceptions from mitmproxy import exceptions
from mitmproxy.test import taddons from mitmproxy.test import taddons
from mitmproxy.test import tflow from mitmproxy.test import tflow
@ -9,7 +8,7 @@ from mitmproxy.test import tflow
def test_simple(): def test_simple():
r = intercept.Intercept() r = intercept.Intercept()
with taddons.context(options=options.Options()) as tctx: with taddons.context() as tctx:
assert not r.filt assert not r.filt
tctx.configure(r, intercept="~q") tctx.configure(r, intercept="~q")
assert r.filt assert r.filt

View File

@ -5,14 +5,13 @@ from mitmproxy.test import tflow
from mitmproxy import io from mitmproxy import io
from mitmproxy import exceptions from mitmproxy import exceptions
from mitmproxy import options
from mitmproxy.addons import save from mitmproxy.addons import save
from mitmproxy.addons import view from mitmproxy.addons import view
def test_configure(tmpdir): def test_configure(tmpdir):
sa = save.Save() sa = save.Save()
with taddons.context(options=options.Options()) as tctx: with taddons.context() as tctx:
with pytest.raises(exceptions.OptionsError): with pytest.raises(exceptions.OptionsError):
tctx.configure(sa, save_stream_file=str(tmpdir)) tctx.configure(sa, save_stream_file=str(tmpdir))
with pytest.raises(Exception, match="Invalid filter"): with pytest.raises(Exception, match="Invalid filter"):

View File

@ -376,8 +376,11 @@ def test_make_parser():
opts.make_parser(parser, "seqstr", short="d") opts.make_parser(parser, "seqstr", short="d")
opts.make_parser(parser, "bool_on", short="e") opts.make_parser(parser, "bool_on", short="e")
# No error for nonexistent options with pytest.raises(ValueError):
opts.make_parser(parser, "xxxxxxx") opts.make_parser(parser, "unknown")
# Nonexistent options ignore
opts.make_parser(parser, "nonexistentxxx")
def test_set(): def test_set():