async def test_service_passes_through_unwrapped_values_embedded_in_response(): """ We do not not need to implement value unwrapping for embedded well-known types, as this is already handled by grpclib. This test merely shows that this is the case. """ output = Output( double_value=10.0, float_value=12.0, int64_value=-13, uint64_value=14, int32_value=-15, uint32_value=16, bool_value=True, string_value="string", bytes_value=bytes(0xFF)[0:4], ) service = TestStub(MockChannel(responses=[output])) response = await service.get_output() assert response.double_value == 10.0 assert response.float_value == 12.0 assert response.int64_value == -13 assert response.uint64_value == 14 assert response.int32_value == -15 assert response.uint32_value == 16 assert response.bool_value assert response.string_value == "string" assert response.bytes_value == bytes(0xFF)[0:4]
async def test_channel_receives_wrapped_type( service_method: Callable[[TestStub], Any], wrapper_class: Callable, value): wrapped_value = wrapper_class() wrapped_value.value = value channel = MockChannel(responses=[wrapped_value]) service = TestStub(channel) await service_method(service) assert channel.requests[0]["response_type"] != Optional[type(value)] assert channel.requests[0]["response_type"] == type(wrapped_value)
async def test_service_unwraps_response(service_method: Callable[[TestStub], Any], wrapper_class: Callable, value): """ grpclib does not unwrap wrapper values returned by services """ wrapped_value = wrapper_class() wrapped_value.value = value service = TestStub(MockChannel(responses=[wrapped_value])) response_value = await service_method(service) assert response_value == value assert type(response_value) == type(value)
def test_service_can_be_instantiated(test_data: TestData) -> None: plugin_module, _, json_data = test_data plugin_module.TestStub(MockChannel())
async def test_service_correctly_imports_reference_message(): mock_response = RequestResponse(value=10) service = TestStub(MockChannel([mock_response])) response = await service.do_thing() assert mock_response == response