From ea4c1f40166e92bd16234b80d7f036b9128597b6 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 5 Feb 2024 13:22:26 -0800 Subject: [PATCH] fix: Resolve AttributeError 'Credentials' object has no attribute 'universe_domain' (#739) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Resolve AttributeError 'Credentials' object has no attribute 'universe_domain' fix: Add google-auth as a direct dependency fix: Add staticmethod decorator to methods added in v1.14.0 chore: Update gapic-generator-python to v1.14.1 PiperOrigin-RevId: 603728206 Source-Link: https://github.com/googleapis/googleapis/commit/9063da8b4d45339db4e2d7d92a27c6708620e694 Source-Link: https://github.com/googleapis/googleapis-gen/commit/891c67d0a855b08085eb301dabb14064ef4b2c6d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODkxYzY3ZDBhODU1YjA4MDg1ZWIzMDFkYWJiMTQwNjRlZjRiMmM2ZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot Co-authored-by: Lingqing Gan --- .../services/big_query_read/client.py | 25 +- .../services/big_query_write/client.py | 25 +- .../services/big_query_read/client.py | 25 +- .../services/big_query_write/client.py | 25 +- .../test_big_query_read.py | 209 +++++++------- .../test_big_query_write.py | 257 +++++++++--------- .../test_big_query_read.py | 209 +++++++------- .../test_big_query_write.py | 257 +++++++++--------- 8 files changed, 500 insertions(+), 532 deletions(-) diff --git a/google/cloud/bigquery_storage_v1/services/big_query_read/client.py b/google/cloud/bigquery_storage_v1/services/big_query_read/client.py index 1d8373b8..a05e9477 100644 --- a/google/cloud/bigquery_storage_v1/services/big_query_read/client.py +++ b/google/cloud/bigquery_storage_v1/services/big_query_read/client.py @@ -430,6 +430,7 @@ def _read_environment_variables(): ) return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + @staticmethod def _get_client_cert_source(provided_cert_source, use_cert_flag): """Return the client cert source to be used by the client. @@ -448,6 +449,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): client_cert_source = mtls.default_client_cert_source() return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ): @@ -522,17 +524,18 @@ def _compare_universes( Raises: ValueError: when client_universe does not match the universe in credentials. """ - if credentials: - credentials_universe = credentials.universe_domain - if client_universe != credentials_universe: - default_universe = BigQueryReadClient._DEFAULT_UNIVERSE - raise ValueError( - "The configured universe domain " - f"({client_universe}) does not match the universe domain " - f"found in the credentials ({credentials_universe}). " - "If you haven't configured the universe domain explicitly, " - f"`{default_universe}` is the default." - ) + + default_universe = BigQueryReadClient._DEFAULT_UNIVERSE + credentials_universe = getattr(credentials, "universe_domain", default_universe) + + if client_universe != credentials_universe: + raise ValueError( + "The configured universe domain " + f"({client_universe}) does not match the universe domain " + f"found in the credentials ({credentials_universe}). " + "If you haven't configured the universe domain explicitly, " + f"`{default_universe}` is the default." + ) return True def _validate_universe_domain(self): diff --git a/google/cloud/bigquery_storage_v1/services/big_query_write/client.py b/google/cloud/bigquery_storage_v1/services/big_query_write/client.py index e2a714cb..a08e6102 100644 --- a/google/cloud/bigquery_storage_v1/services/big_query_write/client.py +++ b/google/cloud/bigquery_storage_v1/services/big_query_write/client.py @@ -413,6 +413,7 @@ def _read_environment_variables(): ) return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + @staticmethod def _get_client_cert_source(provided_cert_source, use_cert_flag): """Return the client cert source to be used by the client. @@ -431,6 +432,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): client_cert_source = mtls.default_client_cert_source() return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ): @@ -505,17 +507,18 @@ def _compare_universes( Raises: ValueError: when client_universe does not match the universe in credentials. """ - if credentials: - credentials_universe = credentials.universe_domain - if client_universe != credentials_universe: - default_universe = BigQueryWriteClient._DEFAULT_UNIVERSE - raise ValueError( - "The configured universe domain " - f"({client_universe}) does not match the universe domain " - f"found in the credentials ({credentials_universe}). " - "If you haven't configured the universe domain explicitly, " - f"`{default_universe}` is the default." - ) + + default_universe = BigQueryWriteClient._DEFAULT_UNIVERSE + credentials_universe = getattr(credentials, "universe_domain", default_universe) + + if client_universe != credentials_universe: + raise ValueError( + "The configured universe domain " + f"({client_universe}) does not match the universe domain " + f"found in the credentials ({credentials_universe}). " + "If you haven't configured the universe domain explicitly, " + f"`{default_universe}` is the default." + ) return True def _validate_universe_domain(self): diff --git a/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py b/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py index 948aa552..a5b79901 100644 --- a/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py +++ b/google/cloud/bigquery_storage_v1beta2/services/big_query_read/client.py @@ -433,6 +433,7 @@ def _read_environment_variables(): ) return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + @staticmethod def _get_client_cert_source(provided_cert_source, use_cert_flag): """Return the client cert source to be used by the client. @@ -451,6 +452,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): client_cert_source = mtls.default_client_cert_source() return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ): @@ -525,17 +527,18 @@ def _compare_universes( Raises: ValueError: when client_universe does not match the universe in credentials. """ - if credentials: - credentials_universe = credentials.universe_domain - if client_universe != credentials_universe: - default_universe = BigQueryReadClient._DEFAULT_UNIVERSE - raise ValueError( - "The configured universe domain " - f"({client_universe}) does not match the universe domain " - f"found in the credentials ({credentials_universe}). " - "If you haven't configured the universe domain explicitly, " - f"`{default_universe}` is the default." - ) + + default_universe = BigQueryReadClient._DEFAULT_UNIVERSE + credentials_universe = getattr(credentials, "universe_domain", default_universe) + + if client_universe != credentials_universe: + raise ValueError( + "The configured universe domain " + f"({client_universe}) does not match the universe domain " + f"found in the credentials ({credentials_universe}). " + "If you haven't configured the universe domain explicitly, " + f"`{default_universe}` is the default." + ) return True def _validate_universe_domain(self): diff --git a/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py b/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py index ca3b6d78..3e95fc42 100644 --- a/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py +++ b/google/cloud/bigquery_storage_v1beta2/services/big_query_write/client.py @@ -414,6 +414,7 @@ def _read_environment_variables(): ) return use_client_cert == "true", use_mtls_endpoint, universe_domain_env + @staticmethod def _get_client_cert_source(provided_cert_source, use_cert_flag): """Return the client cert source to be used by the client. @@ -432,6 +433,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): client_cert_source = mtls.default_client_cert_source() return client_cert_source + @staticmethod def _get_api_endpoint( api_override, client_cert_source, universe_domain, use_mtls_endpoint ): @@ -506,17 +508,18 @@ def _compare_universes( Raises: ValueError: when client_universe does not match the universe in credentials. """ - if credentials: - credentials_universe = credentials.universe_domain - if client_universe != credentials_universe: - default_universe = BigQueryWriteClient._DEFAULT_UNIVERSE - raise ValueError( - "The configured universe domain " - f"({client_universe}) does not match the universe domain " - f"found in the credentials ({credentials_universe}). " - "If you haven't configured the universe domain explicitly, " - f"`{default_universe}` is the default." - ) + + default_universe = BigQueryWriteClient._DEFAULT_UNIVERSE + credentials_universe = getattr(credentials, "universe_domain", default_universe) + + if client_universe != credentials_universe: + raise ValueError( + "The configured universe domain " + f"({client_universe}) does not match the universe domain " + f"found in the credentials ({credentials_universe}). " + "If you haven't configured the universe domain explicitly, " + f"`{default_universe}` is the default." + ) return True def _validate_universe_domain(self): diff --git a/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py b/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py index 7f67f517..e99eba74 100644 --- a/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py +++ b/tests/unit/gapic/bigquery_storage_v1/test_big_query_read.py @@ -78,18 +78,6 @@ def modify_default_endpoint_template(client): ) -# Anonymous Credentials with universe domain property. If no universe domain is provided, then -# the default universe domain is "googleapis.com". -class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): - def __init__(self, universe_domain="googleapis.com"): - super(_AnonymousCredentialsWithUniverseDomain, self).__init__() - self._universe_domain = universe_domain - - @property - def universe_domain(self): - return self._universe_domain - - def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -300,7 +288,7 @@ def test__get_universe_domain(): ) def test__validate_universe_domain(client_class, transport_class, transport_name): client = client_class( - transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + transport=transport_class(credentials=ga_credentials.AnonymousCredentials()) ) assert client._validate_universe_domain() == True @@ -327,42 +315,49 @@ def test__validate_universe_domain(client_class, transport_class, transport_name client = client_class(transport=transport) assert client._validate_universe_domain() == True - # Test the case when there is a universe mismatch from the credentials. - client = client_class( - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain( - universe_domain="foo.com" - ) - ) - ) - with pytest.raises(ValueError) as excinfo: - client._validate_universe_domain() - assert ( - str(excinfo.value) - == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." - ) - - # Test the case when there is a universe mismatch from the client. - # - # TODO: Make this test unconditional once the minimum supported version of - # google-api-core becomes 2.15.0 or higher. - api_core_major, api_core_minor, _ = [ - int(part) for part in api_core_version.__version__.split(".") + # TODO: This is needed to cater for older versions of google-auth + # Make this test unconditional once the minimum supported version of + # google-auth becomes 2.23.0 or higher. + google_auth_major, google_auth_minor, _ = [ + int(part) for part in google.auth.__version__.split(".") ] - if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): - client = client_class( - client_options={"universe_domain": "bar.com"}, - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), - ), - ) + if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23): + credentials = ga_credentials.AnonymousCredentials() + credentials._universe_domain = "foo.com" + # Test the case when there is a universe mismatch from the credentials. + client = client_class(transport=transport_class(credentials=credentials)) with pytest.raises(ValueError) as excinfo: client._validate_universe_domain() assert ( str(excinfo.value) - == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." ) + # Test the case when there is a universe mismatch from the client. + # + # TODO: Make this test unconditional once the minimum supported version of + # google-api-core becomes 2.15.0 or higher. + api_core_major, api_core_minor, _ = [ + int(part) for part in api_core_version.__version__.split(".") + ] + if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): + client = client_class( + client_options={"universe_domain": "bar.com"}, + transport=transport_class( + credentials=ga_credentials.AnonymousCredentials(), + ), + ) + with pytest.raises(ValueError) as excinfo: + client._validate_universe_domain() + assert ( + str(excinfo.value) + == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + ) + + # Test that ValueError is raised if universe_domain is provided via client options and credentials is None + with pytest.raises(ValueError): + client._compare_universes("foo.bar", None) + @pytest.mark.parametrize( "client_class,transport_name", @@ -372,7 +367,7 @@ def test__validate_universe_domain(client_class, transport_class, transport_name ], ) def test_big_query_read_client_from_service_account_info(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -418,7 +413,7 @@ def test_big_query_read_client_service_account_always_use_jwt( ], ) def test_big_query_read_client_from_service_account_file(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -475,9 +470,7 @@ def test_big_query_read_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(BigQueryReadClient, "get_transport_class") as gtc: - transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain() - ) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -868,20 +861,20 @@ def test_big_query_read_client_client_api_endpoint(client_class): ) client = client_class( client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert client.api_endpoint == api_override # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == default_endpoint # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), @@ -893,13 +886,11 @@ def test_big_query_read_client_client_api_endpoint(client_class): if universe_exists: options = client_options.ClientOptions(universe_domain=mock_universe) client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) else: client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == ( mock_endpoint if universe_exists else default_endpoint @@ -915,8 +906,7 @@ def test_big_query_read_client_client_api_endpoint(client_class): delattr(options, "universe_domain") with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == default_endpoint @@ -1065,8 +1055,8 @@ def test_big_query_read_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() - file_creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -1098,7 +1088,7 @@ def test_big_query_read_client_create_channel_credentials_file( ) def test_create_read_session(request_type, transport: str = "grpc"): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1142,7 +1132,7 @@ def test_create_read_session_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1161,7 +1151,7 @@ async def test_create_read_session_async( transport: str = "grpc_asyncio", request_type=storage.CreateReadSessionRequest ): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1210,7 +1200,7 @@ async def test_create_read_session_async_from_dict(): def test_create_read_session_field_headers(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1242,7 +1232,7 @@ def test_create_read_session_field_headers(): @pytest.mark.asyncio async def test_create_read_session_field_headers_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1273,7 +1263,7 @@ async def test_create_read_session_field_headers_async(): def test_create_read_session_flattened(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1307,7 +1297,7 @@ def test_create_read_session_flattened(): def test_create_read_session_flattened_error(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1324,7 +1314,7 @@ def test_create_read_session_flattened_error(): @pytest.mark.asyncio async def test_create_read_session_flattened_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1361,7 +1351,7 @@ async def test_create_read_session_flattened_async(): @pytest.mark.asyncio async def test_create_read_session_flattened_error_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1384,7 +1374,7 @@ async def test_create_read_session_flattened_error_async(): ) def test_read_rows(request_type, transport: str = "grpc"): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1412,7 +1402,7 @@ def test_read_rows_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1429,7 +1419,7 @@ async def test_read_rows_async( transport: str = "grpc_asyncio", request_type=storage.ReadRowsRequest ): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1463,7 +1453,7 @@ async def test_read_rows_async_from_dict(): def test_read_rows_field_headers(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1493,7 +1483,7 @@ def test_read_rows_field_headers(): @pytest.mark.asyncio async def test_read_rows_field_headers_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1525,7 +1515,7 @@ async def test_read_rows_field_headers_async(): def test_read_rows_flattened(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1553,7 +1543,7 @@ def test_read_rows_flattened(): def test_read_rows_flattened_error(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1569,7 +1559,7 @@ def test_read_rows_flattened_error(): @pytest.mark.asyncio async def test_read_rows_flattened_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1600,7 +1590,7 @@ async def test_read_rows_flattened_async(): @pytest.mark.asyncio async def test_read_rows_flattened_error_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1622,7 +1612,7 @@ async def test_read_rows_flattened_error_async(): ) def test_split_read_stream(request_type, transport: str = "grpc"): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1651,7 +1641,7 @@ def test_split_read_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1670,7 +1660,7 @@ async def test_split_read_stream_async( transport: str = "grpc_asyncio", request_type=storage.SplitReadStreamRequest ): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1704,7 +1694,7 @@ async def test_split_read_stream_async_from_dict(): def test_split_read_stream_field_headers(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1736,7 +1726,7 @@ def test_split_read_stream_field_headers(): @pytest.mark.asyncio async def test_split_read_stream_field_headers_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1770,17 +1760,17 @@ async def test_split_read_stream_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryReadClient( @@ -1790,7 +1780,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1805,13 +1795,12 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = BigQueryReadClient( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) # It is an error to provide scopes and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryReadClient( @@ -1823,7 +1812,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) client = BigQueryReadClient(transport=transport) assert client.transport is transport @@ -1832,13 +1821,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.BigQueryReadGrpcAsyncIOTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1854,7 +1843,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() @@ -1867,7 +1856,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = BigQueryReadClient.get_transport_class(transport_name)( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert transport.kind == transport_name @@ -1875,7 +1864,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, @@ -1887,7 +1876,7 @@ def test_big_query_read_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.BigQueryReadTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1899,7 +1888,7 @@ def test_big_query_read_base_transport(): ) as Transport: Transport.return_value = None transport = transports.BigQueryReadTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1933,7 +1922,7 @@ def test_big_query_read_base_transport_with_credentials_file(): "google.cloud.bigquery_storage_v1.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1955,7 +1944,7 @@ def test_big_query_read_base_transport_with_adc(): "google.cloud.bigquery_storage_v1.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport() adc.assert_called_once() @@ -1963,7 +1952,7 @@ def test_big_query_read_base_transport_with_adc(): def test_big_query_read_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) BigQueryReadClient() adc.assert_called_once_with( scopes=None, @@ -1986,7 +1975,7 @@ def test_big_query_read_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2035,7 +2024,7 @@ def test_big_query_read_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2063,7 +2052,7 @@ def test_big_query_read_transport_create_channel(transport_class, grpc_helpers): [transports.BigQueryReadGrpcTransport, transports.BigQueryReadGrpcAsyncIOTransport], ) def test_big_query_read_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2109,7 +2098,7 @@ def test_big_query_read_grpc_transport_client_cert_source_for_mtls(transport_cla ) def test_big_query_read_host_no_port(transport_name): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com" ), @@ -2127,7 +2116,7 @@ def test_big_query_read_host_no_port(transport_name): ) def test_big_query_read_host_with_port(transport_name): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com:8000" ), @@ -2181,7 +2170,7 @@ def test_big_query_read_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2445,7 +2434,7 @@ def test_client_with_default_client_info(): transports.BigQueryReadTransport, "_prep_wrapped_messages" ) as prep: client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2455,7 +2444,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = BigQueryReadClient.get_transport_class() transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2464,7 +2453,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2482,7 +2471,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2498,7 +2487,7 @@ def test_client_ctx(): ] for transport in transports: client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: diff --git a/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py b/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py index 090151dd..5cc8c69d 100644 --- a/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py +++ b/tests/unit/gapic/bigquery_storage_v1/test_big_query_write.py @@ -83,18 +83,6 @@ def modify_default_endpoint_template(client): ) -# Anonymous Credentials with universe domain property. If no universe domain is provided, then -# the default universe domain is "googleapis.com". -class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): - def __init__(self, universe_domain="googleapis.com"): - super(_AnonymousCredentialsWithUniverseDomain, self).__init__() - self._universe_domain = universe_domain - - @property - def universe_domain(self): - return self._universe_domain - - def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -316,7 +304,7 @@ def test__get_universe_domain(): ) def test__validate_universe_domain(client_class, transport_class, transport_name): client = client_class( - transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + transport=transport_class(credentials=ga_credentials.AnonymousCredentials()) ) assert client._validate_universe_domain() == True @@ -343,42 +331,49 @@ def test__validate_universe_domain(client_class, transport_class, transport_name client = client_class(transport=transport) assert client._validate_universe_domain() == True - # Test the case when there is a universe mismatch from the credentials. - client = client_class( - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain( - universe_domain="foo.com" - ) - ) - ) - with pytest.raises(ValueError) as excinfo: - client._validate_universe_domain() - assert ( - str(excinfo.value) - == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." - ) - - # Test the case when there is a universe mismatch from the client. - # - # TODO: Make this test unconditional once the minimum supported version of - # google-api-core becomes 2.15.0 or higher. - api_core_major, api_core_minor, _ = [ - int(part) for part in api_core_version.__version__.split(".") + # TODO: This is needed to cater for older versions of google-auth + # Make this test unconditional once the minimum supported version of + # google-auth becomes 2.23.0 or higher. + google_auth_major, google_auth_minor, _ = [ + int(part) for part in google.auth.__version__.split(".") ] - if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): - client = client_class( - client_options={"universe_domain": "bar.com"}, - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), - ), - ) + if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23): + credentials = ga_credentials.AnonymousCredentials() + credentials._universe_domain = "foo.com" + # Test the case when there is a universe mismatch from the credentials. + client = client_class(transport=transport_class(credentials=credentials)) with pytest.raises(ValueError) as excinfo: client._validate_universe_domain() assert ( str(excinfo.value) - == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." ) + # Test the case when there is a universe mismatch from the client. + # + # TODO: Make this test unconditional once the minimum supported version of + # google-api-core becomes 2.15.0 or higher. + api_core_major, api_core_minor, _ = [ + int(part) for part in api_core_version.__version__.split(".") + ] + if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): + client = client_class( + client_options={"universe_domain": "bar.com"}, + transport=transport_class( + credentials=ga_credentials.AnonymousCredentials(), + ), + ) + with pytest.raises(ValueError) as excinfo: + client._validate_universe_domain() + assert ( + str(excinfo.value) + == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + ) + + # Test that ValueError is raised if universe_domain is provided via client options and credentials is None + with pytest.raises(ValueError): + client._compare_universes("foo.bar", None) + @pytest.mark.parametrize( "client_class,transport_name", @@ -388,7 +383,7 @@ def test__validate_universe_domain(client_class, transport_class, transport_name ], ) def test_big_query_write_client_from_service_account_info(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -434,7 +429,7 @@ def test_big_query_write_client_service_account_always_use_jwt( ], ) def test_big_query_write_client_from_service_account_file(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -491,9 +486,7 @@ def test_big_query_write_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(BigQueryWriteClient, "get_transport_class") as gtc: - transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain() - ) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -890,20 +883,20 @@ def test_big_query_write_client_client_api_endpoint(client_class): ) client = client_class( client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert client.api_endpoint == api_override # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == default_endpoint # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), @@ -915,13 +908,11 @@ def test_big_query_write_client_client_api_endpoint(client_class): if universe_exists: options = client_options.ClientOptions(universe_domain=mock_universe) client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) else: client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == ( mock_endpoint if universe_exists else default_endpoint @@ -937,8 +928,7 @@ def test_big_query_write_client_client_api_endpoint(client_class): delattr(options, "universe_domain") with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == default_endpoint @@ -1089,8 +1079,8 @@ def test_big_query_write_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() - file_creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -1123,7 +1113,7 @@ def test_big_query_write_client_create_channel_credentials_file( ) def test_create_write_stream(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1161,7 +1151,7 @@ def test_create_write_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1180,7 +1170,7 @@ async def test_create_write_stream_async( transport: str = "grpc_asyncio", request_type=storage.CreateWriteStreamRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1223,7 +1213,7 @@ async def test_create_write_stream_async_from_dict(): def test_create_write_stream_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1255,7 +1245,7 @@ def test_create_write_stream_field_headers(): @pytest.mark.asyncio async def test_create_write_stream_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1286,7 +1276,7 @@ async def test_create_write_stream_field_headers_async(): def test_create_write_stream_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1316,7 +1306,7 @@ def test_create_write_stream_flattened(): def test_create_write_stream_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1332,7 +1322,7 @@ def test_create_write_stream_flattened_error(): @pytest.mark.asyncio async def test_create_write_stream_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1365,7 +1355,7 @@ async def test_create_write_stream_flattened_async(): @pytest.mark.asyncio async def test_create_write_stream_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1387,7 +1377,7 @@ async def test_create_write_stream_flattened_error_async(): ) def test_append_rows(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1417,7 +1407,7 @@ async def test_append_rows_async( transport: str = "grpc_asyncio", request_type=storage.AppendRowsRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1459,7 +1449,7 @@ async def test_append_rows_async_from_dict(): ) def test_get_write_stream(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1495,7 +1485,7 @@ def test_get_write_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1512,7 +1502,7 @@ async def test_get_write_stream_async( transport: str = "grpc_asyncio", request_type=storage.GetWriteStreamRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1553,7 +1543,7 @@ async def test_get_write_stream_async_from_dict(): def test_get_write_stream_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1583,7 +1573,7 @@ def test_get_write_stream_field_headers(): @pytest.mark.asyncio async def test_get_write_stream_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1612,7 +1602,7 @@ async def test_get_write_stream_field_headers_async(): def test_get_write_stream_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1636,7 +1626,7 @@ def test_get_write_stream_flattened(): def test_get_write_stream_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1651,7 +1641,7 @@ def test_get_write_stream_flattened_error(): @pytest.mark.asyncio async def test_get_write_stream_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1678,7 +1668,7 @@ async def test_get_write_stream_flattened_async(): @pytest.mark.asyncio async def test_get_write_stream_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1699,7 +1689,7 @@ async def test_get_write_stream_flattened_error_async(): ) def test_finalize_write_stream(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1731,7 +1721,7 @@ def test_finalize_write_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1750,7 +1740,7 @@ async def test_finalize_write_stream_async( transport: str = "grpc_asyncio", request_type=storage.FinalizeWriteStreamRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1787,7 +1777,7 @@ async def test_finalize_write_stream_async_from_dict(): def test_finalize_write_stream_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1819,7 +1809,7 @@ def test_finalize_write_stream_field_headers(): @pytest.mark.asyncio async def test_finalize_write_stream_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1852,7 +1842,7 @@ async def test_finalize_write_stream_field_headers_async(): def test_finalize_write_stream_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1878,7 +1868,7 @@ def test_finalize_write_stream_flattened(): def test_finalize_write_stream_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1893,7 +1883,7 @@ def test_finalize_write_stream_flattened_error(): @pytest.mark.asyncio async def test_finalize_write_stream_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1924,7 +1914,7 @@ async def test_finalize_write_stream_flattened_async(): @pytest.mark.asyncio async def test_finalize_write_stream_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1945,7 +1935,7 @@ async def test_finalize_write_stream_flattened_error_async(): ) def test_batch_commit_write_streams(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1974,7 +1964,7 @@ def test_batch_commit_write_streams_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1993,7 +1983,7 @@ async def test_batch_commit_write_streams_async( transport: str = "grpc_asyncio", request_type=storage.BatchCommitWriteStreamsRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2027,7 +2017,7 @@ async def test_batch_commit_write_streams_async_from_dict(): def test_batch_commit_write_streams_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2059,7 +2049,7 @@ def test_batch_commit_write_streams_field_headers(): @pytest.mark.asyncio async def test_batch_commit_write_streams_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2092,7 +2082,7 @@ async def test_batch_commit_write_streams_field_headers_async(): def test_batch_commit_write_streams_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2118,7 +2108,7 @@ def test_batch_commit_write_streams_flattened(): def test_batch_commit_write_streams_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2133,7 +2123,7 @@ def test_batch_commit_write_streams_flattened_error(): @pytest.mark.asyncio async def test_batch_commit_write_streams_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2164,7 +2154,7 @@ async def test_batch_commit_write_streams_flattened_async(): @pytest.mark.asyncio async def test_batch_commit_write_streams_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2185,7 +2175,7 @@ async def test_batch_commit_write_streams_flattened_error_async(): ) def test_flush_rows(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2215,7 +2205,7 @@ def test_flush_rows_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -2232,7 +2222,7 @@ async def test_flush_rows_async( transport: str = "grpc_asyncio", request_type=storage.FlushRowsRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2267,7 +2257,7 @@ async def test_flush_rows_async_from_dict(): def test_flush_rows_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2297,7 +2287,7 @@ def test_flush_rows_field_headers(): @pytest.mark.asyncio async def test_flush_rows_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2328,7 +2318,7 @@ async def test_flush_rows_field_headers_async(): def test_flush_rows_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2352,7 +2342,7 @@ def test_flush_rows_flattened(): def test_flush_rows_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2367,7 +2357,7 @@ def test_flush_rows_flattened_error(): @pytest.mark.asyncio async def test_flush_rows_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2396,7 +2386,7 @@ async def test_flush_rows_flattened_async(): @pytest.mark.asyncio async def test_flush_rows_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2411,17 +2401,17 @@ async def test_flush_rows_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryWriteClient( @@ -2431,7 +2421,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2446,13 +2436,12 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = BigQueryWriteClient( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) # It is an error to provide scopes and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryWriteClient( @@ -2464,7 +2453,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) client = BigQueryWriteClient(transport=transport) assert client.transport is transport @@ -2473,13 +2462,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.BigQueryWriteGrpcAsyncIOTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2495,7 +2484,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() @@ -2508,7 +2497,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = BigQueryWriteClient.get_transport_class(transport_name)( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert transport.kind == transport_name @@ -2516,7 +2505,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, @@ -2528,7 +2517,7 @@ def test_big_query_write_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.BigQueryWriteTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2540,7 +2529,7 @@ def test_big_query_write_base_transport(): ) as Transport: Transport.return_value = None transport = transports.BigQueryWriteTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2577,7 +2566,7 @@ def test_big_query_write_base_transport_with_credentials_file(): "google.cloud.bigquery_storage_v1.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2600,7 +2589,7 @@ def test_big_query_write_base_transport_with_adc(): "google.cloud.bigquery_storage_v1.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport() adc.assert_called_once() @@ -2608,7 +2597,7 @@ def test_big_query_write_base_transport_with_adc(): def test_big_query_write_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) BigQueryWriteClient() adc.assert_called_once_with( scopes=None, @@ -2632,7 +2621,7 @@ def test_big_query_write_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2682,7 +2671,7 @@ def test_big_query_write_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2714,7 +2703,7 @@ def test_big_query_write_transport_create_channel(transport_class, grpc_helpers) ], ) def test_big_query_write_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2760,7 +2749,7 @@ def test_big_query_write_grpc_transport_client_cert_source_for_mtls(transport_cl ) def test_big_query_write_host_no_port(transport_name): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com" ), @@ -2778,7 +2767,7 @@ def test_big_query_write_host_no_port(transport_name): ) def test_big_query_write_host_with_port(transport_name): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com:8000" ), @@ -2837,7 +2826,7 @@ def test_big_query_write_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -3080,7 +3069,7 @@ def test_client_with_default_client_info(): transports.BigQueryWriteTransport, "_prep_wrapped_messages" ) as prep: client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3090,7 +3079,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = BigQueryWriteClient.get_transport_class() transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3099,7 +3088,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) with mock.patch.object( @@ -3117,7 +3106,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3133,7 +3122,7 @@ def test_client_ctx(): ] for transport in transports: client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: diff --git a/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py b/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py index 5a6d55ff..b58942ca 100644 --- a/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py +++ b/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_read.py @@ -80,18 +80,6 @@ def modify_default_endpoint_template(client): ) -# Anonymous Credentials with universe domain property. If no universe domain is provided, then -# the default universe domain is "googleapis.com". -class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): - def __init__(self, universe_domain="googleapis.com"): - super(_AnonymousCredentialsWithUniverseDomain, self).__init__() - self._universe_domain = universe_domain - - @property - def universe_domain(self): - return self._universe_domain - - def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -302,7 +290,7 @@ def test__get_universe_domain(): ) def test__validate_universe_domain(client_class, transport_class, transport_name): client = client_class( - transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + transport=transport_class(credentials=ga_credentials.AnonymousCredentials()) ) assert client._validate_universe_domain() == True @@ -329,42 +317,49 @@ def test__validate_universe_domain(client_class, transport_class, transport_name client = client_class(transport=transport) assert client._validate_universe_domain() == True - # Test the case when there is a universe mismatch from the credentials. - client = client_class( - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain( - universe_domain="foo.com" - ) - ) - ) - with pytest.raises(ValueError) as excinfo: - client._validate_universe_domain() - assert ( - str(excinfo.value) - == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." - ) - - # Test the case when there is a universe mismatch from the client. - # - # TODO: Make this test unconditional once the minimum supported version of - # google-api-core becomes 2.15.0 or higher. - api_core_major, api_core_minor, _ = [ - int(part) for part in api_core_version.__version__.split(".") + # TODO: This is needed to cater for older versions of google-auth + # Make this test unconditional once the minimum supported version of + # google-auth becomes 2.23.0 or higher. + google_auth_major, google_auth_minor, _ = [ + int(part) for part in google.auth.__version__.split(".") ] - if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): - client = client_class( - client_options={"universe_domain": "bar.com"}, - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), - ), - ) + if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23): + credentials = ga_credentials.AnonymousCredentials() + credentials._universe_domain = "foo.com" + # Test the case when there is a universe mismatch from the credentials. + client = client_class(transport=transport_class(credentials=credentials)) with pytest.raises(ValueError) as excinfo: client._validate_universe_domain() assert ( str(excinfo.value) - == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." ) + # Test the case when there is a universe mismatch from the client. + # + # TODO: Make this test unconditional once the minimum supported version of + # google-api-core becomes 2.15.0 or higher. + api_core_major, api_core_minor, _ = [ + int(part) for part in api_core_version.__version__.split(".") + ] + if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): + client = client_class( + client_options={"universe_domain": "bar.com"}, + transport=transport_class( + credentials=ga_credentials.AnonymousCredentials(), + ), + ) + with pytest.raises(ValueError) as excinfo: + client._validate_universe_domain() + assert ( + str(excinfo.value) + == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + ) + + # Test that ValueError is raised if universe_domain is provided via client options and credentials is None + with pytest.raises(ValueError): + client._compare_universes("foo.bar", None) + @pytest.mark.parametrize( "client_class,transport_name", @@ -374,7 +369,7 @@ def test__validate_universe_domain(client_class, transport_class, transport_name ], ) def test_big_query_read_client_from_service_account_info(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -420,7 +415,7 @@ def test_big_query_read_client_service_account_always_use_jwt( ], ) def test_big_query_read_client_from_service_account_file(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -477,9 +472,7 @@ def test_big_query_read_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(BigQueryReadClient, "get_transport_class") as gtc: - transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain() - ) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -870,20 +863,20 @@ def test_big_query_read_client_client_api_endpoint(client_class): ) client = client_class( client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert client.api_endpoint == api_override # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == default_endpoint # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), @@ -895,13 +888,11 @@ def test_big_query_read_client_client_api_endpoint(client_class): if universe_exists: options = client_options.ClientOptions(universe_domain=mock_universe) client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) else: client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == ( mock_endpoint if universe_exists else default_endpoint @@ -917,8 +908,7 @@ def test_big_query_read_client_client_api_endpoint(client_class): delattr(options, "universe_domain") with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == default_endpoint @@ -1067,8 +1057,8 @@ def test_big_query_read_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() - file_creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -1100,7 +1090,7 @@ def test_big_query_read_client_create_channel_credentials_file( ) def test_create_read_session(request_type, transport: str = "grpc"): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1136,7 +1126,7 @@ def test_create_read_session_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1155,7 +1145,7 @@ async def test_create_read_session_async( transport: str = "grpc_asyncio", request_type=storage.CreateReadSessionRequest ): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1196,7 +1186,7 @@ async def test_create_read_session_async_from_dict(): def test_create_read_session_field_headers(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1228,7 +1218,7 @@ def test_create_read_session_field_headers(): @pytest.mark.asyncio async def test_create_read_session_field_headers_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1259,7 +1249,7 @@ async def test_create_read_session_field_headers_async(): def test_create_read_session_flattened(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1293,7 +1283,7 @@ def test_create_read_session_flattened(): def test_create_read_session_flattened_error(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1310,7 +1300,7 @@ def test_create_read_session_flattened_error(): @pytest.mark.asyncio async def test_create_read_session_flattened_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1347,7 +1337,7 @@ async def test_create_read_session_flattened_async(): @pytest.mark.asyncio async def test_create_read_session_flattened_error_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1370,7 +1360,7 @@ async def test_create_read_session_flattened_error_async(): ) def test_read_rows(request_type, transport: str = "grpc"): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1398,7 +1388,7 @@ def test_read_rows_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1415,7 +1405,7 @@ async def test_read_rows_async( transport: str = "grpc_asyncio", request_type=storage.ReadRowsRequest ): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1449,7 +1439,7 @@ async def test_read_rows_async_from_dict(): def test_read_rows_field_headers(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1479,7 +1469,7 @@ def test_read_rows_field_headers(): @pytest.mark.asyncio async def test_read_rows_field_headers_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1511,7 +1501,7 @@ async def test_read_rows_field_headers_async(): def test_read_rows_flattened(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1539,7 +1529,7 @@ def test_read_rows_flattened(): def test_read_rows_flattened_error(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1555,7 +1545,7 @@ def test_read_rows_flattened_error(): @pytest.mark.asyncio async def test_read_rows_flattened_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1586,7 +1576,7 @@ async def test_read_rows_flattened_async(): @pytest.mark.asyncio async def test_read_rows_flattened_error_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1608,7 +1598,7 @@ async def test_read_rows_flattened_error_async(): ) def test_split_read_stream(request_type, transport: str = "grpc"): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1637,7 +1627,7 @@ def test_split_read_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1656,7 +1646,7 @@ async def test_split_read_stream_async( transport: str = "grpc_asyncio", request_type=storage.SplitReadStreamRequest ): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1690,7 +1680,7 @@ async def test_split_read_stream_async_from_dict(): def test_split_read_stream_field_headers(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1722,7 +1712,7 @@ def test_split_read_stream_field_headers(): @pytest.mark.asyncio async def test_split_read_stream_field_headers_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1756,17 +1746,17 @@ async def test_split_read_stream_field_headers_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryReadClient( @@ -1776,7 +1766,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -1791,13 +1781,12 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = BigQueryReadClient( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) # It is an error to provide scopes and a transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryReadClient( @@ -1809,7 +1798,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) client = BigQueryReadClient(transport=transport) assert client.transport is transport @@ -1818,13 +1807,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryReadGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.BigQueryReadGrpcAsyncIOTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -1840,7 +1829,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() @@ -1853,7 +1842,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = BigQueryReadClient.get_transport_class(transport_name)( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert transport.kind == transport_name @@ -1861,7 +1850,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, @@ -1873,7 +1862,7 @@ def test_big_query_read_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.BigQueryReadTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -1885,7 +1874,7 @@ def test_big_query_read_base_transport(): ) as Transport: Transport.return_value = None transport = transports.BigQueryReadTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -1919,7 +1908,7 @@ def test_big_query_read_base_transport_with_credentials_file(): "google.cloud.bigquery_storage_v1beta2.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -1941,7 +1930,7 @@ def test_big_query_read_base_transport_with_adc(): "google.cloud.bigquery_storage_v1beta2.services.big_query_read.transports.BigQueryReadTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryReadTransport() adc.assert_called_once() @@ -1949,7 +1938,7 @@ def test_big_query_read_base_transport_with_adc(): def test_big_query_read_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) BigQueryReadClient() adc.assert_called_once_with( scopes=None, @@ -1972,7 +1961,7 @@ def test_big_query_read_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2021,7 +2010,7 @@ def test_big_query_read_transport_create_channel(transport_class, grpc_helpers): ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2049,7 +2038,7 @@ def test_big_query_read_transport_create_channel(transport_class, grpc_helpers): [transports.BigQueryReadGrpcTransport, transports.BigQueryReadGrpcAsyncIOTransport], ) def test_big_query_read_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2095,7 +2084,7 @@ def test_big_query_read_grpc_transport_client_cert_source_for_mtls(transport_cla ) def test_big_query_read_host_no_port(transport_name): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com" ), @@ -2113,7 +2102,7 @@ def test_big_query_read_host_no_port(transport_name): ) def test_big_query_read_host_with_port(transport_name): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com:8000" ), @@ -2167,7 +2156,7 @@ def test_big_query_read_transport_channel_mtls_with_client_cert_source(transport mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -2431,7 +2420,7 @@ def test_client_with_default_client_info(): transports.BigQueryReadTransport, "_prep_wrapped_messages" ) as prep: client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2441,7 +2430,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = BigQueryReadClient.get_transport_class() transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2450,7 +2439,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = BigQueryReadAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) with mock.patch.object( @@ -2468,7 +2457,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -2484,7 +2473,7 @@ def test_client_ctx(): ] for transport in transports: client = BigQueryReadClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: diff --git a/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py b/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py index d729506c..fdbe69dc 100644 --- a/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py +++ b/tests/unit/gapic/bigquery_storage_v1beta2/test_big_query_write.py @@ -83,18 +83,6 @@ def modify_default_endpoint_template(client): ) -# Anonymous Credentials with universe domain property. If no universe domain is provided, then -# the default universe domain is "googleapis.com". -class _AnonymousCredentialsWithUniverseDomain(ga_credentials.AnonymousCredentials): - def __init__(self, universe_domain="googleapis.com"): - super(_AnonymousCredentialsWithUniverseDomain, self).__init__() - self._universe_domain = universe_domain - - @property - def universe_domain(self): - return self._universe_domain - - def test__get_default_mtls_endpoint(): api_endpoint = "example.googleapis.com" api_mtls_endpoint = "example.mtls.googleapis.com" @@ -316,7 +304,7 @@ def test__get_universe_domain(): ) def test__validate_universe_domain(client_class, transport_class, transport_name): client = client_class( - transport=transport_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + transport=transport_class(credentials=ga_credentials.AnonymousCredentials()) ) assert client._validate_universe_domain() == True @@ -343,42 +331,49 @@ def test__validate_universe_domain(client_class, transport_class, transport_name client = client_class(transport=transport) assert client._validate_universe_domain() == True - # Test the case when there is a universe mismatch from the credentials. - client = client_class( - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain( - universe_domain="foo.com" - ) - ) - ) - with pytest.raises(ValueError) as excinfo: - client._validate_universe_domain() - assert ( - str(excinfo.value) - == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." - ) - - # Test the case when there is a universe mismatch from the client. - # - # TODO: Make this test unconditional once the minimum supported version of - # google-api-core becomes 2.15.0 or higher. - api_core_major, api_core_minor, _ = [ - int(part) for part in api_core_version.__version__.split(".") + # TODO: This is needed to cater for older versions of google-auth + # Make this test unconditional once the minimum supported version of + # google-auth becomes 2.23.0 or higher. + google_auth_major, google_auth_minor, _ = [ + int(part) for part in google.auth.__version__.split(".") ] - if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): - client = client_class( - client_options={"universe_domain": "bar.com"}, - transport=transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), - ), - ) + if google_auth_major > 2 or (google_auth_major == 2 and google_auth_minor >= 23): + credentials = ga_credentials.AnonymousCredentials() + credentials._universe_domain = "foo.com" + # Test the case when there is a universe mismatch from the credentials. + client = client_class(transport=transport_class(credentials=credentials)) with pytest.raises(ValueError) as excinfo: client._validate_universe_domain() assert ( str(excinfo.value) - == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + == "The configured universe domain (googleapis.com) does not match the universe domain found in the credentials (foo.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." ) + # Test the case when there is a universe mismatch from the client. + # + # TODO: Make this test unconditional once the minimum supported version of + # google-api-core becomes 2.15.0 or higher. + api_core_major, api_core_minor, _ = [ + int(part) for part in api_core_version.__version__.split(".") + ] + if api_core_major > 2 or (api_core_major == 2 and api_core_minor >= 15): + client = client_class( + client_options={"universe_domain": "bar.com"}, + transport=transport_class( + credentials=ga_credentials.AnonymousCredentials(), + ), + ) + with pytest.raises(ValueError) as excinfo: + client._validate_universe_domain() + assert ( + str(excinfo.value) + == "The configured universe domain (bar.com) does not match the universe domain found in the credentials (googleapis.com). If you haven't configured the universe domain explicitly, `googleapis.com` is the default." + ) + + # Test that ValueError is raised if universe_domain is provided via client options and credentials is None + with pytest.raises(ValueError): + client._compare_universes("foo.bar", None) + @pytest.mark.parametrize( "client_class,transport_name", @@ -388,7 +383,7 @@ def test__validate_universe_domain(client_class, transport_class, transport_name ], ) def test_big_query_write_client_from_service_account_info(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: @@ -434,7 +429,7 @@ def test_big_query_write_client_service_account_always_use_jwt( ], ) def test_big_query_write_client_from_service_account_file(client_class, transport_name): - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: @@ -491,9 +486,7 @@ def test_big_query_write_client_client_options( ): # Check that if channel is provided we won't create a new one. with mock.patch.object(BigQueryWriteClient, "get_transport_class") as gtc: - transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain() - ) + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) client = client_class(transport=transport) gtc.assert_not_called() @@ -890,20 +883,20 @@ def test_big_query_write_client_client_api_endpoint(client_class): ) client = client_class( client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert client.api_endpoint == api_override # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="never", # use the _DEFAULT_ENDPOINT_TEMPLATE populated with GDU as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == default_endpoint # If ClientOptions.api_endpoint is not set and GOOGLE_API_USE_MTLS_ENDPOINT="always", # use the DEFAULT_MTLS_ENDPOINT as the api endpoint. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): - client = client_class(credentials=_AnonymousCredentialsWithUniverseDomain()) + client = client_class(credentials=ga_credentials.AnonymousCredentials()) assert client.api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT # If ClientOptions.api_endpoint is not set, GOOGLE_API_USE_MTLS_ENDPOINT="auto" (default), @@ -915,13 +908,11 @@ def test_big_query_write_client_client_api_endpoint(client_class): if universe_exists: options = client_options.ClientOptions(universe_domain=mock_universe) client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) else: client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == ( mock_endpoint if universe_exists else default_endpoint @@ -937,8 +928,7 @@ def test_big_query_write_client_client_api_endpoint(client_class): delattr(options, "universe_domain") with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): client = client_class( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) assert client.api_endpoint == default_endpoint @@ -1089,8 +1079,8 @@ def test_big_query_write_client_create_channel_credentials_file( ) as adc, mock.patch.object( grpc_helpers, "create_channel" ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() - file_creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() load_creds.return_value = (file_creds, None) adc.return_value = (creds, None) client = client_class(client_options=options, transport=transport_name) @@ -1123,7 +1113,7 @@ def test_big_query_write_client_create_channel_credentials_file( ) def test_create_write_stream(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1157,7 +1147,7 @@ def test_create_write_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1176,7 +1166,7 @@ async def test_create_write_stream_async( transport: str = "grpc_asyncio", request_type=storage.CreateWriteStreamRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1215,7 +1205,7 @@ async def test_create_write_stream_async_from_dict(): def test_create_write_stream_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1247,7 +1237,7 @@ def test_create_write_stream_field_headers(): @pytest.mark.asyncio async def test_create_write_stream_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1278,7 +1268,7 @@ async def test_create_write_stream_field_headers_async(): def test_create_write_stream_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1308,7 +1298,7 @@ def test_create_write_stream_flattened(): def test_create_write_stream_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1324,7 +1314,7 @@ def test_create_write_stream_flattened_error(): @pytest.mark.asyncio async def test_create_write_stream_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1357,7 +1347,7 @@ async def test_create_write_stream_flattened_async(): @pytest.mark.asyncio async def test_create_write_stream_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1379,7 +1369,7 @@ async def test_create_write_stream_flattened_error_async(): ) def test_append_rows(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1409,7 +1399,7 @@ async def test_append_rows_async( transport: str = "grpc_asyncio", request_type=storage.AppendRowsRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1451,7 +1441,7 @@ async def test_append_rows_async_from_dict(): ) def test_get_write_stream(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1483,7 +1473,7 @@ def test_get_write_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1500,7 +1490,7 @@ async def test_get_write_stream_async( transport: str = "grpc_asyncio", request_type=storage.GetWriteStreamRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1537,7 +1527,7 @@ async def test_get_write_stream_async_from_dict(): def test_get_write_stream_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1567,7 +1557,7 @@ def test_get_write_stream_field_headers(): @pytest.mark.asyncio async def test_get_write_stream_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1596,7 +1586,7 @@ async def test_get_write_stream_field_headers_async(): def test_get_write_stream_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1620,7 +1610,7 @@ def test_get_write_stream_flattened(): def test_get_write_stream_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1635,7 +1625,7 @@ def test_get_write_stream_flattened_error(): @pytest.mark.asyncio async def test_get_write_stream_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1662,7 +1652,7 @@ async def test_get_write_stream_flattened_async(): @pytest.mark.asyncio async def test_get_write_stream_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1683,7 +1673,7 @@ async def test_get_write_stream_flattened_error_async(): ) def test_finalize_write_stream(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1715,7 +1705,7 @@ def test_finalize_write_stream_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1734,7 +1724,7 @@ async def test_finalize_write_stream_async( transport: str = "grpc_asyncio", request_type=storage.FinalizeWriteStreamRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1771,7 +1761,7 @@ async def test_finalize_write_stream_async_from_dict(): def test_finalize_write_stream_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1803,7 +1793,7 @@ def test_finalize_write_stream_field_headers(): @pytest.mark.asyncio async def test_finalize_write_stream_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -1836,7 +1826,7 @@ async def test_finalize_write_stream_field_headers_async(): def test_finalize_write_stream_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1862,7 +1852,7 @@ def test_finalize_write_stream_flattened(): def test_finalize_write_stream_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1877,7 +1867,7 @@ def test_finalize_write_stream_flattened_error(): @pytest.mark.asyncio async def test_finalize_write_stream_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1908,7 +1898,7 @@ async def test_finalize_write_stream_flattened_async(): @pytest.mark.asyncio async def test_finalize_write_stream_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -1929,7 +1919,7 @@ async def test_finalize_write_stream_flattened_error_async(): ) def test_batch_commit_write_streams(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1958,7 +1948,7 @@ def test_batch_commit_write_streams_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -1977,7 +1967,7 @@ async def test_batch_commit_write_streams_async( transport: str = "grpc_asyncio", request_type=storage.BatchCommitWriteStreamsRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2011,7 +2001,7 @@ async def test_batch_commit_write_streams_async_from_dict(): def test_batch_commit_write_streams_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2043,7 +2033,7 @@ def test_batch_commit_write_streams_field_headers(): @pytest.mark.asyncio async def test_batch_commit_write_streams_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2076,7 +2066,7 @@ async def test_batch_commit_write_streams_field_headers_async(): def test_batch_commit_write_streams_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2102,7 +2092,7 @@ def test_batch_commit_write_streams_flattened(): def test_batch_commit_write_streams_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2117,7 +2107,7 @@ def test_batch_commit_write_streams_flattened_error(): @pytest.mark.asyncio async def test_batch_commit_write_streams_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2148,7 +2138,7 @@ async def test_batch_commit_write_streams_flattened_async(): @pytest.mark.asyncio async def test_batch_commit_write_streams_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2169,7 +2159,7 @@ async def test_batch_commit_write_streams_flattened_error_async(): ) def test_flush_rows(request_type, transport: str = "grpc"): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2199,7 +2189,7 @@ def test_flush_rows_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) @@ -2216,7 +2206,7 @@ async def test_flush_rows_async( transport: str = "grpc_asyncio", request_type=storage.FlushRowsRequest ): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2251,7 +2241,7 @@ async def test_flush_rows_async_from_dict(): def test_flush_rows_field_headers(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2281,7 +2271,7 @@ def test_flush_rows_field_headers(): @pytest.mark.asyncio async def test_flush_rows_field_headers_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as @@ -2312,7 +2302,7 @@ async def test_flush_rows_field_headers_async(): def test_flush_rows_flattened(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2336,7 +2326,7 @@ def test_flush_rows_flattened(): def test_flush_rows_flattened_error(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2351,7 +2341,7 @@ def test_flush_rows_flattened_error(): @pytest.mark.asyncio async def test_flush_rows_flattened_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2380,7 +2370,7 @@ async def test_flush_rows_flattened_async(): @pytest.mark.asyncio async def test_flush_rows_flattened_error_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Attempting to call a method with both a request object and flattened @@ -2395,17 +2385,17 @@ async def test_flush_rows_flattened_error_async(): def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # It is an error to provide a credentials file and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryWriteClient( @@ -2415,7 +2405,7 @@ def test_credentials_transport_error(): # It is an error to provide an api_key and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) options = client_options.ClientOptions() options.api_key = "api_key" @@ -2430,13 +2420,12 @@ def test_credentials_transport_error(): options.api_key = "api_key" with pytest.raises(ValueError): client = BigQueryWriteClient( - client_options=options, - credentials=_AnonymousCredentialsWithUniverseDomain(), + client_options=options, credentials=ga_credentials.AnonymousCredentials() ) # It is an error to provide scopes and a transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = BigQueryWriteClient( @@ -2448,7 +2437,7 @@ def test_credentials_transport_error(): def test_transport_instance(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) client = BigQueryWriteClient(transport=transport) assert client.transport is transport @@ -2457,13 +2446,13 @@ def test_transport_instance(): def test_transport_get_channel(): # A client may be instantiated with a custom transport instance. transport = transports.BigQueryWriteGrpcTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel transport = transports.BigQueryWriteGrpcAsyncIOTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) channel = transport.grpc_channel assert channel @@ -2479,7 +2468,7 @@ def test_transport_get_channel(): def test_transport_adc(transport_class): # Test default credentials are used if not provided. with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class() adc.assert_called_once() @@ -2492,7 +2481,7 @@ def test_transport_adc(transport_class): ) def test_transport_kind(transport_name): transport = BigQueryWriteClient.get_transport_class(transport_name)( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert transport.kind == transport_name @@ -2500,7 +2489,7 @@ def test_transport_kind(transport_name): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( client.transport, @@ -2512,7 +2501,7 @@ def test_big_query_write_base_transport_error(): # Passing both a credentials object and credentials_file should raise an error with pytest.raises(core_exceptions.DuplicateCredentialArgs): transport = transports.BigQueryWriteTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), credentials_file="credentials.json", ) @@ -2524,7 +2513,7 @@ def test_big_query_write_base_transport(): ) as Transport: Transport.return_value = None transport = transports.BigQueryWriteTransport( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), ) # Every method on the transport should just blindly @@ -2561,7 +2550,7 @@ def test_big_query_write_base_transport_with_credentials_file(): "google.cloud.bigquery_storage_v1beta2.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - load_creds.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport( credentials_file="credentials.json", quota_project_id="octopus", @@ -2584,7 +2573,7 @@ def test_big_query_write_base_transport_with_adc(): "google.cloud.bigquery_storage_v1beta2.services.big_query_write.transports.BigQueryWriteTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.BigQueryWriteTransport() adc.assert_called_once() @@ -2592,7 +2581,7 @@ def test_big_query_write_base_transport_with_adc(): def test_big_query_write_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) BigQueryWriteClient() adc.assert_called_once_with( scopes=None, @@ -2616,7 +2605,7 @@ def test_big_query_write_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (_AnonymousCredentialsWithUniverseDomain(), None) + adc.return_value = (ga_credentials.AnonymousCredentials(), None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) adc.assert_called_once_with( scopes=["1", "2"], @@ -2666,7 +2655,7 @@ def test_big_query_write_transport_create_channel(transport_class, grpc_helpers) ) as adc, mock.patch.object( grpc_helpers, "create_channel", autospec=True ) as create_channel: - creds = _AnonymousCredentialsWithUniverseDomain() + creds = ga_credentials.AnonymousCredentials() adc.return_value = (creds, None) transport_class(quota_project_id="octopus", scopes=["1", "2"]) @@ -2698,7 +2687,7 @@ def test_big_query_write_transport_create_channel(transport_class, grpc_helpers) ], ) def test_big_query_write_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -2744,7 +2733,7 @@ def test_big_query_write_grpc_transport_client_cert_source_for_mtls(transport_cl ) def test_big_query_write_host_no_port(transport_name): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com" ), @@ -2762,7 +2751,7 @@ def test_big_query_write_host_no_port(transport_name): ) def test_big_query_write_host_with_port(transport_name): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="bigquerystorage.googleapis.com:8000" ), @@ -2821,7 +2810,7 @@ def test_big_query_write_transport_channel_mtls_with_client_cert_source( mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel - cred = _AnonymousCredentialsWithUniverseDomain() + cred = ga_credentials.AnonymousCredentials() with pytest.warns(DeprecationWarning): with mock.patch.object(google.auth, "default") as adc: adc.return_value = (cred, None) @@ -3064,7 +3053,7 @@ def test_client_with_default_client_info(): transports.BigQueryWriteTransport, "_prep_wrapped_messages" ) as prep: client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3074,7 +3063,7 @@ def test_client_with_default_client_info(): ) as prep: transport_class = BigQueryWriteClient.get_transport_class() transport = transport_class( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3083,7 +3072,7 @@ def test_client_with_default_client_info(): @pytest.mark.asyncio async def test_transport_close_async(): client = BigQueryWriteAsyncClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", ) with mock.patch.object( @@ -3101,7 +3090,7 @@ def test_transport_close(): for transport, close_name in transports.items(): client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) with mock.patch.object( type(getattr(client.transport, close_name)), "close" @@ -3117,7 +3106,7 @@ def test_client_ctx(): ] for transport in transports: client = BigQueryWriteClient( - credentials=_AnonymousCredentialsWithUniverseDomain(), transport=transport + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) # Test client calls underlying transport. with mock.patch.object(type(client.transport), "close") as close: