diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-11-13 18:41:05 -0800 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-11-13 18:41:05 -0800 |
commit | dce469d4c18b027292b84b91951d189a95f8067f (patch) | |
tree | fd506d4dc01a146c9d4b9ef8a71776a077ef151a /test | |
parent | 3cd709d982a7e565a736bf4f3ce0b841eeb6d3ef (diff) | |
parent | e72a9a62a107ea3f53b6b26d1abe63c554448d17 (diff) | |
download | mitmproxy-dce469d4c18b027292b84b91951d189a95f8067f.tar.gz mitmproxy-dce469d4c18b027292b84b91951d189a95f8067f.tar.bz2 mitmproxy-dce469d4c18b027292b84b91951d189a95f8067f.zip |
Merge pull request #833 from zbuc/contentview_scripts
Contentview scripts
Diffstat (limited to 'test')
-rw-r--r-- | test/test_contentview.py | 15 | ||||
-rw-r--r-- | test/test_custom_contentview.py | 52 | ||||
-rw-r--r-- | test/test_script.py | 1 |
3 files changed, 68 insertions, 0 deletions
diff --git a/test/test_contentview.py b/test/test_contentview.py index 14adcd83..2a70b414 100644 --- a/test/test_contentview.py +++ b/test/test_contentview.py @@ -210,6 +210,21 @@ Larry assert "decoded gzip" in r[0] assert "Raw" in r[0] + def test_add_cv(self): + class TestContentView(cv.View): + name = "test" + prompt = ("t", "test") + + tcv = TestContentView() + cv.add(tcv) + + # repeated addition causes exception + tutils.raises( + ContentViewException, + cv.add, + tcv + ) + if pyamf: def test_view_amf_request(): diff --git a/test/test_custom_contentview.py b/test/test_custom_contentview.py new file mode 100644 index 00000000..4b5a3e53 --- /dev/null +++ b/test/test_custom_contentview.py @@ -0,0 +1,52 @@ +from libmproxy import script, flow +import libmproxy.contentviews as cv +from netlib.http import Headers + + +def test_custom_views(): + class ViewNoop(cv.View): + name = "noop" + prompt = ("noop", "n") + content_types = ["text/none"] + + def __call__(self, data, **metadata): + return "noop", cv.format_text(data) + + + view_obj = ViewNoop() + + cv.add(view_obj) + + assert cv.get("noop") + + r = cv.get_content_view( + cv.get("noop"), + "[1, 2, 3]", + headers=Headers( + content_type="text/plain" + ) + ) + assert "noop" in r[0] + + # now try content-type matching + r = cv.get_content_view( + cv.get("Auto"), + "[1, 2, 3]", + headers=Headers( + content_type="text/none" + ) + ) + assert "noop" in r[0] + + # now try removing the custom view + cv.remove(view_obj) + r = cv.get_content_view( + cv.get("Auto"), + "[1, 2, 3]", + headers=Headers( + content_type="text/none" + ) + ) + assert "noop" not in r[0] + + diff --git a/test/test_script.py b/test/test_script.py index 1b0e5a5b..8612d5f3 100644 --- a/test/test_script.py +++ b/test/test_script.py @@ -127,3 +127,4 @@ def test_command_parsing(): absfilepath = os.path.normcase(tutils.test_data.path("scripts/a.py")) s = script.Script(absfilepath, fm) assert os.path.isfile(s.args[0]) + |