diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-08-18 01:47:39 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-08-18 01:47:39 +0200 |
commit | 94fbf066f772032d9ccfdf351c2e50c1488c1d68 (patch) | |
tree | ce9e3ea859c2c15f07c6d639d31782f541cf5ae3 /test/test_script.py | |
parent | 5b7e19a77e12ffac2e699d2dc92f96f90114ee01 (diff) | |
download | mitmproxy-94fbf066f772032d9ccfdf351c2e50c1488c1d68.tar.gz mitmproxy-94fbf066f772032d9ccfdf351c2e50c1488c1d68.tar.bz2 mitmproxy-94fbf066f772032d9ccfdf351c2e50c1488c1d68.zip |
fix script tests
Diffstat (limited to 'test/test_script.py')
-rw-r--r-- | test/test_script.py | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/test/test_script.py b/test/test_script.py index 13903066..587c52d6 100644 --- a/test/test_script.py +++ b/test/test_script.py @@ -73,7 +73,7 @@ class TestScript: r2.reply() # Two instantiations - assert m.call_count == 2 + assert m.call_count == 0 # No calls yet. assert (time.time() - t_start) < 0.09 def test_concurrent2(self): @@ -81,22 +81,29 @@ class TestScript: fm = flow.FlowMaster(None, s) s = script.Script(tutils.test_data.path("scripts/concurrent_decorator.py"), fm) s.load() - f = tutils.tflow_full() - f.error = tutils.terr(f.request) - f.reply = f.request.reply - - with mock.patch("libmproxy.controller.DummyReply.__call__") as m: - t_start = time.time() - s.run("clientconnect", f) - s.run("serverconnect", f) - s.run("response", f) - s.run("error", f) - s.run("clientdisconnect", f) - while (time.time() - t_start) < 1 and m.call_count <= 5: - if m.call_count == 5: - return - time.sleep(0.001) - assert False + m = mock.Mock() + + class Dummy: + def __init__(self): + self.response = self + self.error = self + self.reply = m + + t_start = time.time() + + for hook in ("clientconnect", + "serverconnect", + "response", + "error", + "clientconnect"): + d = Dummy() + assert s.run(hook, d)[0] + d.reply() + while (time.time() - t_start) < 5 and m.call_count <= 5: + if m.call_count == 5: + return + time.sleep(0.001) + assert False def test_concurrent_err(self): s = flow.State() |