From 29f41643442cd11f638fa14c1d9c297c083c7e8a Mon Sep 17 00:00:00 2001 From: itzikBraun Date: Mon, 2 Apr 2018 12:57:33 +0200 Subject: added option to export request as httpie command --- test/mitmproxy/addons/test_export.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_export.py b/test/mitmproxy/addons/test_export.py index 07227a7a..b625df56 100644 --- a/test/mitmproxy/addons/test_export.py +++ b/test/mitmproxy/addons/test_export.py @@ -65,6 +65,26 @@ class TestExportCurlCommand: export.curl_command(tcp_flow) +class TestExportHttpieCommand: + def test_get(self, get_request): + result = """http GET http://address:22/path?a=foo&a=bar&b=baz 'header:qvalue' 'content-length:0'""" + assert export.httpie_command(get_request) == result + + def test_post(self, post_request): + result = "http POST http://address:22/path 'content-length:256' <<< '{}'".format( + str(bytes(range(256)))[2:-1] + ) + assert export.httpie_command(post_request) == result + + def test_patch(self, patch_request): + result = """http PATCH http://address:22/path?query=param 'header:qvalue' 'content-length:7' <<< 'content'""" + assert export.httpie_command(patch_request) == result + + def test_tcp(self, tcp_flow): + with pytest.raises(exceptions.CommandError): + export.httpie_command(tcp_flow) + + class TestRaw: def test_get(self, get_request): assert b"header: qvalue" in export.raw(get_request) @@ -83,7 +103,7 @@ def test_export(tmpdir): f = str(tmpdir.join("path")) e = export.Export() with taddons.context(): - assert e.formats() == ["curl", "raw"] + assert e.formats() == ["curl", "httpie", "raw"] with pytest.raises(exceptions.CommandError): e.file("nonexistent", tflow.tflow(resp=True), f) @@ -95,6 +115,10 @@ def test_export(tmpdir): assert qr(f) os.unlink(f) + e.file("httpie", tflow.tflow(resp=True), f) + assert qr(f) + os.unlink(f) + @pytest.mark.parametrize("exception, log_message", [ (PermissionError, "Permission denied"), @@ -125,6 +149,10 @@ def test_clip(tmpdir): e.clip("curl", tflow.tflow(resp=True)) assert pc.called + with mock.patch('pyperclip.copy') as pc: + e.clip("httpie", tflow.tflow(resp=True)) + assert pc.called + with mock.patch('pyperclip.copy') as pc: log_message = "Pyperclip could not find a " \ "copy/paste mechanism for your system." -- cgit v1.2.3