Skip to content

Commit d94c7b1

Browse files
Adding an RPC codegen test
1 parent 89164f4 commit d94c7b1

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/codegen/rpc/schema.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"services": {
3+
"test_service": {
4+
"procedures": {
5+
"rpc_method": {
6+
"input": {
7+
"type": "object",
8+
"properties": {
9+
"data": {
10+
"type": "string"
11+
}
12+
},
13+
"required": ["data"]
14+
},
15+
"output": {
16+
"type": "object",
17+
"properties": {
18+
"data": {
19+
"type": "string"
20+
}
21+
},
22+
"required": ["data"]
23+
},
24+
"errors": {
25+
"not": {}
26+
},
27+
"type": "rpc"
28+
}
29+
}
30+
}
31+
}
32+
}

tests/codegen/test_rpc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from datetime import timedelta
2+
3+
import pytest
4+
5+
from replit_river.client import Client
6+
from replit_river.codegen.client import schema_to_river_client_codegen
7+
from tests.common_handlers import basic_rpc_method
8+
9+
10+
@pytest.mark.asyncio
11+
@pytest.mark.parametrize("handlers", [{**basic_rpc_method}])
12+
async def test_foo(client: Client):
13+
schema_to_river_client_codegen(
14+
"tests/codegen/rpc/schema.json", "tests/codegen/dist/rpc", "RpcClient", True
15+
)
16+
from tests.codegen.dist.rpc import RpcClient
17+
18+
name = "feep"
19+
_c = RpcClient(client)
20+
res = await _c.test_service.rpc_method({
21+
"data": name,
22+
}, timedelta(seconds=5))
23+
assert res.data == "Hello, feep!", f"Expected 'Hello, {name}!' received {res.data}"

0 commit comments

Comments
 (0)