def intercepted_echo(): # The interceptor adds 'showcase-trailer' client metadata. Showcase server # echos any metadata with key 'showcase-trailer', so the same metadata # should appear as trailing metadata in the response. interceptor = MetadataClientInterceptor('showcase-trailer', 'intercepted') channel = grpc.insecure_channel('localhost:7469') intercept_channel = grpc.intercept_channel(channel, interceptor) transport = EchoClient.get_transport_class('grpc')( channel=intercept_channel, ) return EchoClient(transport=transport)
def intercepted_echo(use_mtls): # The interceptor adds 'showcase-trailer' client metadata. Showcase server # echos any metadata with key 'showcase-trailer', so the same metadata # should appear as trailing metadata in the response. interceptor = MetadataClientInterceptor("showcase-trailer", "intercepted") host = "localhost:7469" channel = (grpc.secure_channel(host, ssl_credentials) if use_mtls else grpc.insecure_channel(host)) intercept_channel = grpc.intercept_channel(channel, interceptor) transport = EchoClient.get_transport_class("grpc")( channel=intercept_channel) return EchoClient(transport=transport)
def test_sample(): ssl_credentials = grpc.ssl_channel_credentials(root_certificates=cert, certificate_chain=cert, private_key=key) with mock.patch("grpc.ssl_channel_credentials", autospec=True) as mock_ssl_cred: mock_ssl_cred.return_value = ssl_credentials client = EchoClient( credentials=credentials.AnonymousCredentials(), client_options=client_options, ) mock_ssl_cred.assert_called_once_with(certificate_chain=cert, private_key=key) response = client.echo( showcase.EchoRequest( content="The hail in Wales falls mainly on the snails.")) assert response.content == "The hail in Wales falls mainly on the snails."
def echo(): transport = EchoClient.get_transport_class('grpc')( channel=grpc.insecure_channel('localhost:7469'), ) return EchoClient(transport=transport)