From 95e690ba31db9cb35eaa7e22ecebbe06ea8e2044 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 23 Apr 2018 11:05:58 +1200 Subject: test: shift test_data out of our public API --- test/examples/test_examples.py | 34 ++++++++++++++++------------------ test/examples/test_har_dump.py | 18 ++++++++---------- 2 files changed, 24 insertions(+), 28 deletions(-) (limited to 'test/examples') diff --git a/test/examples/test_examples.py b/test/examples/test_examples.py index 4c1631ce..255dbf71 100644 --- a/test/examples/test_examples.py +++ b/test/examples/test_examples.py @@ -6,27 +6,25 @@ from mitmproxy.net.http import Headers from ..mitmproxy import tservers -example_dir = tutils.test_data.push("../examples") - class TestScripts(tservers.MasterTest): - def test_add_header(self): + def test_add_header(self, tdata): with taddons.context() as tctx: - a = tctx.script(example_dir.path("simple/add_header.py")) + a = tctx.script(tdata.path("../examples/simple/add_header.py")) f = tflow.tflow(resp=tutils.tresp()) a.response(f) assert f.response.headers["newheader"] == "foo" - def test_custom_contentviews(self): + def test_custom_contentviews(self, tdata): with taddons.context() as tctx: - tctx.script(example_dir.path("simple/custom_contentview.py")) + tctx.script(tdata.path("../examples/simple/custom_contentview.py")) swapcase = contentviews.get("swapcase") _, fmt = swapcase(b"Test!") assert any(b'tEST!' in val[0][1] for val in fmt) - def test_iframe_injector(self): + def test_iframe_injector(self, tdata): with taddons.context() as tctx: - sc = tctx.script(example_dir.path("simple/modify_body_inject_iframe.py")) + sc = tctx.script(tdata.path("../examples/simple/modify_body_inject_iframe.py")) tctx.configure( sc, iframe = "http://example.org/evil_iframe" @@ -38,9 +36,9 @@ class TestScripts(tservers.MasterTest): content = f.response.content assert b'iframe' in content and b'evil_iframe' in content - def test_modify_form(self): + def test_modify_form(self, tdata): with taddons.context() as tctx: - sc = tctx.script(example_dir.path("simple/modify_form.py")) + sc = tctx.script(tdata.path("../examples/simple/modify_form.py")) form_header = Headers(content_type="application/x-www-form-urlencoded") f = tflow.tflow(req=tutils.treq(headers=form_header)) @@ -52,9 +50,9 @@ class TestScripts(tservers.MasterTest): sc.request(f) assert list(f.request.urlencoded_form.items()) == [("foo", "bar")] - def test_modify_querystring(self): + def test_modify_querystring(self, tdata): with taddons.context() as tctx: - sc = tctx.script(example_dir.path("simple/modify_querystring.py")) + sc = tctx.script(tdata.path("../examples/simple/modify_querystring.py")) f = tflow.tflow(req=tutils.treq(path="/search?q=term")) sc.request(f) @@ -64,23 +62,23 @@ class TestScripts(tservers.MasterTest): sc.request(f) assert f.request.query["mitmproxy"] == "rocks" - def test_redirect_requests(self): + def test_redirect_requests(self, tdata): with taddons.context() as tctx: - sc = tctx.script(example_dir.path("simple/redirect_requests.py")) + sc = tctx.script(tdata.path("../examples/simple/redirect_requests.py")) f = tflow.tflow(req=tutils.treq(host="example.org")) sc.request(f) assert f.request.host == "mitmproxy.org" - def test_send_reply_from_proxy(self): + def test_send_reply_from_proxy(self, tdata): with taddons.context() as tctx: - sc = tctx.script(example_dir.path("simple/send_reply_from_proxy.py")) + sc = tctx.script(tdata.path("../examples/simple/send_reply_from_proxy.py")) f = tflow.tflow(req=tutils.treq(host="example.com", port=80)) sc.request(f) assert f.response.content == b"Hello World" - def test_dns_spoofing(self): + def test_dns_spoofing(self, tdata): with taddons.context() as tctx: - sc = tctx.script(example_dir.path("complex/dns_spoofing.py")) + sc = tctx.script(tdata.path("../examples/complex/dns_spoofing.py")) original_host = "example.com" diff --git a/test/examples/test_har_dump.py b/test/examples/test_har_dump.py index 11cd5c29..7eb4f5f9 100644 --- a/test/examples/test_har_dump.py +++ b/test/examples/test_har_dump.py @@ -5,8 +5,6 @@ from mitmproxy.test import tutils from mitmproxy.test import taddons from mitmproxy.net.http import cookies -example_dir = tutils.test_data.push("../examples") - class TestHARDump: def flow(self, resp_content=b'message'): @@ -21,9 +19,9 @@ class TestHARDump: resp=tutils.tresp(content=resp_content, **times) ) - def test_simple(self, tmpdir): + def test_simple(self, tmpdir, tdata): with taddons.context() as tctx: - a = tctx.script(example_dir.path("complex/har_dump.py")) + a = tctx.script(tdata.path("../examples/complex/har_dump.py")) path = str(tmpdir.join("somefile")) tctx.configure(a, hardump=path) tctx.invoke(a, "response", self.flow()) @@ -32,9 +30,9 @@ class TestHARDump: har = json.load(inp) assert len(har["log"]["entries"]) == 1 - def test_base64(self, tmpdir): + def test_base64(self, tmpdir, tdata): with taddons.context() as tctx: - a = tctx.script(example_dir.path("complex/har_dump.py")) + a = tctx.script(tdata.path("../examples/complex/har_dump.py")) path = str(tmpdir.join("somefile")) tctx.configure(a, hardump=path) @@ -46,9 +44,9 @@ class TestHARDump: har = json.load(inp) assert har["log"]["entries"][0]["response"]["content"]["encoding"] == "base64" - def test_format_cookies(self): + def test_format_cookies(self, tdata): with taddons.context() as tctx: - a = tctx.script(example_dir.path("complex/har_dump.py")) + a = tctx.script(tdata.path("../examples/complex/har_dump.py")) CA = cookies.CookieAttrs @@ -65,9 +63,9 @@ class TestHARDump: f = a.format_cookies([("n", "v", CA([("expires", "Mon, 24-Aug-2037 00:00:00 GMT")]))])[0] assert f['expires'] - def test_binary(self, tmpdir): + def test_binary(self, tmpdir, tdata): with taddons.context() as tctx: - a = tctx.script(example_dir.path("complex/har_dump.py")) + a = tctx.script(tdata.path("../examples/complex/har_dump.py")) path = str(tmpdir.join("somefile")) tctx.configure(a, hardump=path) -- cgit v1.2.3