Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Test case for object serde round-tripping #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/grpc/test_grpclib_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DoThingResponse,
GetThingRequest,
TestStub as ThingServiceClient,
ThingType,
)

from .thing_service import ThingService
Expand Down Expand Up @@ -52,6 +53,24 @@ async def test_simple_service_call():
async with ChannelFor([ThingService()]) as channel:
await _test_client(ThingServiceClient(channel))

@pytest.mark.asyncio
async def test_messages_roundtrip_with_default_fields():
async with ChannelFor([ThingService()]) as channel:
client = ThingServiceClient(channel)
request = DoThingRequest("name", ["comment"], ThingType.UNKNOWN, 0) # UNKNOWN and 0 are protobuf default values
response = await client.do_thing(request)

# Assert we get back the request
assert request == response.request
assert response.names == ["name"]
assert response.request.number == 0
assert response.request.type == ThingType.UNKNOWN
assert id(request) != id(response.request) # prove that objects went through serde

# Try with a newly construction request object
expected_request = DoThingRequest("name", ["comment"], ThingType.UNKNOWN, 0)
assert expected_request == response.request


@pytest.mark.asyncio
async def test_trailer_only_error_unary_unary(
Expand Down
2 changes: 1 addition & 1 deletion tests/grpc/thing_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def do_thing(
request = await stream.recv_message()
if self.test_hook is not None:
self.test_hook(stream)
await stream.send_message(DoThingResponse([request.name]))
await stream.send_message(DoThingResponse([request.name], request))

async def do_many_things(
self, stream: "grpclib.server.Stream[DoThingRequest, DoThingResponse]"
Expand Down
2 changes: 2 additions & 0 deletions tests/inputs/service/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ message DoThingRequest {
string name = 1;
repeated string comments = 2;
ThingType type = 3;
int32 number = 4;
}

message DoThingResponse {
repeated string names = 1;
DoThingRequest request = 2;
}

message GetThingRequest {
Expand Down