Update tests.

This commit is contained in:
Matthew Shao 2017-08-01 23:01:58 +08:00
parent 7bbd89b121
commit ddffcf83ec
3 changed files with 23 additions and 14 deletions

View File

@ -105,6 +105,8 @@ class context:
Options object with the given keyword arguments, then calls the Options object with the given keyword arguments, then calls the
configure method on the addon with the updated value. configure method on the addon with the updated value.
""" """
loader = addonmanager.Loader(self.master)
self.master.addons.invoke_addon(addon, "load", loader)
with self.options.rollback(kwargs.keys(), reraise=True): with self.options.rollback(kwargs.keys(), reraise=True):
self.options.update(**kwargs) self.options.update(**kwargs)
self.master.addons.invoke_addon( self.master.addons.invoke_addon(

View File

@ -260,6 +260,9 @@ class TestScriptLoader:
debug = [i.msg for i in tctx.master.logs if i.level == "debug"] debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
assert debug == [ assert debug == [
'a load',
'b load',
'c load',
'c configure', 'c configure',
'a configure', 'a configure',
'b configure', 'b configure',
@ -277,6 +280,9 @@ class TestScriptLoader:
debug = [i.msg for i in tctx.master.logs if i.level == "debug"] debug = [i.msg for i in tctx.master.logs if i.level == "debug"]
assert debug == [ assert debug == [
'c load',
'a load',
'b load',
'c done', 'c done',
'b done', 'b done',
'a configure', 'a configure',

View File

@ -7,10 +7,7 @@ from mitmproxy import flowfilter
from mitmproxy import exceptions from mitmproxy import exceptions
from mitmproxy import io from mitmproxy import io
from mitmproxy.test import taddons from mitmproxy.test import taddons
from mitmproxy import options from mitmproxy.tools.console import consoleaddons
from mitmproxy.tools.console.master import ConsoleMaster
m = ConsoleMaster(options.Options())
def tft(*, method="get", start=0): def tft(*, method="get", start=0):
@ -30,8 +27,8 @@ def test_order_refresh():
v.sig_view_refresh.connect(save) v.sig_view_refresh.connect(save)
tf = tflow.tflow(resp=True) tf = tflow.tflow(resp=True)
with taddons.context(m) as tctx: with taddons.context() as tctx:
tctx.configure(v, console_order="time") tctx.configure(v, view_order="time")
v.add([tf]) v.add([tf])
tf.request.timestamp_start = 1 tf.request.timestamp_start = 1
assert not sargs assert not sargs
@ -297,19 +294,19 @@ def test_setgetval():
def test_order(): def test_order():
v = view.View() v = view.View()
with taddons.context(m) as tctx: with taddons.context() as tctx:
v.request(tft(method="get", start=1)) v.request(tft(method="get", start=1))
v.request(tft(method="put", start=2)) v.request(tft(method="put", start=2))
v.request(tft(method="get", start=3)) v.request(tft(method="get", start=3))
v.request(tft(method="put", start=4)) v.request(tft(method="put", start=4))
assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4]
tctx.configure(v, console_order="method") tctx.configure(v, view_order="method")
assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"] assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"]
v.set_reversed(True) v.set_reversed(True)
assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"] assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"]
tctx.configure(v, console_order="time") tctx.configure(v, view_order="time")
assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1] assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1]
v.set_reversed(False) v.set_reversed(False)
@ -428,7 +425,9 @@ def test_signals():
def test_focus_follow(): def test_focus_follow():
v = view.View() v = view.View()
with taddons.context(m) as tctx: with taddons.context() as tctx:
console_addon = consoleaddons.ConsoleAddon(tctx.master)
tctx.configure(console_addon)
tctx.configure(v, console_focus_follow=True, view_filter="~m get") tctx.configure(v, console_focus_follow=True, view_filter="~m get")
v.add([tft(start=5)]) v.add([tft(start=5)])
@ -545,16 +544,18 @@ def test_settings():
def test_configure(): def test_configure():
v = view.View() v = view.View()
with taddons.context(m) as tctx: with taddons.context() as tctx:
tctx.configure(v, view_filter="~q") tctx.configure(v, view_filter="~q")
with pytest.raises(Exception, match="Invalid interception filter"): with pytest.raises(Exception, match="Invalid interception filter"):
tctx.configure(v, view_filter="~~") tctx.configure(v, view_filter="~~")
tctx.configure(v, console_order="method") tctx.configure(v, view_order="method")
with pytest.raises(Exception, match="Unknown flow order"): with pytest.raises(Exception, match="Unknown flow order"):
tctx.configure(v, console_order="no") tctx.configure(v, view_order="no")
tctx.configure(v, console_order_reversed=True) tctx.configure(v, view_order_reversed=True)
console_addon = consoleaddons.ConsoleAddon(tctx.master)
tctx.configure(console_addon)
tctx.configure(v, console_focus_follow=True) tctx.configure(v, console_focus_follow=True)
assert v.focus_follow assert v.focus_follow