mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Clean up un-necessary arguments to taddons.context
Also test coverage ++
This commit is contained in:
parent
af39e022ef
commit
42094b29ff
@ -4,12 +4,11 @@ import click
|
||||
from mitmproxy.addons import dumper
|
||||
from mitmproxy.test import tflow
|
||||
from mitmproxy.test import taddons
|
||||
from mitmproxy.tools import options
|
||||
|
||||
|
||||
def show(flow_detail, flows):
|
||||
d = dumper.Dumper()
|
||||
with taddons.context(options=options.Options()) as ctx:
|
||||
with taddons.context() as ctx:
|
||||
ctx.configure(d, flow_detail=flow_detail)
|
||||
for f in flows:
|
||||
ctx.cycle(d, f)
|
||||
|
@ -10,12 +10,11 @@ from mitmproxy.test import tutils
|
||||
from mitmproxy.addons import dumper
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy import http
|
||||
from mitmproxy import options
|
||||
|
||||
|
||||
def test_configure():
|
||||
d = dumper.Dumper()
|
||||
with taddons.context(options=options.Options()) as ctx:
|
||||
with taddons.context() as ctx:
|
||||
ctx.configure(d, view_filter="~b foo")
|
||||
assert d.filter
|
||||
|
||||
@ -34,7 +33,7 @@ def test_configure():
|
||||
def test_simple():
|
||||
sio = io.StringIO()
|
||||
d = dumper.Dumper(sio)
|
||||
with taddons.context(options=options.Options()) as ctx:
|
||||
with taddons.context() as ctx:
|
||||
ctx.configure(d, flow_detail=0)
|
||||
d.response(tflow.tflow(resp=True))
|
||||
assert not sio.getvalue()
|
||||
@ -102,7 +101,7 @@ def test_echo_body():
|
||||
|
||||
sio = io.StringIO()
|
||||
d = dumper.Dumper(sio)
|
||||
with taddons.context(options=options.Options()) as ctx:
|
||||
with taddons.context() as ctx:
|
||||
ctx.configure(d, flow_detail=3)
|
||||
d._echo_message(f.response)
|
||||
t = sio.getvalue()
|
||||
@ -112,7 +111,7 @@ def test_echo_body():
|
||||
def test_echo_request_line():
|
||||
sio = io.StringIO()
|
||||
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)
|
||||
f = tflow.tflow(client_conn=None, server_conn=True, resp=True)
|
||||
f.request.is_replay = True
|
||||
@ -147,7 +146,7 @@ class TestContentView:
|
||||
view_auto.side_effect = exceptions.ContentViewException("")
|
||||
sio = io.StringIO()
|
||||
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')
|
||||
d.response(tflow.tflow())
|
||||
assert ctx.master.has_log("content viewer failed")
|
||||
@ -156,7 +155,7 @@ class TestContentView:
|
||||
def test_tcp():
|
||||
sio = io.StringIO()
|
||||
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)
|
||||
f = tflow.ttcpflow()
|
||||
d.tcp_message(f)
|
||||
@ -171,7 +170,7 @@ def test_tcp():
|
||||
def test_websocket():
|
||||
sio = io.StringIO()
|
||||
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)
|
||||
f = tflow.twebsocketflow()
|
||||
d.websocket_message(f)
|
||||
|
@ -1,7 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from mitmproxy.addons import intercept
|
||||
from mitmproxy import options
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy.test import taddons
|
||||
from mitmproxy.test import tflow
|
||||
@ -9,7 +8,7 @@ from mitmproxy.test import tflow
|
||||
|
||||
def test_simple():
|
||||
r = intercept.Intercept()
|
||||
with taddons.context(options=options.Options()) as tctx:
|
||||
with taddons.context() as tctx:
|
||||
assert not r.filt
|
||||
tctx.configure(r, intercept="~q")
|
||||
assert r.filt
|
||||
|
@ -5,14 +5,13 @@ from mitmproxy.test import tflow
|
||||
|
||||
from mitmproxy import io
|
||||
from mitmproxy import exceptions
|
||||
from mitmproxy import options
|
||||
from mitmproxy.addons import save
|
||||
from mitmproxy.addons import view
|
||||
|
||||
|
||||
def test_configure(tmpdir):
|
||||
sa = save.Save()
|
||||
with taddons.context(options=options.Options()) as tctx:
|
||||
with taddons.context() as tctx:
|
||||
with pytest.raises(exceptions.OptionsError):
|
||||
tctx.configure(sa, save_stream_file=str(tmpdir))
|
||||
with pytest.raises(Exception, match="Invalid filter"):
|
||||
|
@ -376,8 +376,11 @@ def test_make_parser():
|
||||
opts.make_parser(parser, "seqstr", short="d")
|
||||
opts.make_parser(parser, "bool_on", short="e")
|
||||
|
||||
# No error for nonexistent options
|
||||
opts.make_parser(parser, "xxxxxxx")
|
||||
with pytest.raises(ValueError):
|
||||
opts.make_parser(parser, "unknown")
|
||||
|
||||
# Nonexistent options ignore
|
||||
opts.make_parser(parser, "nonexistentxxx")
|
||||
|
||||
|
||||
def test_set():
|
||||
|
Loading…
Reference in New Issue
Block a user