-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b57ee1
commit b78db53
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Code generated by river.codegen. DO NOT EDIT. | ||
from pydantic import BaseModel | ||
from typing import Literal | ||
|
||
import replit_river as river | ||
|
||
|
||
from .test_service import Test_ServiceService | ||
|
||
|
||
class RpcClient: | ||
def __init__(self, client: river.Client[Literal[None]]): | ||
self.test_service = Test_ServiceService(client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Code generated by river.codegen. DO NOT EDIT. | ||
from collections.abc import AsyncIterable, AsyncIterator | ||
from typing import Any | ||
import datetime | ||
|
||
from pydantic import TypeAdapter | ||
|
||
from replit_river.error_schema import RiverError | ||
import replit_river as river | ||
|
||
|
||
from .rpc_method import encode_Rpc_MethodInput, Rpc_MethodInput, Rpc_MethodOutput | ||
|
||
|
||
class Test_ServiceService: | ||
def __init__(self, client: river.Client[Any]): | ||
self.client = client | ||
|
||
async def rpc_method( | ||
self, | ||
input: Rpc_MethodInput, | ||
timeout: datetime.timedelta, | ||
) -> Rpc_MethodOutput: | ||
return await self.client.send_rpc( | ||
'test_service', | ||
'rpc_method', | ||
input, | ||
encode_Rpc_MethodInput, | ||
lambda x: TypeAdapter(Rpc_MethodOutput).validate_python( | ||
x # type: ignore[arg-type] | ||
), | ||
lambda x: TypeAdapter(RiverError).validate_python( | ||
x # type: ignore[arg-type] | ||
), | ||
timeout, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# ruff: noqa | ||
# Code generated by river.codegen. DO NOT EDIT. | ||
from collections.abc import AsyncIterable, AsyncIterator | ||
import datetime | ||
from typing import ( | ||
Any, | ||
Callable, | ||
Dict, | ||
List, | ||
Literal, | ||
Optional, | ||
Mapping, | ||
Union, | ||
Tuple, | ||
TypedDict, | ||
) | ||
|
||
from pydantic import BaseModel, Field, TypeAdapter | ||
from replit_river.error_schema import RiverError | ||
|
||
import replit_river as river | ||
|
||
|
||
encode_Rpc_MethodInput: Callable[['Rpc_MethodInput'], Any] = lambda x: { | ||
k: v | ||
for (k, v) in ( | ||
{ | ||
'data': x.get('data'), | ||
} | ||
).items() | ||
if v is not None | ||
} | ||
|
||
|
||
class Rpc_MethodInput(TypedDict): | ||
data: str | ||
|
||
|
||
class Rpc_MethodOutput(BaseModel): | ||
data: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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_basic_rpc(client: Client) -> None: | ||
schema_to_river_client_codegen( | ||
"tests/codegen/rpc/schema.json", "tests/codegen/rpc/generated", "RpcClient", True | ||
) | ||
from tests.codegen.rpc.generated import RpcClient | ||
|
||
res = await RpcClient(client).test_service.rpc_method( | ||
{ | ||
"data": "feep", | ||
}, | ||
timedelta(seconds=5), | ||
) | ||
assert res.data == "Hello, feep!", f"Expected 'Hello, feep!' received {res.data}" |