diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-02-25 12:19:54 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-02-25 12:19:54 +1300 |
commit | 986a41d1806eba2ad3d3746c9163cff9502b9482 (patch) | |
tree | a6d2fb25fb16876522c0275b90a8695039a0721d /test | |
parent | bcda65e45371b15fc57783c3d579492626d1d8ed (diff) | |
download | mitmproxy-986a41d1806eba2ad3d3746c9163cff9502b9482.tar.gz mitmproxy-986a41d1806eba2ad3d3746c9163cff9502b9482.tar.bz2 mitmproxy-986a41d1806eba2ad3d3746c9163cff9502b9482.zip |
Unit test++.
Diffstat (limited to 'test')
-rw-r--r-- | test/scripts/duplicate_flow.py | 5 | ||||
-rw-r--r-- | test/test_flow.py | 13 | ||||
-rw-r--r-- | test/test_proxy.py | 2 | ||||
-rw-r--r-- | test/test_script.py | 15 |
4 files changed, 30 insertions, 5 deletions
diff --git a/test/scripts/duplicate_flow.py b/test/scripts/duplicate_flow.py new file mode 100644 index 00000000..f1b92309 --- /dev/null +++ b/test/scripts/duplicate_flow.py @@ -0,0 +1,5 @@ + +def request(ctx, f): + f = ctx.duplicate_flow(f) + ctx.replay_request(f) + diff --git a/test/test_flow.py b/test/test_flow.py index ffcb6e25..67dfe3c2 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -143,6 +143,17 @@ class uFlow(libpry.AutoTree): assert not f.request is f2.request assert f.request.headers == f2.request.headers assert not f.request.headers is f2.request.headers + assert f.response == f2.response + assert not f.response is f2.response + + f = tutils.tflow_err() + f2 = f.copy() + assert not f is f2 + assert not f.request is f2.request + assert f.request.headers == f2.request.headers + assert not f.request.headers is f2.request.headers + assert f.error == f2.error + assert not f.error is f2.error def test_match(self): f = tutils.tflow() @@ -301,7 +312,6 @@ class uState(libpry.AutoTree): assert c.add_response(resp) assert c.active_flow_count() == 0 - def test_err(self): c = flow.State() req = tutils.treq() @@ -322,7 +332,6 @@ class uState(libpry.AutoTree): assert c.add_error(e) assert c.view - def test_set_limit(self): c = flow.State() diff --git a/test/test_proxy.py b/test/test_proxy.py index 22bcb6d4..fccef977 100644 --- a/test/test_proxy.py +++ b/test/test_proxy.py @@ -24,6 +24,7 @@ class u_read_chunked(libpry.AutoTree): class Dummy: pass + class u_read_http_body(libpry.AutoTree): def test_all(self): @@ -42,7 +43,6 @@ class u_read_http_body(libpry.AutoTree): s = cStringIO.StringIO("testing") libpry.raises(proxy.ProxyError, proxy.read_http_body, s, d, h, False, 4) - h = flow.ODict() s = cStringIO.StringIO("testing") assert len(proxy.read_http_body(s, d, h, True, 4)) == 4 diff --git a/test/test_script.py b/test/test_script.py index 32ee2d95..94f036d9 100644 --- a/test/test_script.py +++ b/test/test_script.py @@ -1,6 +1,7 @@ import os from libmproxy import script, flow import libpry +import tutils class uScript(libpry.AutoTree): def test_simple(self): @@ -13,15 +14,25 @@ class uScript(libpry.AutoTree): 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 not ret[0] assert len(ret[1]) == 2 # Check reload p.load() assert p.run("here") == (True, 1) + def test_duplicate_flow(self): + s = flow.State() + fm = flow.FlowMaster(None, s) + fm.load_script(os.path.join("scripts", "duplicate_flow.py")) + r = tutils.treq() + fm.handle_request(r) + assert fm.state.flow_count() == 2 + assert not fm.state.view[0].request.is_replay() + assert fm.state.view[1].request.is_replay() + def test_err(self): s = flow.State() fm = flow.FlowMaster(None, s) |