aboutsummaryrefslogtreecommitdiffstats
path: root/test/mitmproxy/tools/console/test_keymap.py
blob: 6a75800ef4b1ceb5cb29f4ae1e015893289e86af (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
from mitmproxy.tools.console import keymap
from mitmproxy.test import taddons
from unittest import mock
import pytest


def test_bind():
        with taddons.context() as tctx:
            km = keymap.Keymap(tctx.master)
            km.executor = mock.Mock()

            with pytest.raises(ValueError):
                km.add("foo", "bar", ["unsupported"])

            km.add("key", "str", ["options", "commands"])
            assert km.get("options", "key")
            assert km.get("commands", "key")
            assert not km.get("flowlist", "key")

            km.handle("unknown", "unknown")
            assert not km.executor.called

            km.handle("options", "key")
            assert km.executor.called

            km.add("glob", "str", ["global"])
            km.executor = mock.Mock()
            km.handle("options", "glob")
            assert km.executor.called