This fixes a bug where serialized_on_wire was not set when a message contained only repeated values (eg in a list or map). The fix here is to just set it to true in the `parse` method as soon as we receive any valid data. This also adds a test to expose the behavior.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from typing import Dict
|
|
|
|
import grpclib.const
|
|
import grpclib.server
|
|
import pytest
|
|
from grpclib.testing import ChannelFor
|
|
|
|
import betterproto
|
|
from betterproto.tests.output_betterproto.repeated.repeated import (
|
|
ExampleServiceStub,
|
|
Test,
|
|
)
|
|
|
|
|
|
class ExampleService:
|
|
async def DoThing(
|
|
self, stream: "grpclib.server.Stream[Test, Test]"
|
|
):
|
|
request = await stream.recv_message()
|
|
await stream.send_message(request)
|
|
|
|
def __mapping__(self) -> Dict[str, grpclib.const.Handler]:
|
|
return {
|
|
"/repeated.ExampleService/DoThing": grpclib.const.Handler(
|
|
self.DoThing,
|
|
grpclib.const.Cardinality.UNARY_UNARY,
|
|
Test,
|
|
Test,
|
|
),
|
|
}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_sets_serialized_on_wire() -> None:
|
|
async with ChannelFor([ExampleService()]) as channel:
|
|
stub = ExampleServiceStub(channel)
|
|
response = await stub.do_thing(names=['a', 'b', 'c'])
|
|
assert betterproto.serialized_on_wire(response)
|
|
assert response.names == ['a', 'b', 'c']
|