diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/scripts/a | 9 | ||||
-rw-r--r-- | test/scripts/a.py (renamed from test/plugins/a.py) | 0 | ||||
-rwxr-xr-x | test/scripts/err_data | 2 | ||||
-rwxr-xr-x | test/scripts/err_return | 6 | ||||
-rw-r--r-- | test/scripts/loaderr.py | 3 | ||||
-rw-r--r-- | test/scripts/nonexecutable | 0 | ||||
-rw-r--r-- | test/scripts/syntaxerr.py (renamed from test/plugins/syntaxerr.py) | 0 | ||||
-rw-r--r-- | test/test_plugins.py | 35 | ||||
-rw-r--r-- | test/test_proxy.py | 2 | ||||
-rw-r--r-- | test/test_script.py | 51 |
10 files changed, 55 insertions, 53 deletions
diff --git a/test/scripts/a b/test/scripts/a deleted file mode 100755 index fb4a7b82..00000000 --- a/test/scripts/a +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python -import sys -sys.path.insert(0, "..") -from libmproxy import script - -f = script.load_flow() -f.request.host = "TESTOK" -print >> sys.stderr, "DEBUG" -script.return_flow(f) diff --git a/test/plugins/a.py b/test/scripts/a.py index 0a21b619..0a21b619 100644 --- a/test/plugins/a.py +++ b/test/scripts/a.py diff --git a/test/scripts/err_data b/test/scripts/err_data deleted file mode 100755 index 4bb1b1ba..00000000 --- a/test/scripts/err_data +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python -print "NONSENSE" diff --git a/test/scripts/err_return b/test/scripts/err_return deleted file mode 100755 index 09e9eb5e..00000000 --- a/test/scripts/err_return +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python -import sys -sys.path.insert(0, "..") -print >> sys.stderr, "output" -sys.exit(1) - diff --git a/test/scripts/loaderr.py b/test/scripts/loaderr.py new file mode 100644 index 00000000..8dc4d56d --- /dev/null +++ b/test/scripts/loaderr.py @@ -0,0 +1,3 @@ + + +a = x diff --git a/test/scripts/nonexecutable b/test/scripts/nonexecutable deleted file mode 100644 index e69de29b..00000000 --- a/test/scripts/nonexecutable +++ /dev/null diff --git a/test/plugins/syntaxerr.py b/test/scripts/syntaxerr.py index 219d6b84..219d6b84 100644 --- a/test/plugins/syntaxerr.py +++ b/test/scripts/syntaxerr.py diff --git a/test/test_plugins.py b/test/test_plugins.py deleted file mode 100644 index 135d93ce..00000000 --- a/test/test_plugins.py +++ /dev/null @@ -1,35 +0,0 @@ -import os -from libmproxy import plugins, flow -import libpry - -class uPlugin(libpry.AutoTree): - def test_simple(self): - s = flow.State() - fm = flow.FlowMaster(None, s) - - p = plugins.Plugin(os.path.join("plugins", "a.py"), fm) - assert "here" in p.ns - assert p.run("here") == (True, 1) - assert p.run("here") == (True, 2) - - ret = p.run("errargs") - assert not ret[0] - assert len(ret[1]) == 2 - - # Check reload - p.load() - assert p.run("here") == (True, 1) - - def test_err(self): - s = flow.State() - fm = flow.FlowMaster(None, s) - - libpry.raises(IOError, plugins.Plugin, "nonexistent", fm) - libpry.raises(SyntaxError, plugins.Plugin, os.path.join("plugins", "syntaxerr.py"), fm) - - - -tests = [ - uPlugin(), -] - diff --git a/test/test_proxy.py b/test/test_proxy.py index 83898d11..196942b3 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -1,6 +1,6 @@ import cStringIO, time, re import libpry -from libmproxy import proxy, controller, utils, dump, script +from libmproxy import proxy, controller, utils, dump import email.utils import tutils diff --git a/test/test_script.py b/test/test_script.py new file mode 100644 index 00000000..f6cfcced --- /dev/null +++ b/test/test_script.py @@ -0,0 +1,51 @@ +import os +from libmproxy import script, flow +import libpry + +class uScript(libpry.AutoTree): + def test_simple(self): + s = flow.State() + fm = flow.FlowMaster(None, s) + + p = script.Script(os.path.join("scripts", "a.py"), fm) + p.load() + assert "here" in p.ns + assert p.run("here") == (True, 1) + assert p.run("here") == (True, 2) + + ret = p.run("errargs") + assert not ret[0] + assert len(ret[1]) == 2 + + # Check reload + p.load() + assert p.run("here") == (True, 1) + + def test_err(self): + s = flow.State() + fm = flow.FlowMaster(None, s) + + s = script.Script("nonexistent", fm) + libpry.raises( + script.ScriptError, + s.load + ) + + s = script.Script(os.path.join("scripts", "syntaxerr.py"), fm) + libpry.raises( + script.ScriptError, + s.load + ) + + s = script.Script(os.path.join("scripts", "loaderr.py"), fm) + libpry.raises( + script.ScriptError, + s.load + ) + + + +tests = [ + uScript(), +] + |