Skip to content

Commit

Permalink
Adding an RPC codegen test
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Nov 29, 2024
1 parent b315dfb commit 1bb4d4b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/codegen/rpc/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"services": {
"test_service": {
"procedures": {
"rpc_method": {
"input": {
"type": "object",
"properties": {
"data": {
"type": "string"
}
},
"required": ["data"]
},
"output": {
"type": "object",
"properties": {
"data": {
"type": "string"
}
},
"required": ["data"]
},
"errors": {
"not": {}
},
"type": "rpc"
}
}
}
}
}
23 changes: 23 additions & 0 deletions tests/codegen/test_rpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from datetime import timedelta

import pytest

from replit_river.client import Client
from replit_river.codegen.client import schema_to_river_client_codegen
from tests.common_handlers import basic_rpc_method


@pytest.mark.asyncio
@pytest.mark.parametrize("handlers", [{**basic_rpc_method}])
async def test_foo(client: Client):
schema_to_river_client_codegen(
"tests/codegen/rpc/schema.json", "tests/codegen/dist/rpc", "RpcClient", True
)
from tests.codegen.dist.rpc import RpcClient

name = "feep"
_c = RpcClient(client)
res = await _c.test_service.rpc_method({
"data": name,
}, timedelta(seconds=5))
assert res.data == "Hello, feep!", f"Expected 'Hello, {name}!' received {res.data}"

0 comments on commit 1bb4d4b

Please sign in to comment.