From 773c9535146991af38f954cb4d3b0ead9d7485c5 Mon Sep 17 00:00:00 2001 From: madt1m Date: Wed, 13 Jun 2018 11:56:14 +0200 Subject: View API slightly extended; codebase cleaned in some points --- test/mitmproxy/test_command.py | 2 +- test/mitmproxy/test_types.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py index 029dbafd..d9dcf5f9 100644 --- a/test/mitmproxy/test_command.py +++ b/test/mitmproxy/test_command.py @@ -313,7 +313,7 @@ def test_typename(): class DummyConsole: - @command.command("view.resolve") + @command.command("view.flows.resolve") def resolve(self, spec: str) -> typing.Sequence[flow.Flow]: n = int(spec) return [tflow.tflow(resp=True)] * n diff --git a/test/mitmproxy/test_types.py b/test/mitmproxy/test_types.py index 35ff3241..571985fb 100644 --- a/test/mitmproxy/test_types.py +++ b/test/mitmproxy/test_types.py @@ -146,7 +146,7 @@ def test_strseq(): class DummyConsole: - @command.command("view.resolve") + @command.command("view.flows.resolve") def resolve(self, spec: str) -> typing.Sequence[flow.Flow]: if spec == "err": raise mitmproxy.exceptions.CommandError() -- cgit v1.2.3 From 40faf2c662368b74745031906219e7f9d1a5a4e1 Mon Sep 17 00:00:00 2001 From: madt1m Date: Wed, 13 Jun 2018 15:57:21 +0200 Subject: Added tests for new primitives --- test/mitmproxy/addons/test_view.py | 45 ++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index bd724950..e840eac6 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -107,13 +107,12 @@ def test_simple(): def test_filter(): v = view.View() - f = flowfilter.parse("~m get") v.request(tft(method="get")) v.request(tft(method="put")) v.request(tft(method="get")) v.request(tft(method="put")) assert(len(v)) == 4 - v.set_filter(f) + v.set_filter_cmd("~m get") assert [i.request.method for i in v] == ["GET", "GET"] assert len(v._store) == 4 v.set_filter(None) @@ -303,23 +302,24 @@ def test_setgetval(): def test_order(): v = view.View() - with taddons.context(v) as tctx: - v.request(tft(method="get", start=1)) - v.request(tft(method="put", start=2)) - v.request(tft(method="get", start=3)) - v.request(tft(method="put", start=4)) - assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] - - tctx.configure(v, view_order="method") - assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"] - v.set_reversed(True) - assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"] + v.request(tft(method="get", start=1)) + v.request(tft(method="put", start=2)) + v.request(tft(method="get", start=3)) + v.request(tft(method="put", start=4)) + assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] + + v.set_order("method") + assert v.get_order() == "method" + assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"] + v.set_reversed(True) + assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"] - tctx.configure(v, view_order="time") - assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1] + v.set_order("time") + assert v.get_order() == "time" + assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1] - v.set_reversed(False) - assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] + v.set_reversed(False) + assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] def test_reversed(): @@ -551,6 +551,17 @@ def test_settings(): assert not v.settings.keys() +def test_properties(): + v = view.View() + f = tft() + v.request(f) + assert v.get_length() == 1 + assert not v.get_marked() + v.toggle_marked() + assert v.get_length() == 0 + assert v.get_marked() + + def test_configure(): v = view.View() with taddons.context(v) as tctx: -- cgit v1.2.3 From af54c260143f378bc71e3eba836544a59e9a2736 Mon Sep 17 00:00:00 2001 From: madt1m Date: Wed, 13 Jun 2018 17:39:46 +0200 Subject: fixed exception type; full coverage on view --- test/mitmproxy/addons/test_view.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test') diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index e840eac6..976c14b7 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -123,6 +123,9 @@ def test_filter(): v.toggle_marked() assert len(v) == 4 + with pytest.raises(exceptions.CommandError): + v.set_filter_cmd("~notafilter regex") + v[1].marked = True v.toggle_marked() assert len(v) == 1 @@ -320,6 +323,8 @@ def test_order(): v.set_reversed(False) assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4] + with pytest.raises(exceptions.CommandError): + v.set_order("not_an_order") def test_reversed(): -- cgit v1.2.3