def test_google_call_credentials_success(self): callback_event = threading.Event() def mock_callback(metadata, error): self.assertEqual(metadata, (('authorization', 'Bearer token'), )) self.assertIsNone(error) callback_event.set() call_creds = _auth.AccessTokenCallCredentials('token') call_creds(None, mock_callback) self.assertTrue(callback_event.wait(1.0))
def access_token_call_credentials(access_token): """Construct CallCredentials from an access token. Args: access_token: A string to place directly in the http request authorization header, ie "Authorization: Bearer <access_token>". Returns: A CallCredentials. """ from grpc import _auth return metadata_call_credentials( _auth.AccessTokenCallCredentials(access_token))