diff --git a/ChangeLog b/ChangeLog index fda79e1f9..7bacda0a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +* 32.0.0 +- Remove validation checking if developer token is present in configuration. +- Remove `use_cloud_org_for_api_access` configuration option. + * 31.4.0 - Google Ads API v25_1 release. diff --git a/google/ads/googleads/__init__.py b/google/ads/googleads/__init__.py index b7e9f6a93..ed3f5536b 100644 --- a/google/ads/googleads/__init__.py +++ b/google/ads/googleads/__init__.py @@ -19,7 +19,7 @@ import google.ads.googleads.errors import google.ads.googleads.util -VERSION = "31.4.0" +VERSION = "32.0.0" # Checks if the current runtime is Python 3.10. if sys.version_info.major == 3 and sys.version_info.minor <= 10: diff --git a/google/ads/googleads/client.py b/google/ads/googleads/client.py index f0ec15ba7..aa7f408a8 100644 --- a/google/ads/googleads/client.py +++ b/google/ads/googleads/client.py @@ -203,9 +203,6 @@ def _get_client_kwargs(cls, config_data: Dict[str, Any]) -> Dict[str, Any]: "linked_customer_id": config_data.get("linked_customer_id"), "http_proxy": config_data.get("http_proxy"), "use_proto_plus": config_data.get("use_proto_plus"), - "use_cloud_org_for_api_access": config_data.get( - "use_cloud_org_for_api_access" - ), "ads_assistant": config_data.get("ads_assistant"), } @@ -324,7 +321,7 @@ def load_from_storage( def __init__( self, credentials: Dict[str, Any], - developer_token: str, + developer_token: Union[str, None] = None, endpoint: Union[str, None] = None, login_customer_id: Union[str, None] = None, logging_config: Union[Dict[str, Any], None] = None, @@ -332,14 +329,13 @@ def __init__( version: Union[str, None] = None, http_proxy: Union[str, None] = None, use_proto_plus: bool = False, - use_cloud_org_for_api_access: Union[str, None] = None, ads_assistant: Union[str, None] = None, ): """Initializer for the GoogleAdsClient. Args: credentials: a google.oauth2.credentials.Credentials instance. - developer_token: a str developer token. + developer_token: an optional str developer token. endpoint: a str specifying an optional alternative API endpoint. login_customer_id: a str specifying a login customer ID. logging_config: a dict specifying logging config options. @@ -348,27 +344,19 @@ def __init__( http_proxy: a str specifying the proxy URI through which to connect. use_proto_plus: a bool specifying whether or not to use proto-plus for protobuf message interfaces. - use_cloud_org_for_api_access: a str specifying whether to use the - Google Cloud Organization of your Google Cloud project instead - of developer token to determine your Google Ads API access - levels. Use this flag only if you are enrolled into a limited - pilot that supports this configuration. ads_assistant: a str specifying the Google Ads API Assistant version. """ if logging_config: logging.config.dictConfig(logging_config) self.credentials: Credentials = credentials - self.developer_token: str = developer_token + self.developer_token: Union[str, None] = developer_token self.endpoint: Union[str, None] = endpoint self.login_customer_id: Union[str, None] = login_customer_id self.linked_customer_id: Union[str, None] = linked_customer_id self.version: Union[str, None] = version self.http_proxy: Union[str, None] = http_proxy self.use_proto_plus: bool = use_proto_plus - self.use_cloud_org_for_api_access: Union[str, None] = ( - use_cloud_org_for_api_access - ) self.enums: _EnumGetter = _EnumGetter(self) self._ads_assistant: Union[str, None] = ads_assistant @@ -447,14 +435,12 @@ def get_service( self.developer_token, self.login_customer_id, self.linked_customer_id, - self.use_cloud_org_for_api_access, ads_assistant=self._ads_assistant, ), AsyncUnaryStreamMetadataInterceptor( self.developer_token, self.login_customer_id, self.linked_customer_id, - self.use_cloud_org_for_api_access, ads_assistant=self._ads_assistant, ), AsyncUnaryUnaryLoggingInterceptor(_logger, version, endpoint), @@ -487,7 +473,6 @@ def get_service( developer_token=self.developer_token, login_customer_id=self.login_customer_id, linked_customer_id=self.linked_customer_id, - use_cloud_org_for_api_access=self.use_cloud_org_for_api_access, ) return service_client_class(transport=service_transport) @@ -508,7 +493,6 @@ def get_service( self.developer_token, self.login_customer_id, self.linked_customer_id, - self.use_cloud_org_for_api_access, ads_assistant=self._ads_assistant, ), LoggingInterceptor(_logger, version, endpoint), @@ -530,7 +514,6 @@ def get_service( developer_token=self.developer_token, login_customer_id=self.login_customer_id, linked_customer_id=self.linked_customer_id, - use_cloud_org_for_api_access=self.use_cloud_org_for_api_access, ) return service_client_class(transport=service_transport) diff --git a/google/ads/googleads/config.py b/google/ads/googleads/config.py index 3b382d7d5..713dc8bab 100644 --- a/google/ads/googleads/config.py +++ b/google/ads/googleads/config.py @@ -25,14 +25,14 @@ _ENV_PREFIX = "GOOGLE_ADS_" -_REQUIRED_KEYS = ("developer_token", "use_proto_plus") +_REQUIRED_KEYS = ("use_proto_plus",) _OPTIONAL_KEYS = ( + "developer_token", "login_customer_id", "endpoint", "logging", "linked_customer_id", "http_proxy", - "use_cloud_org_for_api_access", "use_application_default_credentials", "ads_assistant", ) diff --git a/google/ads/googleads/interceptors/metadata_interceptor.py b/google/ads/googleads/interceptors/metadata_interceptor.py index 226023c8a..daef6e732 100644 --- a/google/ads/googleads/interceptors/metadata_interceptor.py +++ b/google/ads/googleads/interceptors/metadata_interceptor.py @@ -60,10 +60,9 @@ class MetadataInterceptor( def __init__( self, - developer_token: str, + developer_token: Optional[str] = None, login_customer_id: Optional[str] = None, linked_customer_id: Optional[str] = None, - use_cloud_org_for_api_access: Optional[bool] = None, ads_assistant: Optional[str] = None, ): """Initialization method for this class. @@ -72,16 +71,10 @@ def __init__( developer_token: a str developer token. login_customer_id: a str specifying a login customer ID. linked_customer_id: a str specifying a linked customer ID. - use_cloud_org_for_api_access: a str specifying whether to use the - Google Cloud Organization of your Google Cloud project instead - of developer token to determine your Google Ads API access - levels. Use this flag only if you are enrolled into a limited - pilot that supports this configuration ads_assistant: a str specifying the Google Ads API Assistant version. """ - self.developer_token_meta: Tuple[str, str] = ( - "developer-token", - developer_token, + self.developer_token_meta: Optional[Tuple[str, str]] = ( + ("developer-token", developer_token) if developer_token else None ) self.login_customer_id_meta: Optional[Tuple[str, str]] = ( ("login-customer-id", login_customer_id) @@ -94,9 +87,6 @@ def __init__( else None ) self.ads_assistant: Optional[str] = ads_assistant - self.use_cloud_org_for_api_access: Optional[bool] = ( - use_cloud_org_for_api_access - ) def _update_client_call_details_metadata( self, @@ -148,9 +138,7 @@ def _intercept( else: metadata: MetadataType = list(client_call_details.metadata) - # If self.use_cloud_org_for_api_access is not True, add the developer - # token to the request's metadata - if not self.use_cloud_org_for_api_access: + if self.developer_token_meta: metadata.append(self.developer_token_meta) if self.login_customer_id_meta: @@ -266,9 +254,7 @@ async def _intercept( else: metadata: MetadataType = list(client_call_details.metadata) - # If self.use_cloud_org_for_api_access is not True, add the developer - # token to the request's metadata - if not self.use_cloud_org_for_api_access: + if self.developer_token_meta: metadata.append(self.developer_token_meta) if self.login_customer_id_meta: diff --git a/pyproject.toml b/pyproject.toml index 1072806e8..8ee515e1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ build-backend = "setuptools.build_meta" [project] name = "google-ads" -version = "31.4.0" +version = "32.0.0" description = "Client library for the Google Ads API" readme = "./README.rst" requires-python = ">=3.9, <3.15" diff --git a/tests/client_test.py b/tests/client_test.py index 093f1c2b6..8ef6e4324 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -113,7 +113,6 @@ def test_get_client_kwargs_login_customer_id(self): "logging_config": None, "linked_customer_id": self.linked_customer_id, "http_proxy": None, - "use_cloud_org_for_api_access": None, "ads_assistant": None, }, ) @@ -147,7 +146,6 @@ def test_get_client_kwargs_login_customer_id_as_None(self): "logging_config": None, "linked_customer_id": None, "http_proxy": None, - "use_cloud_org_for_api_access": None, "ads_assistant": None, }, ) @@ -181,7 +179,6 @@ def test_get_client_kwargs_linked_customer_id(self): "logging_config": None, "linked_customer_id": self.linked_customer_id, "http_proxy": None, - "use_cloud_org_for_api_access": None, "ads_assistant": None, }, ) @@ -215,7 +212,6 @@ def test_get_client_kwargs_linked_customer_id_as_none(self): "logging_config": None, "login_customer_id": None, "http_proxy": None, - "use_cloud_org_for_api_access": None, "ads_assistant": None, }, ) @@ -249,7 +245,6 @@ def test_get_client_kwargs(self): "logging_config": None, "linked_customer_id": None, "http_proxy": self.http_proxy, - "use_cloud_org_for_api_access": None, "ads_assistant": None, }, ) @@ -284,7 +279,6 @@ def test_get_client_kwargs_custom_endpoint(self): "logging_config": None, "linked_customer_id": None, "http_proxy": None, - "use_cloud_org_for_api_access": None, "ads_assistant": None, }, ) @@ -323,7 +317,6 @@ def test_load_from_env(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -361,7 +354,6 @@ def test_load_from_env_versioned(self): linked_customer_id=None, version="v4", http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -398,7 +390,6 @@ def test_load_from_dict(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -435,7 +426,6 @@ def test_load_from_dict_versioned(self): linked_customer_id=None, version="v4", http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -479,7 +469,6 @@ def test_load_from_dict_login_customer_id_explicit_none(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -516,7 +505,6 @@ def test_load_from_string(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -555,7 +543,6 @@ def test_load_from_string_versioned(self): linked_customer_id=None, version="v4", http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -963,7 +950,6 @@ def test_load_http_proxy_from_env(self): linked_customer_id=None, version=None, http_proxy=self.http_proxy, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1001,7 +987,6 @@ def test_load_http_proxy_from_dict(self): linked_customer_id=None, version=None, http_proxy=self.http_proxy, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1039,7 +1024,6 @@ def test_load_http_proxy_from_string(self): linked_customer_id=None, version=None, http_proxy=self.http_proxy, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1114,7 +1098,6 @@ def test_load_http_proxy_from_storage(self): linked_customer_id=None, version=None, http_proxy=self.http_proxy, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1159,7 +1142,6 @@ def test_load_from_storage(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1204,7 +1186,6 @@ def test_load_from_storage_versioned(self): linked_customer_id=None, version="v4", http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1251,7 +1232,6 @@ def test_load_from_storage_login_cid_int(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1290,7 +1270,6 @@ def test_load_from_storage_custom_path(self): linked_customer_id=None, version=None, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) @@ -1356,6 +1335,5 @@ def test_load_from_storage_service_account_config(self): linked_customer_id=None, version=latest_version, http_proxy=None, - use_cloud_org_for_api_access=None, ads_assistant=None, ) diff --git a/tests/config_test.py b/tests/config_test.py index be579d5d3..cffd29b8b 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -37,7 +37,6 @@ def setUp(self): self.configuration_file_path = "/usr/test/path/google-ads.yaml" self.impersonated_email = "impersonated@account.com" self.use_proto_plus = False - self.use_cloud_org_for_api_access = False self.use_application_default_credentials = True # The below fields are defaults that include required keys. # They are merged with other keys in individual tests, and isolated @@ -120,10 +119,9 @@ def test_load_from_yaml_file(self): self.assertEqual(result["client_secret"], self.client_secret) self.assertEqual(result["refresh_token"], self.refresh_token) - def test_load_from_yaml_file_missing_developer_token(self): - """Should raise ValueError if developer_token key is missing.""" + def test_load_from_yaml_file_without_developer_token(self): + """Should load config successfully even if developer_token key is missing.""" file_path = os.path.join(os.path.expanduser("~"), "google-ads.yaml") - # save a YAML file without a required developer_token key self.fs.create_file( file_path, contents=yaml.safe_dump( @@ -136,7 +134,9 @@ def test_load_from_yaml_file_missing_developer_token(self): ), ) - self.assertRaises(ValueError, config.load_from_yaml_file) + result = config.load_from_yaml_file() + self.assertIsNone(result.get("developer_token")) + self.assertEqual(result["use_proto_plus"], self.use_proto_plus) def test_load_from_yaml_file_missing_use_proto_plus_key(self): """Should raise ValueError if use_proto_plus key is missing.""" @@ -265,11 +265,10 @@ def test_parse_yaml_document_to_dict(self): def test_parse_yaml_document_to_dict_missing_required_key(self): """Should raise ValueError if yaml string is missing a required key.""" - # YAML document is missing the required developer_token key + # YAML document is missing the required use_proto_plus key yaml_doc = f""" client_id: {self.client_id}\n client_secret: {self.client_secret}\n - use_proto_plus: {self.use_proto_plus}\n refresh_token: {self.refresh_token}\n """ @@ -406,7 +405,7 @@ def test_load_from_env(self, config_spy): @mock.patch.object(config, "_logger", mock.Mock()) def test_load_from_env_missing_required_key(self): """Should raise ValueError if missing required env var..""" - # environ is missing required developer_token key + # environ is missing required use_proto_plus key environ = { "GOOGLE_ADS_CLIENT_ID": self.client_id, "GOOGLE_ADS_CLIENT_SECRET": self.client_secret, @@ -421,6 +420,21 @@ def test_load_from_env_missing_required_key(self): with mock.patch("os.environ", environ): self.assertRaises(ValueError, config.load_from_env) + @mock.patch.object(config, "_logger", mock.Mock()) + def test_load_from_env_without_developer_token(self): + """Should load config from env successfully without developer_token.""" + environ = { + "GOOGLE_ADS_CLIENT_ID": self.client_id, + "GOOGLE_ADS_CLIENT_SECRET": self.client_secret, + "GOOGLE_ADS_REFRESH_TOKEN": self.refresh_token, + "GOOGLE_ADS_USE_PROTO_PLUS": str(self.use_proto_plus), + } + + with mock.patch("os.environ", environ): + result = config.load_from_env() + self.assertIsNone(result.get("developer_token")) + self.assertEqual(result["use_proto_plus"], self.use_proto_plus) + def test_load_from_env_config_file_path(self): """Should delegate to load_from_yaml_file method.""" environ = { @@ -718,35 +732,6 @@ def test_load_from_yaml_file_ads_assistant_not_set(self): result = config.load_from_yaml_file() self.assertEqual(result.get("ads_assistant"), None) - def test_load_from_env_use_cloud_org_for_api_access(self): - """Should load api access flag from environment when specified""" - environ = { - **self.default_env_var_config, - **{ - "GOOGLE_ADS_USE_CLOUD_ORG_FOR_API_ACCESS": self.use_cloud_org_for_api_access, - }, - } - - with mock.patch("os.environ", environ): - results = config.load_from_env() - self.assertEqual( - results["use_cloud_org_for_api_access"], - self.use_cloud_org_for_api_access, - ) - - def test_load_from_yaml_file_use_cloud_org_for_api_access(self): - """Should load "use_cloud_org_for_api_access" config from a yaml.""" - self._create_mock_yaml({"use_cloud_org_for_api_access": True}) - - result = config.load_from_yaml_file() - self.assertEqual(result["use_cloud_org_for_api_access"], True) - - def test_load_from_yaml_file_use_cloud_org_for_api_access_not_set(self): - """Should set "use_cloud_org_for_api_access" as None when not set.""" - self._create_mock_yaml({}) - result = config.load_from_yaml_file() - self.assertEqual(result.get("use_cloud_org_for_api_access"), None) - def test_load_from_yaml_file_use_account_default_credentials(self): """Should load "use_account_default_credentials" config from a yaml.""" self._create_mock_yaml({"use_account_default_credentials": True}) diff --git a/tests/interceptors/metadata_interceptor_test.py b/tests/interceptors/metadata_interceptor_test.py index c1322dfbe..db5eeeb2c 100644 --- a/tests/interceptors/metadata_interceptor_test.py +++ b/tests/interceptors/metadata_interceptor_test.py @@ -33,7 +33,6 @@ def setUp(self): self.mock_developer_token = "1234567890" self.mock_login_customer_id = "0987654321" self.mock_linked_customer_id = "5555555555" - self.use_cloud_org_for_api_access = True self.python_version = python_version super(MetadataInterceptorTest, self).setUp() @@ -52,6 +51,16 @@ def test_init(self): ("login-customer-id", self.mock_login_customer_id), ) + def test_init_no_developer_token(self): + interceptor = MetadataInterceptor(None, self.mock_login_customer_id) + + self.assertIsNone(interceptor.developer_token_meta) + + self.assertEqual( + interceptor.login_customer_id_meta, + ("login-customer-id", self.mock_login_customer_id), + ) + def test_init_no_login_customer_id(self): interceptor = MetadataInterceptor(self.mock_developer_token, None) @@ -121,6 +130,40 @@ def test_intercept_unary_unary(self): mock_continuation.assert_called_once() + def test_intercept_unary_unary_no_developer_token(self): + interceptor = MetadataInterceptor( + None, + self.mock_login_customer_id, + self.mock_linked_customer_id, + ) + + mock_continuation = mock.Mock(return_value=None) + mock_client_call_details = mock.Mock() + mock_client_call_details.method = "test/method" + mock_client_call_details.timeout = 5 + mock_client_call_details.metadata = [("apples", "oranges")] + mock_request = mock.Mock() + + with mock.patch.object( + interceptor, + "_update_client_call_details_metadata", + wraps=interceptor._update_client_call_details_metadata, + ) as mock_updater: + interceptor.intercept_unary_unary( + mock_continuation, mock_client_call_details, mock_request + ) + + mock_updater.assert_called_once_with( + mock_client_call_details, + [ + mock_client_call_details.metadata[0], + interceptor.login_customer_id_meta, + interceptor.linked_customer_id_meta, + ], + ) + + mock_continuation.assert_called_once() + def test_intercept_unary_stream(self): interceptor = MetadataInterceptor( self.mock_developer_token, @@ -180,6 +223,7 @@ def test_intercept_updates_user_agent_add_pb(self): f"gl-python/{self.python_version} grpc/1.45.0 gax/2.2.2", ), ] + # Create a simple function that just returns the client_call_details # so we can make assertions about what was modified in the _intercept # method. @@ -222,6 +266,7 @@ def test_intercept_updates_user_agent_existing_pb(self): f"gl-python/{self.python_version} grpc/1.45.0 pb/3.21.0", ), ] + # Create a simple function that just returns the client_call_details # so we can make assertions about what was modified in the _intercept # method. @@ -288,49 +333,12 @@ def mock_continuation(client_call_details, _): # value pair because it was already present when passed in. self.assertEqual(user_agent.count("pb"), 0) - def test_intercept_unary_stream_use_cloud_org_for_api_access(self): - interceptor = MetadataInterceptor( - self.mock_developer_token, - self.mock_login_customer_id, - self.mock_linked_customer_id, - self.use_cloud_org_for_api_access, - ) - - mock_continuation = mock.Mock(return_value=None) - mock_client_call_details = mock.Mock() - mock_client_call_details.method = "test/method" - mock_client_call_details.timeout = 5 - mock_client_call_details.metadata = [("apples", "oranges")] - mock_request = mock.Mock() - - with mock.patch.object( - interceptor, - "_update_client_call_details_metadata", - wraps=interceptor._update_client_call_details_metadata, - ) as mock_updater: - interceptor.intercept_unary_stream( - mock_continuation, mock_client_call_details, mock_request - ) - # Assets that if "use_cloud_org_for_api_access" is passed into - # MetadataInterceptor as True, then - mock_updater.assert_called_once_with( - mock_client_call_details, - [ - mock_client_call_details.metadata[0], - interceptor.login_customer_id_meta, - interceptor.linked_customer_id_meta, - ], - ) - - mock_continuation.assert_called_once() - class AsyncMetadataInterceptorTest(IsolatedAsyncioTestCase): def setUp(self): self.mock_developer_token = "1234567890" self.mock_login_customer_id = "0987654321" self.mock_linked_customer_id = "5555555555" - self.use_cloud_org_for_api_access = True self.python_version = python_version def test_init(self): @@ -348,6 +356,18 @@ def test_init(self): ("login-customer-id", self.mock_login_customer_id), ) + def test_init_no_developer_token(self): + interceptor = AsyncMetadataInterceptor( + None, self.mock_login_customer_id + ) + + self.assertIsNone(interceptor.developer_token_meta) + + self.assertEqual( + interceptor.login_customer_id_meta, + ("login-customer-id", self.mock_login_customer_id), + ) + def test_init_no_login_customer_id(self): interceptor = AsyncMetadataInterceptor(self.mock_developer_token, None) @@ -359,7 +379,9 @@ def test_init_no_login_customer_id(self): self.assertEqual(interceptor.login_customer_id_meta, None) def test_init_no_linked_customer_id(self): - interceptor = AsyncMetadataInterceptor(self.mock_developer_token, None, None) + interceptor = AsyncMetadataInterceptor( + self.mock_developer_token, None, None + ) self.assertEqual( interceptor.developer_token_meta, @@ -417,6 +439,40 @@ async def test_intercept_unary_unary(self): mock_continuation.assert_called_once() + async def test_intercept_unary_unary_no_developer_token(self): + interceptor = AsyncMetadataInterceptor( + None, + self.mock_login_customer_id, + self.mock_linked_customer_id, + ) + + mock_continuation = mock.AsyncMock(return_value=None) + mock_client_call_details = mock.Mock() + mock_client_call_details.method = "test/method" + mock_client_call_details.timeout = 5 + mock_client_call_details.metadata = [("apples", "oranges")] + mock_request = mock.Mock() + + with mock.patch.object( + interceptor, + "_update_client_call_details_metadata", + wraps=interceptor._update_client_call_details_metadata, + ) as mock_updater: + await interceptor.intercept_unary_unary( + mock_continuation, mock_client_call_details, mock_request + ) + + mock_updater.assert_called_once_with( + mock_client_call_details, + [ + mock_client_call_details.metadata[0], + interceptor.login_customer_id_meta, + interceptor.linked_customer_id_meta, + ], + ) + + mock_continuation.assert_called_once() + async def test_intercept_unary_stream(self): interceptor = AsyncMetadataInterceptor( self.mock_developer_token, @@ -476,6 +532,7 @@ async def test_intercept_updates_user_agent_add_pb(self): f"gl-python/{self.python_version} grpc/1.45.0 gax/2.2.2", ), ] + # Create a simple function that just returns the client_call_details # so we can make assertions about what was modified in the _intercept # method. @@ -518,6 +575,7 @@ async def test_intercept_updates_user_agent_existing_pb(self): f"gl-python/{self.python_version} grpc/1.45.0 pb/3.21.0", ), ] + # Create a simple function that just returns the client_call_details # so we can make assertions about what was modified in the _intercept # method. @@ -583,39 +641,3 @@ async def mock_continuation(client_call_details, _): # We assert that the _intercept method did not add the "pb" key # value pair because it was already present when passed in. self.assertEqual(user_agent.count("pb"), 0) - - async def test_intercept_unary_stream_use_cloud_org_for_api_access(self): - interceptor = AsyncMetadataInterceptor( - self.mock_developer_token, - self.mock_login_customer_id, - self.mock_linked_customer_id, - self.use_cloud_org_for_api_access, - ) - - mock_continuation = mock.AsyncMock(return_value=None) - mock_client_call_details = mock.Mock() - mock_client_call_details.method = "test/method" - mock_client_call_details.timeout = 5 - mock_client_call_details.metadata = [("apples", "oranges")] - mock_request = mock.Mock() - - with mock.patch.object( - interceptor, - "_update_client_call_details_metadata", - wraps=interceptor._update_client_call_details_metadata, - ) as mock_updater: - await interceptor.intercept_unary_stream( - mock_continuation, mock_client_call_details, mock_request - ) - # Assets that if "use_cloud_org_for_api_access" is passed into - # MetadataInterceptor as True, then - mock_updater.assert_called_once_with( - mock_client_call_details, - [ - mock_client_call_details.metadata[0], - interceptor.login_customer_id_meta, - interceptor.linked_customer_id_meta, - ], - ) - - mock_continuation.assert_called_once()