Skip to content

Commit 4536c26

Browse files
committed
Fix serializer issue
1 parent 4255f4e commit 4536c26

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tests/test_serializer.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
from typing import Any, NamedTuple
22

3+
import pytest
4+
from aiohttp.web import Application
35
from wsrpc_aiohttp import WSRPCClient, serializer
46
from wsrpc_aiohttp.websocket.tools import json_dumps
57

68

7-
async def test_call_error(client: WSRPCClient, handler):
8-
9+
@pytest.fixture
10+
def application(handler, socket_path):
11+
app = Application()
912
handler.configure(dumps=json_dumps)
13+
app.router.add_route("*", socket_path, handler)
14+
return app
15+
1016

11-
class CustomType(NamedTuple):
17+
async def test_call_error(client: WSRPCClient, handler):
18+
class CustomType:
1219
name: str
1320
value: Any
1421

22+
def __init__(self, name, value):
23+
self.name = name
24+
self.value = value
25+
1526
@serializer.register(CustomType)
16-
def _serizlize(value: CustomType):
27+
def _serialize(value: CustomType):
1728
return {
1829
"custom_type": {
1930
"name": value.name,
20-
"value": serializer(value.value),
31+
"value": value.value,
2132
},
2233
}
2334

35+
assert serializer(CustomType("foo", "bar")) == {
36+
"custom_type": {"name": "foo", "value": "bar"}
37+
}
38+
2439
async def handle_request(_):
2540
return CustomType(name="the answer", value=42)
2641

@@ -29,4 +44,4 @@ async def handle_request(_):
2944
async with client:
3045
result = await client.call("send_custom")
3146

32-
assert result
47+
assert result == {"custom_type": {"name": "the answer", "value": 42}}

0 commit comments

Comments
 (0)