diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-07-23 11:38:45 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-07-23 11:38:45 +1200 |
commit | b5416895f5157d0191c3967850be576450ec2d7d (patch) | |
tree | a61379f7e5721c4d35a07ddcd05986fcef61576b /test | |
parent | 9294d19f908cdde86b390fb2fa93aad422da8522 (diff) | |
download | mitmproxy-b5416895f5157d0191c3967850be576450ec2d7d.tar.gz mitmproxy-b5416895f5157d0191c3967850be576450ec2d7d.tar.bz2 mitmproxy-b5416895f5157d0191c3967850be576450ec2d7d.zip |
script: convert test recorder to an addon class
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/builtins/test_script.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/data/addonscripts/recorder.py | 36 |
2 files changed, 19 insertions, 19 deletions
diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/builtins/test_script.py index 3f07b576..826d2a91 100644 --- a/test/mitmproxy/builtins/test_script.py +++ b/test/mitmproxy/builtins/test_script.py @@ -48,7 +48,7 @@ def test_load_script(): "data/addonscripts/recorder.py" ), [] ) - assert ns.configure + assert ns.start class TestScript(mastertest.MasterTest): diff --git a/test/mitmproxy/data/addonscripts/recorder.py b/test/mitmproxy/data/addonscripts/recorder.py index b6ac8d89..890e6f4e 100644 --- a/test/mitmproxy/data/addonscripts/recorder.py +++ b/test/mitmproxy/data/addonscripts/recorder.py @@ -2,24 +2,24 @@ from mitmproxy import controller from mitmproxy import ctx import sys -call_log = [] -if len(sys.argv) > 1: - name = sys.argv[1] -else: - name = "solo" +class CallLogger: + call_log = [] -# Keep a log of all possible event calls -evts = list(controller.Events) + ["configure"] -for i in evts: - def mkprox(): - evt = i + def __init__(self, name = "solo"): + self.name = name - def prox(*args, **kwargs): - lg = (name, evt, args, kwargs) - if evt != "log": - ctx.log.info(str(lg)) - call_log.append(lg) - ctx.log.debug("%s %s" % (name, evt)) - return prox - globals()[i] = mkprox() + def __getattr__(self, attr): + if attr in controller.Events: + def prox(*args, **kwargs): + lg = (self.name, attr, args, kwargs) + if attr != "log": + ctx.log.info(str(lg)) + self.call_log.append(lg) + ctx.log.debug("%s %s" % (self.name, attr)) + return prox + raise AttributeError + + +def start(): + return CallLogger(*sys.argv[1:]) |