aboutsummaryrefslogtreecommitdiffstats
path: root/test/tutils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2014-01-04 14:34:20 -0800
committerAldo Cortesi <aldo@corte.si>2014-01-04 14:34:20 -0800
commit7d37e0ce10d6684c237833b85280c922ba2926de (patch)
treee15cd7b52c1511aafa7229191e9f7faddbb3e3e2 /test/tutils.py
parent8a599be0602382e0ea5ffbc4018db07b0f379ae7 (diff)
parent799c87767684880469c12d75053fb860f4a0d3c9 (diff)
downloadmitmproxy-7d37e0ce10d6684c237833b85280c922ba2926de.tar.gz
mitmproxy-7d37e0ce10d6684c237833b85280c922ba2926de.tar.bz2
mitmproxy-7d37e0ce10d6684c237833b85280c922ba2926de.zip
Merge pull request #193 from droope/search-functionality
Search functionality
Diffstat (limited to 'test/tutils.py')
-rw-r--r--test/tutils.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/test/tutils.py b/test/tutils.py
index 4cd7b7f8..d6332107 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -1,8 +1,11 @@
import os, shutil, tempfile
from contextlib import contextmanager
from libmproxy import flow, utils, controller
+from libmproxy.console.flowview import FlowView
+from libmproxy.console import ConsoleState
from netlib import certutils
from nose.plugins.skip import SkipTest
+from mock import Mock
def _SkipWindows():
raise SkipTest("Skipped on Windows.")
@@ -12,13 +15,14 @@ def SkipWindows(fn):
else:
return fn
-def treq(conn=None):
+def treq(conn=None, content="content"):
if not conn:
conn = flow.ClientConnect(("address", 22))
conn.reply = controller.DummyReply()
headers = flow.ODictCaseless()
headers["header"] = ["qvalue"]
- r = flow.Request(conn, (1, 1), "host", 80, "http", "GET", "/path", headers, "content")
+ r = flow.Request(conn, (1, 1), "host", 80, "http", "GET", "/path", headers,
+ content)
r.reply = controller.DummyReply()
return r
@@ -41,8 +45,9 @@ def terr(req=None):
return err
-def tflow():
- r = treq()
+def tflow(r=None):
+ if r == None:
+ r = treq()
return flow.Flow(r)
@@ -57,6 +62,20 @@ def tflow_err():
f.error = terr(f.request)
return f
+def tflowview(request_contents=None):
+ m = Mock()
+ cs = ConsoleState()
+ if request_contents == None:
+ flow = tflow()
+ else:
+ req = treq(None, request_contents)
+ flow = tflow(req)
+
+ fv = FlowView(m, cs, flow)
+ return fv
+
+def get_body_line(last_displayed_body, line_nb):
+ return last_displayed_body.contents()[line_nb + 2]
@contextmanager
def tmpdir(*args, **kwargs):