diff options
author | Maximilian Hils <git@maximilianhils.com> | 2013-06-17 16:48:06 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2013-06-17 16:48:06 +0200 |
commit | d462b444b7eed04927e77d8971d4b218459fdee3 (patch) | |
tree | 98cfc69daa13dfe1b647ea89d9364bcc8117d624 | |
parent | 84248d431bcad4a289f1ce82bf090da41970020b (diff) | |
download | mitmproxy-d462b444b7eed04927e77d8971d4b218459fdee3.tar.gz mitmproxy-d462b444b7eed04927e77d8971d4b218459fdee3.tar.bz2 mitmproxy-d462b444b7eed04927e77d8971d4b218459fdee3.zip |
update tests to reflect changes to options.scripts
-rw-r--r-- | libmproxy/dump.py | 3 | ||||
-rw-r--r-- | libmproxy/script.py | 6 | ||||
-rw-r--r-- | test/test_console.py | 4 | ||||
-rw-r--r-- | test/test_console_common.py | 5 | ||||
-rw-r--r-- | test/test_console_contentview.py | 5 | ||||
-rw-r--r-- | test/test_console_help.py | 5 | ||||
-rw-r--r-- | test/test_dump.py | 7 | ||||
-rw-r--r-- | test/test_flow.py | 16 |
8 files changed, 37 insertions, 14 deletions
diff --git a/libmproxy/dump.py b/libmproxy/dump.py index cfc7c5da..88deb0d5 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -121,7 +121,8 @@ class DumpMaster(flow.FlowMaster): not options.keepserving ) - for script_argv in options.scripts: + scripts = options.scripts or [] + for script_argv in scripts: err = self.load_script(script_argv) if err: raise DumpError(err) diff --git a/libmproxy/script.py b/libmproxy/script.py index 4676672b..a7b774e6 100644 --- a/libmproxy/script.py +++ b/libmproxy/script.py @@ -46,10 +46,12 @@ class Script: ns = {} try: execfile(path, ns, ns) - self.ns = ns - self.run("start", self.argv) except Exception, v: raise ScriptError(traceback.format_exc(v)) + self.ns = ns + r = self.run("start", self.argv) + if not r[0] and r[1]: + raise ScriptError(r[1][1]) def unload(self): return self.run("done") diff --git a/test/test_console.py b/test/test_console.py index 498a93bd..4fd9bb9f 100644 --- a/test/test_console.py +++ b/test/test_console.py @@ -1,4 +1,8 @@ import os +from nose.plugins.skip import SkipTest +if os.name == "nt": + raise SkipTest("Skipped on Windows.") + from libmproxy import console from libmproxy.console import common import tutils diff --git a/test/test_console_common.py b/test/test_console_common.py index 29bf7b84..d798e4dc 100644 --- a/test/test_console_common.py +++ b/test/test_console_common.py @@ -1,3 +1,8 @@ +import os +from nose.plugins.skip import SkipTest +if os.name == "nt": + raise SkipTest("Skipped on Windows.") + import libmproxy.console.common as common from libmproxy import utils, flow, encoding import tutils diff --git a/test/test_console_contentview.py b/test/test_console_contentview.py index f6b45f67..ef44f834 100644 --- a/test/test_console_contentview.py +++ b/test/test_console_contentview.py @@ -1,3 +1,8 @@ +import os +from nose.plugins.skip import SkipTest +if os.name == "nt": + raise SkipTest("Skipped on Windows.") + import sys import libmproxy.console.contentview as cv from libmproxy import utils, flow, encoding diff --git a/test/test_console_help.py b/test/test_console_help.py index 98e202ad..6e1f9fad 100644 --- a/test/test_console_help.py +++ b/test/test_console_help.py @@ -1,3 +1,8 @@ +import os +from nose.plugins.skip import SkipTest +if os.name == "nt": + raise SkipTest("Skipped on Windows.") + import libmproxy.console.help as help class DummyMaster: diff --git a/test/test_dump.py b/test/test_dump.py index 6a35cdec..ccfa9189 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -43,6 +43,7 @@ class TestDumpMaster: m = dump.DumpMaster(None, o, filt, outfile=cs) for i in range(n): self._cycle(m, content) + m.shutdown() return cs.getvalue() def _flowfile(self, path): @@ -143,7 +144,7 @@ class TestDumpMaster: def test_script(self): ret = self._dummy_cycle( 1, None, "", - script=tutils.test_data.path("scripts/all.py"), verbosity=0, eventlog=True + scripts=[[tutils.test_data.path("scripts/all.py")]], verbosity=0, eventlog=True ) assert "XCLIENTCONNECT" in ret assert "XREQUEST" in ret @@ -151,11 +152,11 @@ class TestDumpMaster: assert "XCLIENTDISCONNECT" in ret tutils.raises( dump.DumpError, - self._dummy_cycle, 1, None, "", script="nonexistent" + self._dummy_cycle, 1, None, "", scripts=[["nonexistent"]] ) tutils.raises( dump.DumpError, - self._dummy_cycle, 1, None, "", script="starterr.py" + self._dummy_cycle, 1, None, "", scripts=[["starterr.py"]] ) def test_stickycookie(self): diff --git a/test/test_flow.py b/test/test_flow.py index 21d64f95..eacd7c25 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -542,12 +542,12 @@ class TestFlowMaster: def test_load_script(self): s = flow.State() fm = flow.FlowMaster(None, s) - assert not fm.load_script(tutils.test_data.path("scripts/a.py")) - assert not fm.load_script(tutils.test_data.path("scripts/a.py")) + assert not fm.load_script([tutils.test_data.path("scripts/a.py")]) + assert not fm.load_script([tutils.test_data.path("scripts/a.py")]) assert not fm.unload_script(fm.scripts[0]) assert not fm.unload_script(fm.scripts[0]) - assert fm.load_script("nonexistent") - assert "ValueError" in fm.load_script(tutils.test_data.path("scripts/starterr.py")) + assert fm.load_script(["nonexistent"]) + assert "ValueError" in fm.load_script([tutils.test_data.path("scripts/starterr.py")]) assert len(fm.scripts) == 0 def test_replay(self): @@ -563,7 +563,7 @@ class TestFlowMaster: def test_script_reqerr(self): s = flow.State() fm = flow.FlowMaster(None, s) - assert not fm.load_script(tutils.test_data.path("scripts/reqerr.py")) + assert not fm.load_script([tutils.test_data.path("scripts/reqerr.py")]) req = tutils.treq() fm.handle_clientconnect(req.client_conn) assert fm.handle_request(req) @@ -571,7 +571,7 @@ class TestFlowMaster: def test_script(self): s = flow.State() fm = flow.FlowMaster(None, s) - assert not fm.load_script(tutils.test_data.path("scripts/all.py")) + assert not fm.load_script([tutils.test_data.path("scripts/all.py")]) req = tutils.treq() fm.handle_clientconnect(req.client_conn) assert fm.scripts[0].ns["log"][-1] == "clientconnect" @@ -581,7 +581,7 @@ class TestFlowMaster: fm.handle_response(resp) assert fm.scripts[0].ns["log"][-1] == "response" #load second script - assert not fm.load_script(tutils.test_data.path("scripts/all.py")) + assert not fm.load_script([tutils.test_data.path("scripts/all.py")]) assert len(fm.scripts) == 2 dc = flow.ClientDisconnect(req.client_conn) dc.reply = controller.DummyReply() @@ -634,7 +634,7 @@ class TestFlowMaster: err.reply = controller.DummyReply() fm.handle_error(err) - fm.load_script(tutils.test_data.path("scripts/a.py")) + fm.load_script([tutils.test_data.path("scripts/a.py")]) fm.shutdown() def test_client_playback(self): |