-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest_async_main.py
47 lines (35 loc) · 1.19 KB
/
test_async_main.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pytest
from oslash.either import Right
from jsonrpcserver.async_main import (
dispatch_to_response,
dispatch_to_serializable,
dispatch_to_json,
)
from jsonrpcserver.response import SuccessResponse
from jsonrpcserver.result import Result, Success
async def ping() -> Result:
return Success("pong")
@pytest.mark.asyncio
async def test_dispatch_to_response():
assert await dispatch_to_response(
'{"jsonrpc": "2.0", "method": "ping", "id": 1}', {"ping": ping}
) == Right(SuccessResponse("pong", 1))
@pytest.mark.asyncio
async def test_dispatch_to_serializable():
assert await dispatch_to_serializable(
'{"jsonrpc": "2.0", "method": "ping", "id": 1}', {"ping": ping}
) == {"jsonrpc": "2.0", "result": "pong", "id": 1}
@pytest.mark.asyncio
async def test_dispatch_to_json():
assert (
await dispatch_to_json(
'{"jsonrpc": "2.0", "method": "ping", "id": 1}', {"ping": ping}
)
== '{"jsonrpc": "2.0", "result": "pong", "id": 1}'
)
@pytest.mark.asyncio
async def test_dispatch_to_json_notification():
assert (
await dispatch_to_json('{"jsonrpc": "2.0", "method": "ping"}', {"ping": ping})
== ""
)