From 40faf2c662368b74745031906219e7f9d1a5a4e1 Mon Sep 17 00:00:00 2001 From: madt1m Date: Wed, 13 Jun 2018 15:57:21 +0200 Subject: [PATCH] Added tests for new primitives --- mitmproxy/addons/view.py | 2 +- test/mitmproxy/addons/test_view.py | 43 +++++++++++++++++++----------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 6c771d961..4c1895525 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -292,7 +292,7 @@ class View(collections.Sequence): # Filter @command.command("view.filter.set") - def filter_set(self, f: str) -> None: + def set_filter_cmd(self, f: str) -> None: """ Sets the current view filter. """ diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index bd724950b..e840eac63 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] + 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.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: