Test the dispatch of methods, with a variety of bindings.
()
| 5 | |
| 6 | |
| 7 | def test_simple_methods(): |
| 8 | """Test the dispatch of methods, with a variety of bindings. |
| 9 | """ |
| 10 | call_list = [] |
| 11 | p = Plugin(autopatch=False) |
| 12 | |
| 13 | @p.method("test1") |
| 14 | def test1(name): |
| 15 | """Has a single positional argument.""" |
| 16 | assert name == 'World' |
| 17 | call_list.append(test1) |
| 18 | request = p._parse_request({ |
| 19 | 'id': 1, |
| 20 | 'jsonrpc': '2.0', |
| 21 | 'method': 'test1', |
| 22 | 'params': {'name': 'World'} |
| 23 | }) |
| 24 | p._dispatch_request(request) |
| 25 | assert call_list == [test1] |
| 26 | |
| 27 | @p.method("test2") |
| 28 | def test2(name, plugin): |
| 29 | """Also asks for the plugin instance. """ |
| 30 | assert plugin == p |
| 31 | call_list.append(test2) |
| 32 | request = p._parse_request({ |
| 33 | 'id': 1, |
| 34 | 'jsonrpc': '2.0', |
| 35 | 'method': 'test2', |
| 36 | 'params': {'name': 'World'} |
| 37 | }) |
| 38 | p._dispatch_request(request) |
| 39 | assert call_list == [test1, test2] |
| 40 | |
| 41 | @p.method("test3") |
| 42 | def test3(name, request): |
| 43 | """Also asks for the request instance. """ |
| 44 | assert request is not None |
| 45 | call_list.append(test3) |
| 46 | request = p._parse_request({ |
| 47 | 'id': 1, |
| 48 | 'jsonrpc': '2.0', |
| 49 | 'method': 'test3', |
| 50 | 'params': {'name': 'World'} |
| 51 | }) |
| 52 | p._dispatch_request(request) |
| 53 | assert call_list == [test1, test2, test3] |
| 54 | |
| 55 | @p.method("test4") |
| 56 | def test4(name): |
| 57 | """Try the positional arguments.""" |
| 58 | assert name == 'World' |
| 59 | call_list.append(test4) |
| 60 | request = p._parse_request({ |
| 61 | 'id': 1, |
| 62 | 'jsonrpc': '2.0', |
| 63 | 'method': 'test4', |
| 64 | 'params': ['World'] |
nothing calls this directly
no test coverage detected