From a92017a6c1a0d7cf20f53e1cb4eb24716aaf55e6 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 29 Apr 2017 11:02:36 +1200 Subject: Rework client and server replay - Add client.replay [flows], client.replay.stop - Add server.replay [flows], server.replay.stop - The corresponding options for file loading are only read on startup, further changes are ignored. In interactive contexts, replay is started with the commands, not through option changes. - Deprecate flow.replay, use replay.client instead --- test/mitmproxy/addons/test_clientplayback.py | 9 ++++++++- test/mitmproxy/addons/test_core.py | 10 ---------- test/mitmproxy/addons/test_serverplayback.py | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/mitmproxy/addons/test_clientplayback.py b/test/mitmproxy/addons/test_clientplayback.py index f71662f0..843d7409 100644 --- a/test/mitmproxy/addons/test_clientplayback.py +++ b/test/mitmproxy/addons/test_clientplayback.py @@ -26,7 +26,7 @@ class TestClientPlayback: with taddons.context() as tctx: assert cp.count() == 0 f = tflow.tflow(resp=True) - cp.load([f]) + cp.start_replay([f]) assert cp.count() == 1 RP = "mitmproxy.proxy.protocol.http_replay.RequestReplayThread" with mock.patch(RP) as rp: @@ -44,13 +44,20 @@ class TestClientPlayback: cp.tick() assert cp.current_thread is None + cp.start_replay([f]) + cp.stop_replay() + assert not cp.flows + def test_configure(self, tmpdir): cp = clientplayback.ClientPlayback() with taddons.context() as tctx: path = str(tmpdir.join("flows")) tdump(path, [tflow.tflow()]) tctx.configure(cp, client_replay=[path]) + cp.configured = False tctx.configure(cp, client_replay=[]) + cp.configured = False tctx.configure(cp) + cp.configured = False with pytest.raises(exceptions.OptionsError): tctx.configure(cp, client_replay=["nonexistent"]) diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 9501fb22..25fefb5d 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -3,7 +3,6 @@ from mitmproxy.test import taddons from mitmproxy.test import tflow from mitmproxy import exceptions import pytest -from unittest import mock def test_set(): @@ -43,15 +42,6 @@ def test_mark(): assert f.marked -def test_replay(): - sa = core.Core() - with taddons.context(): - f = tflow.tflow() - with mock.patch("mitmproxy.master.Master.replay_request") as rp: - sa.replay(f) - assert rp.called - - def test_kill(): sa = core.Core() with taddons.context(): diff --git a/test/mitmproxy/addons/test_serverplayback.py b/test/mitmproxy/addons/test_serverplayback.py index 29de48a0..e0c025fe 100644 --- a/test/mitmproxy/addons/test_serverplayback.py +++ b/test/mitmproxy/addons/test_serverplayback.py @@ -22,6 +22,7 @@ def test_config(tmpdir): fpath = str(tmpdir.join("flows")) tdump(fpath, [tflow.tflow(resp=True)]) tctx.configure(s, server_replay=[fpath]) + s.configured = False with pytest.raises(exceptions.OptionsError): tctx.configure(s, server_replay=[str(tmpdir)]) -- cgit v1.2.3