@@ -624,65 +624,25 @@ def _call_fut(self, *args, **kwargs):
624624
625625 def test_it (self ):
626626 from six .moves import http_client
627- from google .cloud import _helpers as MUT
628-
629- SSL_CREDS = object ()
630- METADATA_CREDS = object ()
631- COMPOSITE_CREDS = object ()
632- CHANNEL = object ()
633-
634- class _GRPCModule (object ):
635-
636- def __init__ (self ):
637- self .ssl_channel_credentials_args = None
638- self .metadata_call_credentials_args = None
639- self .composite_channel_credentials_args = None
640- self .secure_channel_args = None
641-
642- def ssl_channel_credentials (self , * args ):
643- self .ssl_channel_credentials_args = args
644- return SSL_CREDS
645-
646- def metadata_call_credentials (self , * args , ** kwargs ):
647- self .metadata_call_credentials_args = (args , kwargs )
648- return METADATA_CREDS
649-
650- def composite_channel_credentials (self , * args ):
651- self .composite_channel_credentials_args = args
652- return COMPOSITE_CREDS
653627
654- def secure_channel (self , * args , ** kwargs ):
655- self .secure_channel_args = (args , kwargs )
656- return CHANNEL
657-
658- grpc_mod = _GRPCModule ()
659-
660- host = 'HOST'
661628 credentials = object ()
629+ host = 'HOST'
662630 user_agent = 'USER_AGENT'
663631
664- grpc_patch = mock .patch . object ( MUT , 'grpc' , new = grpc_mod )
665- request_patch = mock . patch ( 'google_auth_httplib2.Request' )
666- plugin_patch = mock . patch . object (
667- MUT , 'AuthMetadataPlugin' , create = True )
668- with grpc_patch , request_patch as request_mock , plugin_patch as plugin :
632+ secure_authorized_channel_patch = mock .patch (
633+ 'google.auth.transport.grpc.secure_authorized_channel' ,
634+ autospec = True )
635+
636+ with secure_authorized_channel_patch as secure_authorized_channel :
669637 result = self ._call_fut (credentials , user_agent , host )
670638
671- self .assertIs (result , CHANNEL )
672- plugin .assert_called_once_with (credentials , request_mock .return_value )
673- self .assertEqual (grpc_mod .ssl_channel_credentials_args , ())
674- self .assertEqual (grpc_mod .metadata_call_credentials_args ,
675- ((plugin .return_value ,), {'name' : 'google_creds' }))
676- self .assertEqual (
677- grpc_mod .composite_channel_credentials_args ,
678- (SSL_CREDS , METADATA_CREDS ))
679- target = '%s:%d' % (host , http_client .HTTPS_PORT )
680- secure_args = (target , COMPOSITE_CREDS )
681- secure_kwargs = {
682- 'options' : (('grpc.primary_user_agent' , user_agent ),)
683- }
684- self .assertEqual (grpc_mod .secure_channel_args ,
685- (secure_args , secure_kwargs ))
639+ self .assertIs (result , secure_authorized_channel .return_value )
640+
641+ expected_target = '%s:%d' % (host , http_client .HTTPS_PORT )
642+ expected_options = (('grpc.primary_user_agent' , user_agent ),)
643+
644+ secure_authorized_channel .assert_called_once_with (
645+ credentials , mock .ANY , expected_target , options = expected_options )
686646
687647
688648class Test_make_secure_stub (unittest .TestCase ):
0 commit comments