aboutsummaryrefslogtreecommitdiffstats
path: root/test/mitmproxy/test_taddons.py
blob: 5a4c99fc906ae7eb913ae68b24f9b76ec45804e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import io
from mitmproxy.test import taddons
from mitmproxy.test import tutils
from mitmproxy import ctx


def test_recordingmaster():
    with taddons.context() as tctx:
        assert not tctx.master.has_log("nonexistent")
        assert not tctx.master.has_event("nonexistent")
        ctx.log.error("foo")
        assert not tctx.master.has_log("foo", level="debug")
        assert tctx.master.has_log("foo", level="error")


def test_dumplog():
    with taddons.context() as tctx:
        ctx.log.info("testing")
        s = io.StringIO()
        tctx.master.dump_log(s)
        assert s.getvalue()


def test_load_script():
    with taddons.context() as tctx:
        s = tctx.script(
            tutils.test_data.path(
                "mitmproxy/data/addonscripts/recorder/recorder.py"
            )
        )
        assert s