@@ -251,7 +251,28 @@ def messaging(use_mtls, request):
251251 return construct_client (MessagingClient , use_mtls , transport_name = request .param )
252252
253253
254- class MetadataClienGrpcInterceptor (
254+ class EchoMetadataClientRestInterceptor (EchoRestInterceptor ):
255+ request_metadata : Sequence [Tuple [str , str ]] = []
256+ response_metadata : Sequence [Tuple [str , str ]] = []
257+
258+ def pre_echo (self , request , metadata ):
259+ self .request_metadata = metadata
260+ return request , metadata
261+
262+ def post_echo_with_metadata (self , request , metadata ):
263+ self .response_metadata = metadata
264+ return request , metadata
265+
266+ def pre_expand (self , request , metadata ):
267+ self .request_metadata = metadata
268+ return request , metadata
269+
270+ def post_expand_with_metadata (self , request , metadata ):
271+ self .response_metadata = metadata
272+ return request , metadata
273+
274+
275+ class EchoMetadataClientGrpcInterceptor (
255276 grpc .UnaryUnaryClientInterceptor ,
256277 grpc .UnaryStreamClientInterceptor ,
257278 grpc .StreamUnaryClientInterceptor ,
@@ -295,7 +316,7 @@ def intercept_stream_stream(
295316 return response_it
296317
297318
298- class MetadataClientGrpcAsyncInterceptor (
319+ class EchoMetadataClientGrpcAsyncInterceptor (
299320 grpc .aio .UnaryUnaryClientInterceptor ,
300321 grpc .aio .UnaryStreamClientInterceptor ,
301322 grpc .aio .StreamUnaryClientInterceptor ,
@@ -339,33 +360,12 @@ async def intercept_stream_stream(
339360 return response_it
340361
341362
342- class EchoMetadataClientRestInterceptor (EchoRestInterceptor ):
343- request_metadata : Sequence [Tuple [str , str ]] = []
344- response_metadata : Sequence [Tuple [str , str ]] = []
345-
346- def pre_echo (self , request , metadata ):
347- self .request_metadata = metadata
348- return request , metadata
349-
350- def post_echo_with_metadata (self , request , metadata ):
351- self .response_metadata = metadata
352- return request , metadata
353-
354- def pre_expand (self , request , metadata ):
355- self .request_metadata = metadata
356- return request , metadata
357-
358- def post_expand_with_metadata (self , request , metadata ):
359- self .response_metadata = metadata
360- return request , metadata
361-
362-
363363@pytest .fixture
364364def intercepted_echo_grpc (use_mtls ):
365365 # The interceptor adds 'showcase-trailer' client metadata. Showcase server
366366 # echos any metadata with key 'showcase-trailer', so the same metadata
367367 # should appear as trailing metadata in the response.
368- interceptor = MetadataClienGrpcInterceptor (
368+ interceptor = EchoMetadataClientGrpcInterceptor (
369369 "showcase-trailer" ,
370370 "intercepted" ,
371371 )
@@ -383,28 +383,12 @@ def intercepted_echo_grpc(use_mtls):
383383 return EchoClient (transport = transport ), interceptor
384384
385385
386- @pytest .fixture
387- def intercepted_echo_rest ():
388- transport_name = "rest"
389- transport_cls = EchoClient .get_transport_class (transport_name )
390- interceptor = EchoMetadataClientRestInterceptor ()
391-
392- # The custom host explicitly bypasses https.
393- transport = transport_cls (
394- credentials = ga_credentials .AnonymousCredentials (),
395- host = "localhost:7469" ,
396- url_scheme = "http" ,
397- interceptor = interceptor ,
398- )
399- return EchoClient (transport = transport ), interceptor
400-
401-
402386@pytest .fixture
403387def intercepted_echo_grpc_async ():
404388 # The interceptor adds 'showcase-trailer' client metadata. Showcase server
405389 # echos any metadata with key 'showcase-trailer', so the same metadata
406390 # should appear as trailing metadata in the response.
407- interceptor = MetadataClientGrpcAsyncInterceptor (
391+ interceptor = EchoMetadataClientGrpcAsyncInterceptor (
408392 "showcase-trailer" ,
409393 "intercepted" ,
410394 )
@@ -416,3 +400,18 @@ def intercepted_echo_grpc_async():
416400 channel = channel ,
417401 )
418402 return EchoAsyncClient (transport = transport ), interceptor
403+
404+ @pytest .fixture
405+ def intercepted_echo_rest ():
406+ transport_name = "rest"
407+ transport_cls = EchoClient .get_transport_class (transport_name )
408+ interceptor = EchoMetadataClientRestInterceptor ()
409+
410+ # The custom host explicitly bypasses https.
411+ transport = transport_cls (
412+ credentials = ga_credentials .AnonymousCredentials (),
413+ host = "localhost:7469" ,
414+ url_scheme = "http" ,
415+ interceptor = interceptor ,
416+ )
417+ return EchoClient (transport = transport ), interceptor
0 commit comments