From d3a36920be18cdc079ec4abc43bc727262a40534 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Wed, 25 Nov 2026 19:27:25 -0700 Subject: [PATCH 1/3] added google-cloud-core to core-deps list --- packages/gapic-generator/gapic/templates/noxfile.py.j2 | 2 ++ .../gapic-generator/tests/integration/goldens/asset/noxfile.py | 2 ++ .../tests/integration/goldens/credentials/noxfile.py | 2 ++ .../tests/integration/goldens/eventarc/noxfile.py | 2 ++ .../tests/integration/goldens/logging/noxfile.py | 2 ++ .../tests/integration/goldens/logging_internal/noxfile.py | 2 ++ .../gapic-generator/tests/integration/goldens/redis/noxfile.py | 2 ++ .../tests/integration/goldens/redis_selective/noxfile.py | 2 ++ .../tests/integration/goldens/showcase/noxfile.py | 2 ++ .../tests/integration/goldens/storagebatchoperations/noxfile.py | 2 ++ packages/google-cloud-ndb/noxfile.py | 2 ++ 11 files changed, 22 insertions(+) diff --git a/packages/gapic-generator/gapic/templates/noxfile.py.j2 b/packages/gapic-generator/gapic/templates/noxfile.py.j2 index 2464d0653f07..e31fa7abb68c 100644 --- a/packages/gapic-generator/gapic/templates/noxfile.py.j2 +++ b/packages/gapic-generator/gapic/templates/noxfile.py.j2 @@ -516,6 +516,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -639,6 +640,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py index 87372f93db86..4524ca21cfe6 100755 --- a/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/asset/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py index 791b93813e03..117d3570afd4 100755 --- a/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/credentials/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py index 75df30bfc86d..2b514732910f 100755 --- a/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/eventarc/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py index 6955f4cfe4d3..1c7c6b57f566 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py index 6955f4cfe4d3..1c7c6b57f566 100755 --- a/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/logging_internal/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py index 43f67b01ddf7..cba023a1b919 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py index 43f67b01ddf7..cba023a1b919 100755 --- a/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/redis_selective/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/showcase/noxfile.py b/packages/gapic-generator/tests/integration/goldens/showcase/noxfile.py index 7d9d45bbf2f5..342ecd790b34 100755 --- a/packages/gapic-generator/tests/integration/goldens/showcase/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/showcase/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py index 17d431fe191c..e1eda843603c 100755 --- a/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py +++ b/packages/gapic-generator/tests/integration/goldens/storagebatchoperations/noxfile.py @@ -508,6 +508,7 @@ def prerelease_deps(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "grpcio>=1.75.1" if session.python >= "3.12" else "grpcio<=1.62.2", "grpcio-status", @@ -631,6 +632,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] diff --git a/packages/google-cloud-ndb/noxfile.py b/packages/google-cloud-ndb/noxfile.py index 43158b4cf800..5c9b466f0846 100644 --- a/packages/google-cloud-ndb/noxfile.py +++ b/packages/google-cloud-ndb/noxfile.py @@ -151,6 +151,7 @@ def prerelease_deps(session, protobuf_implementation): "grpcio-status", "google-api-core", "google-auth", + "google-cloud-core", "proto-plus", "google-cloud-testutils", # dependencies of google-cloud-testutils" @@ -518,6 +519,7 @@ def core_deps_from_source(session, protobuf_implementation): "googleapis-common-protos", "google-api-core", "google-auth", + "google-cloud-core", "grpc-google-iam-v1", "proto-plus", ] From 2e69e4860b9d8718f7819bca6aceaa203448e226 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Wed, 25 Nov 2026 19:30:06 -0700 Subject: [PATCH 2/3] pass universe domain in mocks --- .../tests/unit/bigquery/conftest.py | 4 +- .../tests/unit/bigquery/test_bigquery.py | 208 +++++++++++---- .../tests/unit/helpers.py | 4 +- .../tests/unit/test_client.py | 16 +- .../tests/unit/test_client_bigframes.py | 4 +- .../test_client_resumable_media_upload.py | 4 +- .../tests/unit/test_client_retry.py | 4 +- .../tests/unit/test_magics.py | 242 +++++++++++++----- .../tests/unit/test_opentelemetry_tracing.py | 8 +- .../tests/unit/test_table.py | 20 +- .../tests/unit/v2_client/_testing.py | 2 + .../tests/unit/test_client.py | 4 +- .../tests/unit/test_client.py | 4 +- .../tests/unit/test__logging.py | 4 +- .../tests/unit/test_client.py | 4 +- .../tests/unit/v1/_test_helpers.py | 4 +- .../tests/unit/v1/test_async_batch.py | 4 +- .../tests/unit/v1/test_async_client.py | 4 +- .../tests/unit/v1/test_async_transaction.py | 4 +- .../tests/unit/v1/test_base_batch.py | 4 +- .../tests/unit/v1/test_base_client.py | 20 +- .../tests/unit/v1/test_base_collection.py | 4 +- .../tests/unit/v1/test_base_document.py | 4 +- .../tests/unit/v1/test_batch.py | 4 +- .../tests/unit/v1/test_bulk_batch.py | 4 +- .../tests/unit/v1/test_bulk_writer.py | 4 +- .../tests/unit/v1/test_client.py | 4 +- .../tests/unit/v1/test_cross_language.py | 10 +- .../tests/unit/v1/test_document.py | 4 +- .../tests/unit/v1/test_transaction.py | 4 +- .../tests/unit/v1/test_vector.py | 4 +- .../tests/unit/test__gapic.py | 24 +- .../tests/unit/test__http.py | 4 +- .../tests/unit/test_client.py | 14 +- .../tests/unit/test_logger.py | 4 +- .../tests/unit/test_client.py | 2 +- .../tests/unit/test_client.py | 4 +- 37 files changed, 491 insertions(+), 179 deletions(-) diff --git a/packages/bigquery-magics/tests/unit/bigquery/conftest.py b/packages/bigquery-magics/tests/unit/bigquery/conftest.py index 3bda7a386beb..662ae7860054 100644 --- a/packages/bigquery-magics/tests/unit/bigquery/conftest.py +++ b/packages/bigquery-magics/tests/unit/bigquery/conftest.py @@ -63,7 +63,9 @@ def fail_if(name, globals, locals, fromlist, level): @pytest.fixture def mock_credentials(monkeypatch): credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent diff --git a/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py b/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py index 2260406faa61..a7690891ba2b 100644 --- a/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py +++ b/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py @@ -113,7 +113,9 @@ def test_context_with_default_connection(): bigquery_magics.context._connection = None default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -159,7 +161,9 @@ def test_context_with_custom_connection(): ) default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -318,7 +322,9 @@ def test__get_graph_schema_success(): ) def test__make_bqstorage_client(): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -332,7 +338,9 @@ def test__make_bqstorage_client_true_raises_import_error(missing_bq_storage): ImportError. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -354,7 +362,9 @@ def test__make_bqstorage_client_true_obsolete_dependency(): version, returns None, and raises a warning. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -432,7 +442,9 @@ def test_bigquery_magic_without_optional_arguments(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -483,7 +495,9 @@ def test_bigquery_graph_spanner_graph_notebook_missing(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -540,7 +554,9 @@ def test_bigquery_graph_int_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -597,7 +613,9 @@ def test_bigquery_graph_str_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -654,7 +672,9 @@ def test_bigquery_graph_json_json_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -728,7 +748,9 @@ def test_bigquery_graph_json_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -852,7 +874,9 @@ def test_bigquery_graph_size_exceeds_max(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) monkeypatch.setattr(bigquery_magics.context, "_credentials", mock_credentials) monkeypatch.setattr(bigquery_magics.context, "_project", PROJECT_ID) @@ -912,7 +936,9 @@ def test_bigquery_graph_size_exceeds_query_result_max(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) monkeypatch.setattr(bigquery_magics.context, "_credentials", mock_credentials) monkeypatch.setattr(bigquery_magics.context, "_project", PROJECT_ID) @@ -973,7 +999,9 @@ def test_bigquery_graph_with_args_serialization(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1051,7 +1079,9 @@ def test_bigquery_graph_colab(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1187,7 +1217,9 @@ def test_bigquery_graph_missing_spanner_deps(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1406,7 +1438,9 @@ def test_bigquery_magic_default_connection_user_agent(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1431,7 +1465,9 @@ def test_bigquery_magic_default_connection_user_agent_vscode(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1474,7 +1510,9 @@ def test_bigquery_magic_default_connection_user_agent_vscode_extension( bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1536,7 +1574,9 @@ def test_bigquery_magic_default_connection_user_agent_jupyter(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1563,7 +1603,9 @@ def test_bigquery_magic_default_connection_user_agent_jupyter_plugin(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1611,7 +1653,9 @@ def test_bigquery_magic_with_legacy_sql(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) run_query_patch = mock.patch("bigquery_magics.bigquery._run_query", autospec=True) @@ -1627,7 +1671,9 @@ def test_bigquery_magic_with_result_saved_to_variable(ipython_ns_cleanup): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "df")) @@ -1658,7 +1704,9 @@ def test_bigquery_magic_does_not_clear_display_in_verbose_mode(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) clear_patch = mock.patch( @@ -1677,7 +1725,9 @@ def test_bigquery_magic_clears_display_in_non_verbose_mode(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) clear_patch = mock.patch( @@ -1699,7 +1749,9 @@ def test_bigquery_magic_with_bqstorage_from_argument(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1769,7 +1821,9 @@ def test_bigquery_magic_with_rest_client_requested(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1811,7 +1865,9 @@ def test_bigquery_magic_w_max_results_invalid(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1833,7 +1889,9 @@ def test_bigquery_magic_w_max_results_valid_calls_queryjob_result(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1868,7 +1926,9 @@ def test_bigquery_magic_with_use_geodataframe(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1912,7 +1972,9 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1951,7 +2013,9 @@ def test_bigquery_magic_w_table_id_invalid(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1981,7 +2045,9 @@ def test_bigquery_magic_w_missing_query(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2010,7 +2076,9 @@ def test_bigquery_magic_w_table_id_and_default_variable( ipython_ns_cleanup.append((ip, "df")) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2046,7 +2114,9 @@ def test_bigquery_magic_w_table_id_and_destination_var(ipython_ns_cleanup): ipython_ns_cleanup.append((ip, "df")) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2083,7 +2153,9 @@ def test_bigquery_magic_w_table_id_and_bqstorage_client(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2123,7 +2195,9 @@ def test_bigquery_magic_dryrun_option_sets_job_config(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) run_query_patch = mock.patch("bigquery_magics.bigquery._run_query", autospec=True) @@ -2142,7 +2216,9 @@ def test_bigquery_magic_dryrun_option_returns_query_job(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True @@ -2164,7 +2240,9 @@ def test_bigquery_magic_dryrun_option_variable_error_message(ipython_ns_cleanup) ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "q_job")) @@ -2191,7 +2269,9 @@ def test_bigquery_magic_dryrun_option_saves_query_job_to_variable(ipython_ns_cle ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True @@ -2219,7 +2299,9 @@ def test_bigquery_magic_saves_query_job_to_variable_on_error(ipython_ns_cleanup) ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "result")) @@ -2254,7 +2336,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_invalid(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2289,7 +2373,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_overrides_context(param_value, ex query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2329,7 +2415,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_inplace(): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2369,7 +2457,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_setter(): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2511,7 +2601,9 @@ def test_bigquery_magic_with_project(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2621,7 +2713,9 @@ def test_bigquery_magic_with_multiple_options(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2649,7 +2743,9 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -2684,7 +2780,9 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -2725,7 +2823,9 @@ def test_bigquery_magic_with_dict_params_nonexisting(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @foo AS foo" @@ -2739,7 +2839,9 @@ def test_bigquery_magic_with_dict_params_incorrect_syntax(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @foo AS foo" @@ -2886,7 +2988,9 @@ def test_bigquery_magic_with_improperly_formatted_params(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @num AS num" diff --git a/packages/google-cloud-bigquery/tests/unit/helpers.py b/packages/google-cloud-bigquery/tests/unit/helpers.py index c5414138e8f5..a337015b2094 100644 --- a/packages/google-cloud-bigquery/tests/unit/helpers.py +++ b/packages/google-cloud-bigquery/tests/unit/helpers.py @@ -40,7 +40,9 @@ def _to_pyarrow(value): def make_client(project="PROJECT", **kw): - credentials = mock.Mock(spec=google.auth.credentials.Credentials) + credentials = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) return google.cloud.bigquery.client.Client(project, credentials, **kw) diff --git a/packages/google-cloud-bigquery/tests/unit/test_client.py b/packages/google-cloud-bigquery/tests/unit/test_client.py index 519e74adaeb7..0560a0721e71 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client.py @@ -63,10 +63,12 @@ from tests.unit.helpers import make_connection -def _make_credentials(): +def _make_credentials(universe_domain="googleapis.com"): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain=universe_domain + ) def _make_list_partitons_meta_info(project, dataset_id, table_id, num_rows=0): @@ -149,7 +151,7 @@ def test_ctor_w_empty_client_options(self): @mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}) def test_ctor_w_only_env_universe(self): - creds = _make_credentials() + creds = _make_credentials(universe_domain="foo.com") http = object() client = self._make_one( project=self.PROJECT, @@ -194,7 +196,7 @@ def test_ctor_w_client_options_object(self): reason="universe_domain not supported with google-api-core < 2.15.0", ) def test_ctor_w_client_options_universe(self): - creds = _make_credentials() + creds = _make_credentials(universe_domain="foo.com") http = object() client_options = {"universe_domain": "foo.com"} client = self._make_one( @@ -863,7 +865,7 @@ def test_ensure_bqstorage_client_uses_client_universe(self): bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage") mock_client = mock.create_autospec(bigquery_storage.BigQueryReadClient) - creds = _make_credentials() + creds = _make_credentials(universe_domain="foo.com") client = self._make_one( project=self.PROJECT, credentials=creds, @@ -882,7 +884,7 @@ def test_ensure_bqstorage_client_keeps_given_client_options(self): bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage") mock_client = mock.create_autospec(bigquery_storage.BigQueryReadClient) - creds = _make_credentials() + creds = _make_credentials(universe_domain="foo.com") client = self._make_one( project=self.PROJECT, credentials=creds, @@ -1118,7 +1120,7 @@ def test_get_shared_bqstorage_client_uses_universe_domain(self): bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage") mock_client = mock.create_autospec(bigquery_storage.BigQueryReadClient) - creds = _make_credentials() + creds = _make_credentials(universe_domain="foo.com") client = self._make_one( project=self.PROJECT, credentials=creds, diff --git a/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py b/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py index 0260da5e4bc8..00b1a00d58b4 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py @@ -43,7 +43,9 @@ def make_response(body, *, status_code: int = 200): def client(): """A real client object with mocked API requests.""" credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) http_session = mock.Mock() return google.cloud.bigquery.client.Client( diff --git a/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py b/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py index 642c18d15c11..228186b122f8 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py @@ -48,7 +48,9 @@ def mock_sleep(monkeypatch): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(*args, **kw): diff --git a/packages/google-cloud-bigquery/tests/unit/test_client_retry.py b/packages/google-cloud-bigquery/tests/unit/test_client_retry.py index f0e7ac88f302..76bf793067b1 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client_retry.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client_retry.py @@ -32,7 +32,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(*args, **kw): diff --git a/packages/google-cloud-bigquery/tests/unit/test_magics.py b/packages/google-cloud-bigquery/tests/unit/test_magics.py index 6076363d8a93..62a2a493d382 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_magics.py +++ b/packages/google-cloud-bigquery/tests/unit/test_magics.py @@ -49,7 +49,9 @@ def use_local_magics_context(monkeypatch): local_context = magics.Context() local_context._project = "unit-test-project" mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) local_context._credentials = mock_credentials monkeypatch.setattr(magics, "context", local_context) @@ -153,7 +155,9 @@ def test_context_resolves_unset_credentials_and_project(): project = "prahj-ekt" credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, project) @@ -176,7 +180,9 @@ def test_context_with_default_connection(monkeypatch): magics.context._connection = None default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -214,7 +220,9 @@ def test_context_credentials_and_project_can_be_set_explicitly(): project1 = "one-project-55564" project2 = "other-project-52569" credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, project1) @@ -242,7 +250,9 @@ def test_context_with_custom_connection(monkeypatch): ) default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -329,7 +339,9 @@ def test__run_query_dry_run_without_errors_is_silent(): def test__make_bqstorage_client_false(): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -343,7 +355,9 @@ def test__make_bqstorage_client_false(): ) def test__make_bqstorage_client_true(): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -357,7 +371,9 @@ def test__make_bqstorage_client_true_raises_import_error(missing_bq_storage): ImportError. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -379,7 +395,9 @@ def test__make_bqstorage_client_true_obsolete_dependency(): version, returns None, and raises a warning. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -410,7 +428,9 @@ def test__make_bqstorage_client_true_obsolete_dependency(): @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") def test__make_bqstorage_client_true_missing_gapic(missing_grpcio_lib): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) with pytest.raises(ImportError) as exc_context, missing_grpcio_lib: @@ -468,7 +488,9 @@ def test_bigquery_magic_without_optional_arguments(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -515,7 +537,9 @@ def test_bigquery_magic_default_connection_user_agent(monkeypatch): magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -539,7 +563,9 @@ def test_bigquery_magic_with_legacy_sql(monkeypatch, use_local_magics_context): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) run_query_patch = mock.patch( @@ -561,7 +587,9 @@ def test_bigquery_magic_with_result_saved_to_variable( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "df")) @@ -597,7 +625,9 @@ def test_bigquery_magic_does_not_clear_display_in_verbose_mode( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) clear_patch = mock.patch( @@ -621,7 +651,9 @@ def test_bigquery_magic_clears_display_in_non_verbose_mode( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) clear_patch = mock.patch( @@ -648,7 +680,9 @@ def test_bigquery_magic_with_bqstorage_from_argument( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -720,7 +754,9 @@ def test_bigquery_magic_with_rest_client_requested( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -765,7 +801,9 @@ def test_bigquery_magic_w_max_results_invalid(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -788,7 +826,9 @@ def test_bigquery_magic_w_max_results_valid_calls_queryjob_result(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -823,7 +863,9 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -862,7 +904,9 @@ def test_bigquery_magic_w_table_id_invalid(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -893,7 +937,9 @@ def test_bigquery_magic_w_missing_query(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -921,7 +967,9 @@ def test_bigquery_magic_w_table_id_and_destination_var(ipython_ns_cleanup, monke ipython_ns_cleanup.append((ip, "df")) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -962,7 +1010,9 @@ def test_bigquery_magic_w_table_id_and_bqstorage_client(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1005,7 +1055,9 @@ def test_bigquery_magic_dryrun_option_sets_job_config(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "project-from-context" @@ -1028,7 +1080,9 @@ def test_bigquery_magic_dryrun_option_returns_query_job(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "project-from-context" query_job_mock = mock.create_autospec( @@ -1056,7 +1110,9 @@ def test_bigquery_magic_dryrun_option_variable_error_message( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "project-from-context" @@ -1087,7 +1143,9 @@ def test_bigquery_magic_dryrun_option_saves_query_job_to_variable( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "project-from-context" query_job_mock = mock.create_autospec( @@ -1121,7 +1179,9 @@ def test_bigquery_magic_saves_query_job_to_variable_on_error( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "project-from-context" @@ -1158,7 +1218,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_invalid(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1197,7 +1259,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_overrides_context( query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1237,7 +1301,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_inplace(monkeypatch): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1277,7 +1343,9 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_setter(monkeypatch): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1306,7 +1374,11 @@ def test_bigquery_magic_with_no_query_cache(monkeypatch): monkeypatch.setattr( magics.context, "credentials", - mock.create_autospec(google.auth.credentials.Credentials, instance=True), + mock.create_autospec( + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", + ), ) monkeypatch.setattr(magics.context, "project", "project-from-context") @@ -1340,7 +1412,9 @@ def test_context_with_no_query_cache_from_context(monkeypatch): context = magics.Context() conn = make_connection() context._connection = conn - context.credentials = mock.create_autospec(google.auth.credentials.Credentials) + context.credentials = mock.create_autospec( + google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) context.default_query_job_config = bigquery.QueryJobConfig(use_query_cache=False) context.project = "project-from-context" monkeypatch.setattr(magics, "context", context) @@ -1372,7 +1446,9 @@ def test_bigquery_magic_w_progress_bar_type_w_context_setter(monkeypatch): magics.context.progress_bar_type = "tqdm_gui" mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1419,7 +1495,9 @@ def test_bigquery_magic_with_progress_bar_type(monkeypatch): context = magics.Context() conn = make_connection() context._connection = conn - context.credentials = mock.create_autospec(google.auth.credentials.Credentials) + context.credentials = mock.create_autospec( + google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) context.progress_bar_type = None context.project = "unit-test-project" monkeypatch.setattr(magics, "context", context) @@ -1447,7 +1525,9 @@ def test_bigquery_magic_with_project(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1574,7 +1654,9 @@ def test_bigquery_magic_with_multiple_options(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1605,7 +1687,9 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup, monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1645,7 +1729,9 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup, monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1692,7 +1778,9 @@ def test_bigquery_magic_with_dict_params_nonexisting(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @foo AS foo" @@ -1708,7 +1796,9 @@ def test_bigquery_magic_with_dict_params_incorrect_syntax(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @foo AS foo" @@ -1725,7 +1815,9 @@ def test_bigquery_magic_with_dict_params_duplicate(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @foo AS foo" @@ -1744,7 +1836,9 @@ def test_bigquery_magic_with_option_value_incorrect(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "unit-test-project" @@ -1764,7 +1858,9 @@ def test_bigquery_magic_with_dict_params_negative_value( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1807,7 +1903,9 @@ def test_bigquery_magic_with_dict_params_array_value(ipython_ns_cleanup, monkeyp monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1850,7 +1948,9 @@ def test_bigquery_magic_with_dict_params_tuple_value(ipython_ns_cleanup, monkeyp monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1893,7 +1993,9 @@ def test_bigquery_magic_with_improperly_formatted_params(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @num AS num" @@ -1914,7 +2016,9 @@ def test_bigquery_magic_valid_query_in_existing_variable( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "unit-test-project" @@ -1955,7 +2059,9 @@ def test_bigquery_magic_nonexisting_query_variable(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "unit-test-project" @@ -1981,7 +2087,9 @@ def test_bigquery_magic_empty_query_variable_name(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "unit-test-project" run_query_patch = mock.patch( @@ -2004,7 +2112,9 @@ def test_bigquery_magic_query_variable_non_string(ipython_ns_cleanup, monkeypatc monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "unit-test-project" @@ -2032,7 +2142,9 @@ def test_bigquery_magic_query_variable_not_identifier(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context.project = "unit-test-project" @@ -2061,7 +2173,9 @@ def test_bigquery_magic_with_invalid_multiple_option_values(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) sql = "SELECT @foo AS foo" @@ -2080,7 +2194,9 @@ def test_bigquery_magic_omits_tracebacks_from_error_message(monkeypatch): bigquery.load_ipython_extension(ip) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2109,7 +2225,9 @@ def test_bigquery_magic_w_destination_table_invalid_format(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2136,7 +2254,9 @@ def test_bigquery_magic_w_destination_table(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context._project = "test-project" @@ -2170,7 +2290,9 @@ def test_bigquery_magic_create_dataset_fails(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, instance=True + google.auth.credentials.Credentials, + instance=True, + universe_domain="googleapis.com", ) magics.context._project = "test-project" diff --git a/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py b/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py index 03e12e20e7f6..6431b7a5efa4 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py +++ b/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py @@ -200,7 +200,9 @@ def test_default_no_data_leakage(setup): from google.cloud.bigquery import client from google.cloud.bigquery import job - mock_credentials = mock.Mock(spec=google.auth.credentials.Credentials) + mock_credentials = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) test_client = client.Client( project="test_project", credentials=mock_credentials, location="test_location" ) @@ -248,7 +250,9 @@ def test_span_creation_error(setup): from google.cloud.bigquery import client from google.api_core.exceptions import GoogleAPICallError, InvalidArgument - mock_credentials = mock.Mock(spec=google.auth.credentials.Credentials) + mock_credentials = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) test_client = client.Client( project="test_project", credentials=mock_credentials, location="test_location" ) diff --git a/packages/google-cloud-bigquery/tests/unit/test_table.py b/packages/google-cloud-bigquery/tests/unit/test_table.py index 41a5eecace84..e1a1eea308ae 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_table.py +++ b/packages/google-cloud-bigquery/tests/unit/test_table.py @@ -3587,7 +3587,10 @@ def test_to_arrow_create_read_session_user_agent(self): ): client = client_module.Client( project="proj", - credentials=mock.Mock(spec=google.auth.credentials.Credentials), + credentials=mock.Mock( + spec=google.auth.credentials.Credentials, + universe_domain="googleapis.com", + ), ) row_iterator = mut.RowIterator( client, @@ -3641,7 +3644,10 @@ def test_to_arrow_create_read_session_user_agent_pandas_gbq_not_installed(self): ): client = client_module.Client( project="proj", - credentials=mock.Mock(spec=google.auth.credentials.Credentials), + credentials=mock.Mock( + spec=google.auth.credentials.Credentials, + universe_domain="googleapis.com", + ), ) row_iterator = mut.RowIterator( client, @@ -4968,7 +4974,10 @@ def test_to_dataframe_create_read_session_user_agent(self): ): client = client_module.Client( project="proj", - credentials=mock.Mock(spec=google.auth.credentials.Credentials), + credentials=mock.Mock( + spec=google.auth.credentials.Credentials, + universe_domain="googleapis.com", + ), ) row_iterator = mut.RowIterator( client, @@ -5022,7 +5031,10 @@ def test_to_dataframe_create_read_session_user_agent_pandas_gbq_not_installed(se ): client = client_module.Client( project="proj", - credentials=mock.Mock(spec=google.auth.credentials.Credentials), + credentials=mock.Mock( + spec=google.auth.credentials.Credentials, + universe_domain="googleapis.com", + ), ) row_iterator = mut.RowIterator( client, diff --git a/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py b/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py index e3da99269c9a..eabaa49ee942 100644 --- a/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py +++ b/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py @@ -38,11 +38,13 @@ class _CredentialsWithScopesAndQuotaProject( pass credentials = mock.Mock(spec=_CredentialsWithScopesAndQuotaProject) + credentials.universe_domain = BigtableClient._DEFAULT_UNIVERSE # Needed to mock universe domain and quota project for new data client tests credentials_with_scopes = mock.Mock(spec=_CredentialsWithScopesAndQuotaProject) credentials_with_scopes.universe_domain = BigtableClient._DEFAULT_UNIVERSE credentials_with_scopes.with_quota_project.return_value = credentials_with_scopes + credentials_with_scopes.with_scopes.return_value = credentials_with_scopes credentials.with_scopes.return_value = credentials_with_scopes return credentials diff --git a/packages/google-cloud-datastore/tests/unit/test_client.py b/packages/google-cloud-datastore/tests/unit/test_client.py index caaeef3a03a7..fccf5daeb306 100644 --- a/packages/google-cloud-datastore/tests/unit/test_client.py +++ b/packages/google-cloud-datastore/tests/unit/test_client.py @@ -1923,7 +1923,9 @@ def _make_datastore_api(*keys, **kwargs): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_entity_pb(project, kind, integer_id, name=None, str_val=None, database=None): diff --git a/packages/google-cloud-dns/tests/unit/test_client.py b/packages/google-cloud-dns/tests/unit/test_client.py index aa0a72b81694..96fd9da38da6 100644 --- a/packages/google-cloud-dns/tests/unit/test_client.py +++ b/packages/google-cloud-dns/tests/unit/test_client.py @@ -20,7 +20,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) class TestClient(unittest.TestCase): diff --git a/packages/google-cloud-error-reporting/tests/unit/test__logging.py b/packages/google-cloud-error-reporting/tests/unit/test__logging.py index 433c91929300..e1ba04abe0fb 100644 --- a/packages/google-cloud-error-reporting/tests/unit/test__logging.py +++ b/packages/google-cloud-error-reporting/tests/unit/test__logging.py @@ -20,7 +20,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) class Test_ErrorReportingLoggingAPI(unittest.TestCase): diff --git a/packages/google-cloud-error-reporting/tests/unit/test_client.py b/packages/google-cloud-error-reporting/tests/unit/test_client.py index 13abc8ba93d6..80e7cc272514 100644 --- a/packages/google-cloud-error-reporting/tests/unit/test_client.py +++ b/packages/google-cloud-error-reporting/tests/unit/test_client.py @@ -22,7 +22,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) class TestClient(unittest.TestCase): diff --git a/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py b/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py index 39f27ee8c2f2..36bf1ae8e55b 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py +++ b/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py @@ -33,7 +33,9 @@ def make_test_credentials() -> google.auth.credentials.Credentials: # type: ignore import google.auth.credentials # type: ignore - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def make_client( diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py index 43fa809819db..cfa3a75e157f 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py @@ -163,7 +163,9 @@ async def test_as_context_mgr_w_error(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py b/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py index 3aeef8f9f9c0..572a6a48a81e 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py @@ -577,7 +577,9 @@ def test_asyncclient_pipeline(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_batch_response(**kwargs): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py b/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py index a09dd1c5b9ef..dc4136b79789 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py @@ -926,7 +926,9 @@ def test_async_transactional_factory(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project="feral-tom-cat"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py index 3bd7c7e80689..6b1ee5a7c070 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py @@ -165,7 +165,9 @@ def _value_pb(**kwargs): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py index 3762af7815eb..19668f9fae72 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py @@ -164,8 +164,7 @@ def test_baseclient__firestore_api_helper_async_wo_emulator(): def test_baseclient__firestore_api_helper_w_emulator(): emulator_host = "localhost:8081" - with mock.patch("os.getenv") as getenv: - getenv.return_value = emulator_host + with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): client = _make_default_base_client() client_options = client._client_options = mock.Mock() @@ -222,9 +221,7 @@ def test_baseclient___rpc_metadata_property(): def test_baseclient__rpc_metadata_property_with_emulator(): emulator_host = "localhost:8081" - with mock.patch("os.getenv") as getenv: - getenv.return_value = emulator_host - + with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): credentials = _make_credentials() database = "quanta" client = _make_base_client( @@ -248,8 +245,7 @@ def test_baseclient__emulator_channel(): emulator_host = "localhost:8081" credentials = _make_credentials() database = "quanta" - with mock.patch("os.getenv") as getenv: - getenv.return_value = emulator_host + with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): credentials.id_token = None client = _make_base_client( project=PROJECT, credentials=credentials, database=database @@ -266,8 +262,7 @@ def test_baseclient__emulator_channel(): # NOTE: On windows, emulation requires an insecure channel. If this is # altered to use a secure channel, start by verifying that it still # works as expected on windows. - with mock.patch("os.getenv") as getenv: - getenv.return_value = emulator_host + with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): credentials.id_token = "test" client = _make_base_client( project=PROJECT, credentials=credentials, database=database @@ -299,8 +294,7 @@ def test_baseclient__target_helper_w_emulator_host(): emulator_host = "localhost:8081" credentials = _make_credentials() database = "quanta" - with mock.patch("os.getenv") as getenv: - getenv.return_value = emulator_host + with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): credentials.id_token = None client = _make_base_client( project=PROJECT, credentials=credentials, database=database @@ -545,7 +539,9 @@ def test__get_doc_mask_w_paths(): def _make_credentials(): import google.oauth2.credentials - return mock.Mock(spec=google.oauth2.credentials.Credentials) + return mock.Mock( + spec=google.oauth2.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_batch_response(**kwargs): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py index 79cfc3ac88c5..2accb23e91c6 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py @@ -468,7 +468,9 @@ def test__auto_id_fallback_to_random(mock_system_rand_choice, mock_rand_choice): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py index d22a37b07761..43e2e6b6cd13 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py @@ -546,7 +546,9 @@ def test__first_write_result_more_than_one(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project=DEFAULT_TEST_PROJECT): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_batch.py index 5e51222981c9..3b4c437ed733 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_batch.py @@ -157,7 +157,9 @@ def test_writebatch_as_context_mgr_w_error(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py index bd23c61dcafd..265ada1699d5 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py @@ -88,7 +88,9 @@ def test_bulkwritebatch_write_w_retry_timeout(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py index 7fb6776e06eb..6e0a8651387f 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py @@ -79,7 +79,9 @@ def _instantiate_executor(self): def _make_credentials(): from google.auth.credentials import Credentials - return mock.create_autospec(Credentials, project_id="project-id") + return mock.create_autospec( + Credentials, project_id="project-id", universe_domain="googleapis.com" + ) class _SyncClientMixin: diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_client.py b/packages/google-cloud-firestore/tests/unit/v1/test_client.py index 9d0199f9258b..dac67734209a 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_client.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_client.py @@ -35,7 +35,9 @@ def _make_client(*args, **kwargs): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_default_client(*args, **kwargs): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py b/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py index d2adeb2ba6b0..084f6110e17c 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py @@ -92,7 +92,9 @@ def _make_client_document(firestore_api, testcase): assert database == DEFAULT_DATABASE # Attach the fake GAPIC to a real client. - credentials = mock.Mock(spec=google.auth.credentials.Credentials) + credentials = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) client = Client(project=project, credentials=credentials) client._firestore_api_internal = firestore_api return client, client.document(doc_path) @@ -223,7 +225,9 @@ def test_listen_testprotos(test_proto): # pragma: NO COVER testcase = test_proto.listen testname = test_proto.description - credentials = mock.Mock(spec=google.auth.credentials.Credentials) + credentials = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) client = Client(project="project", credentials=credentials) # conformance data has db string as this db_str = "projects/projectID/databases/(default)" @@ -456,7 +460,7 @@ def parse_query(testcase): _directions = {"asc": Query.ASCENDING, "desc": Query.DESCENDING} - credentials = mock.create_autospec(Credentials) + credentials = mock.create_autospec(Credentials, universe_domain="googleapis.com") client = Client("projectID", credentials) path = parse_path(testcase.coll_path) collection = client.collection(*path) diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_document.py b/packages/google-cloud-firestore/tests/unit/v1/test_document.py index 96e21cb6c320..087a737cff43 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_document.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_document.py @@ -625,7 +625,9 @@ def test_documentreference_on_snapshot(watch): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project=DEFAULT_TEST_PROJECT, database=None): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py b/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py index 7a93615b3ea4..06c2efe294bf 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py @@ -948,7 +948,9 @@ def test_transactional_factory(): def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) def _make_client(project="feral-tom-cat", database=None): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_vector.py b/packages/google-cloud-firestore/tests/unit/v1/test_vector.py index d850fc1cfd16..f499c8bc1569 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_vector.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_vector.py @@ -42,7 +42,9 @@ def _make_firestore_api(): def _make_client(firestore_api): client = Client( project="dignity", - credentials=mock.Mock(spec=google.auth.credentials.Credentials), + credentials=mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ), database=None, ) client._firestore_api_internal = firestore_api diff --git a/packages/google-cloud-logging/tests/unit/test__gapic.py b/packages/google-cloud-logging/tests/unit/test__gapic.py index 340870572cc4..7a358197acd7 100644 --- a/packages/google-cloud-logging/tests/unit/test__gapic.py +++ b/packages/google-cloud-logging/tests/unit/test__gapic.py @@ -39,7 +39,9 @@ class Test_LoggingAPI(unittest.TestCase): @staticmethod def make_logging_api(): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock(spec=google.auth.credentials.Credentials) + creds = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) # Pass those credentials to the GAPIC client gapic_client = LoggingServiceV2Client(credentials=creds) @@ -49,7 +51,9 @@ def make_logging_api(): def test_ctor(self): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock(spec=google.auth.credentials.Credentials) + creds = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) # Pass those credentials to the GAPIC client gapic_client = LoggingServiceV2Client(credentials=creds) @@ -217,7 +221,9 @@ class Test_SinksAPI(unittest.TestCase): @staticmethod def make_sinks_api(): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock(spec=google.auth.credentials.Credentials) + creds = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) # Pass those credentials to the GAPIC client gapic_client = ConfigServiceV2Client(credentials=creds) @@ -227,7 +233,9 @@ def make_sinks_api(): def test_ctor(self): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock(spec=google.auth.credentials.Credentials) + creds = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) # Pass those credentials to the GAPIC client gapic_client = ConfigServiceV2Client(credentials=creds) @@ -433,7 +441,9 @@ class Test_MetricsAPI(unittest.TestCase): @staticmethod def make_metrics_api(): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock(spec=google.auth.credentials.Credentials) + creds = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) # Pass those credentials to the GAPIC client gapic_client = MetricsServiceV2Client(credentials=creds) @@ -443,7 +453,9 @@ def make_metrics_api(): def test_ctor(self): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock(spec=google.auth.credentials.Credentials) + creds = mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) # Pass those credentials to the GAPIC client gapic_client = MetricsServiceV2Client(credentials=creds) diff --git a/packages/google-cloud-logging/tests/unit/test__http.py b/packages/google-cloud-logging/tests/unit/test__http.py index 02e34b48d1af..25149f3ba00e 100644 --- a/packages/google-cloud-logging/tests/unit/test__http.py +++ b/packages/google-cloud-logging/tests/unit/test__http.py @@ -20,7 +20,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) class TestConnection(unittest.TestCase): diff --git a/packages/google-cloud-logging/tests/unit/test_client.py b/packages/google-cloud-logging/tests/unit/test_client.py index 387253fc79d2..2cdb4230fc71 100644 --- a/packages/google-cloud-logging/tests/unit/test_client.py +++ b/packages/google-cloud-logging/tests/unit/test_client.py @@ -24,10 +24,12 @@ ) -def _make_credentials(): +def _make_credentials(universe_domain="googleapis.com"): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain=universe_domain + ) class TestClient(unittest.TestCase): @@ -124,7 +126,7 @@ def test_ctor_default_universe_domain(self): ) def test_ctor_w_universe_domain_dict_http(self): - creds = _make_credentials() + creds = _make_credentials(universe_domain="example.com") client = self._make_one( project=self.PROJECT, credentials=creds, @@ -137,7 +139,7 @@ def test_ctor_w_universe_domain_dict_http(self): def test_ctor_w_universe_domain_client_options_object_http(self): from google.api_core.client_options import ClientOptions - creds = _make_credentials() + creds = _make_credentials(universe_domain="example.com") client_options = ClientOptions(universe_domain="example.com") client = self._make_one( project=self.PROJECT, @@ -151,7 +153,7 @@ def test_ctor_w_universe_domain_client_options_object_http(self): def test_ctor_w_universe_domain_env_var_http(self): import os - creds = _make_credentials() + creds = _make_credentials(universe_domain="example.com") with mock.patch.dict( os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "example.com"} ): @@ -166,7 +168,7 @@ def test_ctor_universe_domain_precedence(self): from google.api_core.client_options import ClientOptions - creds = _make_credentials() + creds = _make_credentials(universe_domain="example.com") with mock.patch.dict( os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "env-universe.example.com"} ): diff --git a/packages/google-cloud-logging/tests/unit/test_logger.py b/packages/google-cloud-logging/tests/unit/test_logger.py index aac65c948f8a..7d9d78f17c72 100644 --- a/packages/google-cloud-logging/tests/unit/test_logger.py +++ b/packages/google-cloud-logging/tests/unit/test_logger.py @@ -21,7 +21,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) class TestLogger(unittest.TestCase): diff --git a/packages/google-cloud-ndb/tests/unit/test_client.py b/packages/google-cloud-ndb/tests/unit/test_client.py index 458716a813d9..8779ab7a011e 100644 --- a/packages/google-cloud-ndb/tests/unit/test_client.py +++ b/packages/google-cloud-ndb/tests/unit/test_client.py @@ -28,7 +28,7 @@ @contextlib.contextmanager def patch_credentials(project): - creds = mock.Mock(spec=credentials.Credentials) + creds = mock.Mock(spec=credentials.Credentials, universe_domain="googleapis.com") patch = mock.patch("google.auth.default", return_value=(creds, project)) with patch: yield creds diff --git a/packages/google-cloud-runtimeconfig/tests/unit/test_client.py b/packages/google-cloud-runtimeconfig/tests/unit/test_client.py index 2d1e0f69a30f..2f8d61e11353 100644 --- a/packages/google-cloud-runtimeconfig/tests/unit/test_client.py +++ b/packages/google-cloud-runtimeconfig/tests/unit/test_client.py @@ -20,7 +20,9 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock(spec=google.auth.credentials.Credentials) + return mock.Mock( + spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" + ) class TestClient(unittest.TestCase): From 460553d6562906f103b9dfcc34b72ddd31983225 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Wed, 25 Nov 2026 22:45:22 -0700 Subject: [PATCH 3/3] Revert "pass universe domain in mocks" This reverts commit 2e69e4860b9d8718f7819bca6aceaa203448e226. --- .../tests/unit/bigquery/conftest.py | 4 +- .../tests/unit/bigquery/test_bigquery.py | 208 ++++----------- .../tests/unit/helpers.py | 4 +- .../tests/unit/test_client.py | 16 +- .../tests/unit/test_client_bigframes.py | 4 +- .../test_client_resumable_media_upload.py | 4 +- .../tests/unit/test_client_retry.py | 4 +- .../tests/unit/test_magics.py | 242 +++++------------- .../tests/unit/test_opentelemetry_tracing.py | 8 +- .../tests/unit/test_table.py | 20 +- .../tests/unit/v2_client/_testing.py | 2 - .../tests/unit/test_client.py | 4 +- .../tests/unit/test_client.py | 4 +- .../tests/unit/test__logging.py | 4 +- .../tests/unit/test_client.py | 4 +- .../tests/unit/v1/_test_helpers.py | 4 +- .../tests/unit/v1/test_async_batch.py | 4 +- .../tests/unit/v1/test_async_client.py | 4 +- .../tests/unit/v1/test_async_transaction.py | 4 +- .../tests/unit/v1/test_base_batch.py | 4 +- .../tests/unit/v1/test_base_client.py | 20 +- .../tests/unit/v1/test_base_collection.py | 4 +- .../tests/unit/v1/test_base_document.py | 4 +- .../tests/unit/v1/test_batch.py | 4 +- .../tests/unit/v1/test_bulk_batch.py | 4 +- .../tests/unit/v1/test_bulk_writer.py | 4 +- .../tests/unit/v1/test_client.py | 4 +- .../tests/unit/v1/test_cross_language.py | 10 +- .../tests/unit/v1/test_document.py | 4 +- .../tests/unit/v1/test_transaction.py | 4 +- .../tests/unit/v1/test_vector.py | 4 +- .../tests/unit/test__gapic.py | 24 +- .../tests/unit/test__http.py | 4 +- .../tests/unit/test_client.py | 14 +- .../tests/unit/test_logger.py | 4 +- .../tests/unit/test_client.py | 2 +- .../tests/unit/test_client.py | 4 +- 37 files changed, 179 insertions(+), 491 deletions(-) diff --git a/packages/bigquery-magics/tests/unit/bigquery/conftest.py b/packages/bigquery-magics/tests/unit/bigquery/conftest.py index 662ae7860054..3bda7a386beb 100644 --- a/packages/bigquery-magics/tests/unit/bigquery/conftest.py +++ b/packages/bigquery-magics/tests/unit/bigquery/conftest.py @@ -63,9 +63,7 @@ def fail_if(name, globals, locals, fromlist, level): @pytest.fixture def mock_credentials(monkeypatch): credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent diff --git a/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py b/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py index a7690891ba2b..2260406faa61 100644 --- a/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py +++ b/packages/bigquery-magics/tests/unit/bigquery/test_bigquery.py @@ -113,9 +113,7 @@ def test_context_with_default_connection(): bigquery_magics.context._connection = None default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -161,9 +159,7 @@ def test_context_with_custom_connection(): ) default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -322,9 +318,7 @@ def test__get_graph_schema_success(): ) def test__make_bqstorage_client(): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -338,9 +332,7 @@ def test__make_bqstorage_client_true_raises_import_error(missing_bq_storage): ImportError. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -362,9 +354,7 @@ def test__make_bqstorage_client_true_obsolete_dependency(): version, returns None, and raises a warning. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -442,9 +432,7 @@ def test_bigquery_magic_without_optional_arguments(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -495,9 +483,7 @@ def test_bigquery_graph_spanner_graph_notebook_missing(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -554,9 +540,7 @@ def test_bigquery_graph_int_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -613,9 +597,7 @@ def test_bigquery_graph_str_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -672,9 +654,7 @@ def test_bigquery_graph_json_json_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -748,9 +728,7 @@ def test_bigquery_graph_json_result(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -874,9 +852,7 @@ def test_bigquery_graph_size_exceeds_max(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) monkeypatch.setattr(bigquery_magics.context, "_credentials", mock_credentials) monkeypatch.setattr(bigquery_magics.context, "_project", PROJECT_ID) @@ -936,9 +912,7 @@ def test_bigquery_graph_size_exceeds_query_result_max(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) monkeypatch.setattr(bigquery_magics.context, "_credentials", mock_credentials) monkeypatch.setattr(bigquery_magics.context, "_project", PROJECT_ID) @@ -999,9 +973,7 @@ def test_bigquery_graph_with_args_serialization(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1079,9 +1051,7 @@ def test_bigquery_graph_colab(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1217,9 +1187,7 @@ def test_bigquery_graph_missing_spanner_deps(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1438,9 +1406,7 @@ def test_bigquery_magic_default_connection_user_agent(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1465,9 +1431,7 @@ def test_bigquery_magic_default_connection_user_agent_vscode(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1510,9 +1474,7 @@ def test_bigquery_magic_default_connection_user_agent_vscode_extension( bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1574,9 +1536,7 @@ def test_bigquery_magic_default_connection_user_agent_jupyter(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1603,9 +1563,7 @@ def test_bigquery_magic_default_connection_user_agent_jupyter_plugin(): bigquery_magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1653,9 +1611,7 @@ def test_bigquery_magic_with_legacy_sql(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) run_query_patch = mock.patch("bigquery_magics.bigquery._run_query", autospec=True) @@ -1671,9 +1627,7 @@ def test_bigquery_magic_with_result_saved_to_variable(ipython_ns_cleanup): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "df")) @@ -1704,9 +1658,7 @@ def test_bigquery_magic_does_not_clear_display_in_verbose_mode(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) clear_patch = mock.patch( @@ -1725,9 +1677,7 @@ def test_bigquery_magic_clears_display_in_non_verbose_mode(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) clear_patch = mock.patch( @@ -1749,9 +1699,7 @@ def test_bigquery_magic_with_bqstorage_from_argument(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1821,9 +1769,7 @@ def test_bigquery_magic_with_rest_client_requested(monkeypatch): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1865,9 +1811,7 @@ def test_bigquery_magic_w_max_results_invalid(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1889,9 +1833,7 @@ def test_bigquery_magic_w_max_results_valid_calls_queryjob_result(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1926,9 +1868,7 @@ def test_bigquery_magic_with_use_geodataframe(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1972,9 +1912,7 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2013,9 +1951,7 @@ def test_bigquery_magic_w_table_id_invalid(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2045,9 +1981,7 @@ def test_bigquery_magic_w_missing_query(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2076,9 +2010,7 @@ def test_bigquery_magic_w_table_id_and_default_variable( ipython_ns_cleanup.append((ip, "df")) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2114,9 +2046,7 @@ def test_bigquery_magic_w_table_id_and_destination_var(ipython_ns_cleanup): ipython_ns_cleanup.append((ip, "df")) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2153,9 +2083,7 @@ def test_bigquery_magic_w_table_id_and_bqstorage_client(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2195,9 +2123,7 @@ def test_bigquery_magic_dryrun_option_sets_job_config(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) run_query_patch = mock.patch("bigquery_magics.bigquery._run_query", autospec=True) @@ -2216,9 +2142,7 @@ def test_bigquery_magic_dryrun_option_returns_query_job(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True @@ -2240,9 +2164,7 @@ def test_bigquery_magic_dryrun_option_variable_error_message(ipython_ns_cleanup) ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "q_job")) @@ -2269,9 +2191,7 @@ def test_bigquery_magic_dryrun_option_saves_query_job_to_variable(ipython_ns_cle ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True @@ -2299,9 +2219,7 @@ def test_bigquery_magic_saves_query_job_to_variable_on_error(ipython_ns_cleanup) ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "result")) @@ -2336,9 +2254,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_invalid(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2373,9 +2289,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_overrides_context(param_value, ex query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2415,9 +2329,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_inplace(): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2457,9 +2369,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_setter(): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2601,9 +2511,7 @@ def test_bigquery_magic_with_project(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2713,9 +2621,7 @@ def test_bigquery_magic_with_multiple_options(): bigquery_magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2743,9 +2649,7 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -2780,9 +2684,7 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -2823,9 +2725,7 @@ def test_bigquery_magic_with_dict_params_nonexisting(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @foo AS foo" @@ -2839,9 +2739,7 @@ def test_bigquery_magic_with_dict_params_incorrect_syntax(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @foo AS foo" @@ -2988,9 +2886,7 @@ def test_bigquery_magic_with_improperly_formatted_params(): ip = globalipapp.get_ipython() ip.extension_manager.load_extension("bigquery_magics") bigquery_magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @num AS num" diff --git a/packages/google-cloud-bigquery/tests/unit/helpers.py b/packages/google-cloud-bigquery/tests/unit/helpers.py index a337015b2094..c5414138e8f5 100644 --- a/packages/google-cloud-bigquery/tests/unit/helpers.py +++ b/packages/google-cloud-bigquery/tests/unit/helpers.py @@ -40,9 +40,7 @@ def _to_pyarrow(value): def make_client(project="PROJECT", **kw): - credentials = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + credentials = mock.Mock(spec=google.auth.credentials.Credentials) return google.cloud.bigquery.client.Client(project, credentials, **kw) diff --git a/packages/google-cloud-bigquery/tests/unit/test_client.py b/packages/google-cloud-bigquery/tests/unit/test_client.py index 0560a0721e71..519e74adaeb7 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client.py @@ -63,12 +63,10 @@ from tests.unit.helpers import make_connection -def _make_credentials(universe_domain="googleapis.com"): +def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain=universe_domain - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_list_partitons_meta_info(project, dataset_id, table_id, num_rows=0): @@ -151,7 +149,7 @@ def test_ctor_w_empty_client_options(self): @mock.patch.dict(os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com"}) def test_ctor_w_only_env_universe(self): - creds = _make_credentials(universe_domain="foo.com") + creds = _make_credentials() http = object() client = self._make_one( project=self.PROJECT, @@ -196,7 +194,7 @@ def test_ctor_w_client_options_object(self): reason="universe_domain not supported with google-api-core < 2.15.0", ) def test_ctor_w_client_options_universe(self): - creds = _make_credentials(universe_domain="foo.com") + creds = _make_credentials() http = object() client_options = {"universe_domain": "foo.com"} client = self._make_one( @@ -865,7 +863,7 @@ def test_ensure_bqstorage_client_uses_client_universe(self): bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage") mock_client = mock.create_autospec(bigquery_storage.BigQueryReadClient) - creds = _make_credentials(universe_domain="foo.com") + creds = _make_credentials() client = self._make_one( project=self.PROJECT, credentials=creds, @@ -884,7 +882,7 @@ def test_ensure_bqstorage_client_keeps_given_client_options(self): bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage") mock_client = mock.create_autospec(bigquery_storage.BigQueryReadClient) - creds = _make_credentials(universe_domain="foo.com") + creds = _make_credentials() client = self._make_one( project=self.PROJECT, credentials=creds, @@ -1120,7 +1118,7 @@ def test_get_shared_bqstorage_client_uses_universe_domain(self): bigquery_storage = pytest.importorskip("google.cloud.bigquery_storage") mock_client = mock.create_autospec(bigquery_storage.BigQueryReadClient) - creds = _make_credentials(universe_domain="foo.com") + creds = _make_credentials() client = self._make_one( project=self.PROJECT, credentials=creds, diff --git a/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py b/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py index 00b1a00d58b4..0260da5e4bc8 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client_bigframes.py @@ -43,9 +43,7 @@ def make_response(body, *, status_code: int = 200): def client(): """A real client object with mocked API requests.""" credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) http_session = mock.Mock() return google.cloud.bigquery.client.Client( diff --git a/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py b/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py index 228186b122f8..642c18d15c11 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client_resumable_media_upload.py @@ -48,9 +48,7 @@ def mock_sleep(monkeypatch): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(*args, **kw): diff --git a/packages/google-cloud-bigquery/tests/unit/test_client_retry.py b/packages/google-cloud-bigquery/tests/unit/test_client_retry.py index 76bf793067b1..f0e7ac88f302 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_client_retry.py +++ b/packages/google-cloud-bigquery/tests/unit/test_client_retry.py @@ -32,9 +32,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(*args, **kw): diff --git a/packages/google-cloud-bigquery/tests/unit/test_magics.py b/packages/google-cloud-bigquery/tests/unit/test_magics.py index 62a2a493d382..6076363d8a93 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_magics.py +++ b/packages/google-cloud-bigquery/tests/unit/test_magics.py @@ -49,9 +49,7 @@ def use_local_magics_context(monkeypatch): local_context = magics.Context() local_context._project = "unit-test-project" mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) local_context._credentials = mock_credentials monkeypatch.setattr(magics, "context", local_context) @@ -155,9 +153,7 @@ def test_context_resolves_unset_credentials_and_project(): project = "prahj-ekt" credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, project) @@ -180,9 +176,7 @@ def test_context_with_default_connection(monkeypatch): magics.context._connection = None default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -220,9 +214,7 @@ def test_context_credentials_and_project_can_be_set_explicitly(): project1 = "one-project-55564" project2 = "other-project-52569" credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, project1) @@ -250,9 +242,7 @@ def test_context_with_custom_connection(monkeypatch): ) default_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) credentials_patch = mock.patch( "google.auth.default", return_value=(default_credentials, "project-from-env") @@ -339,9 +329,7 @@ def test__run_query_dry_run_without_errors_is_silent(): def test__make_bqstorage_client_false(): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -355,9 +343,7 @@ def test__make_bqstorage_client_false(): ) def test__make_bqstorage_client_true(): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -371,9 +357,7 @@ def test__make_bqstorage_client_true_raises_import_error(missing_bq_storage): ImportError. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -395,9 +379,7 @@ def test__make_bqstorage_client_true_obsolete_dependency(): version, returns None, and raises a warning. """ credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) test_client = bigquery.Client( project="test_project", credentials=credentials_mock, location="test_location" @@ -428,9 +410,7 @@ def test__make_bqstorage_client_true_obsolete_dependency(): @pytest.mark.skipif(pandas is None, reason="Requires `pandas`") def test__make_bqstorage_client_true_missing_gapic(missing_grpcio_lib): credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) with pytest.raises(ImportError) as exc_context, missing_grpcio_lib: @@ -488,9 +468,7 @@ def test_bigquery_magic_without_optional_arguments(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -537,9 +515,7 @@ def test_bigquery_magic_default_connection_user_agent(monkeypatch): magics.context._connection = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -563,9 +539,7 @@ def test_bigquery_magic_with_legacy_sql(monkeypatch, use_local_magics_context): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) run_query_patch = mock.patch( @@ -587,9 +561,7 @@ def test_bigquery_magic_with_result_saved_to_variable( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "df")) @@ -625,9 +597,7 @@ def test_bigquery_magic_does_not_clear_display_in_verbose_mode( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) clear_patch = mock.patch( @@ -651,9 +621,7 @@ def test_bigquery_magic_clears_display_in_non_verbose_mode( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) clear_patch = mock.patch( @@ -680,9 +648,7 @@ def test_bigquery_magic_with_bqstorage_from_argument( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -754,9 +720,7 @@ def test_bigquery_magic_with_rest_client_requested( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -801,9 +765,7 @@ def test_bigquery_magic_w_max_results_invalid(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -826,9 +788,7 @@ def test_bigquery_magic_w_max_results_valid_calls_queryjob_result(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -863,9 +823,7 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -904,9 +862,7 @@ def test_bigquery_magic_w_table_id_invalid(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -937,9 +893,7 @@ def test_bigquery_magic_w_missing_query(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -967,9 +921,7 @@ def test_bigquery_magic_w_table_id_and_destination_var(ipython_ns_cleanup, monke ipython_ns_cleanup.append((ip, "df")) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1010,9 +962,7 @@ def test_bigquery_magic_w_table_id_and_bqstorage_client(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1055,9 +1005,7 @@ def test_bigquery_magic_dryrun_option_sets_job_config(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "project-from-context" @@ -1080,9 +1028,7 @@ def test_bigquery_magic_dryrun_option_returns_query_job(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "project-from-context" query_job_mock = mock.create_autospec( @@ -1110,9 +1056,7 @@ def test_bigquery_magic_dryrun_option_variable_error_message( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "project-from-context" @@ -1143,9 +1087,7 @@ def test_bigquery_magic_dryrun_option_saves_query_job_to_variable( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "project-from-context" query_job_mock = mock.create_autospec( @@ -1179,9 +1121,7 @@ def test_bigquery_magic_saves_query_job_to_variable_on_error( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "project-from-context" @@ -1218,9 +1158,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_invalid(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1259,9 +1197,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_overrides_context( query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1301,9 +1237,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_inplace(monkeypatch): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1343,9 +1277,7 @@ def test_bigquery_magic_w_maximum_bytes_billed_w_context_setter(monkeypatch): query_results = {"jobReference": job_reference, "totalRows": 0, "jobComplete": True} data = {"jobReference": job_reference, "totalRows": 0, "rows": []} credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1374,11 +1306,7 @@ def test_bigquery_magic_with_no_query_cache(monkeypatch): monkeypatch.setattr( magics.context, "credentials", - mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", - ), + mock.create_autospec(google.auth.credentials.Credentials, instance=True), ) monkeypatch.setattr(magics.context, "project", "project-from-context") @@ -1412,9 +1340,7 @@ def test_context_with_no_query_cache_from_context(monkeypatch): context = magics.Context() conn = make_connection() context._connection = conn - context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + context.credentials = mock.create_autospec(google.auth.credentials.Credentials) context.default_query_job_config = bigquery.QueryJobConfig(use_query_cache=False) context.project = "project-from-context" monkeypatch.setattr(magics, "context", context) @@ -1446,9 +1372,7 @@ def test_bigquery_magic_w_progress_bar_type_w_context_setter(monkeypatch): magics.context.progress_bar_type = "tqdm_gui" mock_credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) # Set up the context with monkeypatch so that it's reset for subsequent @@ -1495,9 +1419,7 @@ def test_bigquery_magic_with_progress_bar_type(monkeypatch): context = magics.Context() conn = make_connection() context._connection = conn - context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + context.credentials = mock.create_autospec(google.auth.credentials.Credentials) context.progress_bar_type = None context.project = "unit-test-project" monkeypatch.setattr(magics, "context", context) @@ -1525,9 +1447,7 @@ def test_bigquery_magic_with_project(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1654,9 +1574,7 @@ def test_bigquery_magic_with_multiple_options(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -1687,9 +1605,7 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup, monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1729,9 +1645,7 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup, monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1778,9 +1692,7 @@ def test_bigquery_magic_with_dict_params_nonexisting(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @foo AS foo" @@ -1796,9 +1708,7 @@ def test_bigquery_magic_with_dict_params_incorrect_syntax(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @foo AS foo" @@ -1815,9 +1725,7 @@ def test_bigquery_magic_with_dict_params_duplicate(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @foo AS foo" @@ -1836,9 +1744,7 @@ def test_bigquery_magic_with_option_value_incorrect(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "unit-test-project" @@ -1858,9 +1764,7 @@ def test_bigquery_magic_with_dict_params_negative_value( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1903,9 +1807,7 @@ def test_bigquery_magic_with_dict_params_array_value(ipython_ns_cleanup, monkeyp monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1948,9 +1850,7 @@ def test_bigquery_magic_with_dict_params_tuple_value(ipython_ns_cleanup, monkeyp monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) ipython_ns_cleanup.append((ip, "params_dict_df")) @@ -1993,9 +1893,7 @@ def test_bigquery_magic_with_improperly_formatted_params(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @num AS num" @@ -2016,9 +1914,7 @@ def test_bigquery_magic_valid_query_in_existing_variable( monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "unit-test-project" @@ -2059,9 +1955,7 @@ def test_bigquery_magic_nonexisting_query_variable(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "unit-test-project" @@ -2087,9 +1981,7 @@ def test_bigquery_magic_empty_query_variable_name(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "unit-test-project" run_query_patch = mock.patch( @@ -2112,9 +2004,7 @@ def test_bigquery_magic_query_variable_non_string(ipython_ns_cleanup, monkeypatc monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "unit-test-project" @@ -2142,9 +2032,7 @@ def test_bigquery_magic_query_variable_not_identifier(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context.project = "unit-test-project" @@ -2173,9 +2061,7 @@ def test_bigquery_magic_with_invalid_multiple_option_values(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) sql = "SELECT @foo AS foo" @@ -2194,9 +2080,7 @@ def test_bigquery_magic_omits_tracebacks_from_error_message(monkeypatch): bigquery.load_ipython_extension(ip) credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2225,9 +2109,7 @@ def test_bigquery_magic_w_destination_table_invalid_format(monkeypatch): magics.context._project = None credentials_mock = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) default_patch = mock.patch( "google.auth.default", return_value=(credentials_mock, "general-project") @@ -2254,9 +2136,7 @@ def test_bigquery_magic_w_destination_table(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context._project = "test-project" @@ -2290,9 +2170,7 @@ def test_bigquery_magic_create_dataset_fails(monkeypatch): monkeypatch.setattr(bigquery, "bigquery_magics", None) bigquery.load_ipython_extension(ip) magics.context.credentials = mock.create_autospec( - google.auth.credentials.Credentials, - instance=True, - universe_domain="googleapis.com", + google.auth.credentials.Credentials, instance=True ) magics.context._project = "test-project" diff --git a/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py b/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py index 6431b7a5efa4..03e12e20e7f6 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py +++ b/packages/google-cloud-bigquery/tests/unit/test_opentelemetry_tracing.py @@ -200,9 +200,7 @@ def test_default_no_data_leakage(setup): from google.cloud.bigquery import client from google.cloud.bigquery import job - mock_credentials = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + mock_credentials = mock.Mock(spec=google.auth.credentials.Credentials) test_client = client.Client( project="test_project", credentials=mock_credentials, location="test_location" ) @@ -250,9 +248,7 @@ def test_span_creation_error(setup): from google.cloud.bigquery import client from google.api_core.exceptions import GoogleAPICallError, InvalidArgument - mock_credentials = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + mock_credentials = mock.Mock(spec=google.auth.credentials.Credentials) test_client = client.Client( project="test_project", credentials=mock_credentials, location="test_location" ) diff --git a/packages/google-cloud-bigquery/tests/unit/test_table.py b/packages/google-cloud-bigquery/tests/unit/test_table.py index e1a1eea308ae..41a5eecace84 100644 --- a/packages/google-cloud-bigquery/tests/unit/test_table.py +++ b/packages/google-cloud-bigquery/tests/unit/test_table.py @@ -3587,10 +3587,7 @@ def test_to_arrow_create_read_session_user_agent(self): ): client = client_module.Client( project="proj", - credentials=mock.Mock( - spec=google.auth.credentials.Credentials, - universe_domain="googleapis.com", - ), + credentials=mock.Mock(spec=google.auth.credentials.Credentials), ) row_iterator = mut.RowIterator( client, @@ -3644,10 +3641,7 @@ def test_to_arrow_create_read_session_user_agent_pandas_gbq_not_installed(self): ): client = client_module.Client( project="proj", - credentials=mock.Mock( - spec=google.auth.credentials.Credentials, - universe_domain="googleapis.com", - ), + credentials=mock.Mock(spec=google.auth.credentials.Credentials), ) row_iterator = mut.RowIterator( client, @@ -4974,10 +4968,7 @@ def test_to_dataframe_create_read_session_user_agent(self): ): client = client_module.Client( project="proj", - credentials=mock.Mock( - spec=google.auth.credentials.Credentials, - universe_domain="googleapis.com", - ), + credentials=mock.Mock(spec=google.auth.credentials.Credentials), ) row_iterator = mut.RowIterator( client, @@ -5031,10 +5022,7 @@ def test_to_dataframe_create_read_session_user_agent_pandas_gbq_not_installed(se ): client = client_module.Client( project="proj", - credentials=mock.Mock( - spec=google.auth.credentials.Credentials, - universe_domain="googleapis.com", - ), + credentials=mock.Mock(spec=google.auth.credentials.Credentials), ) row_iterator = mut.RowIterator( client, diff --git a/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py b/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py index eabaa49ee942..e3da99269c9a 100644 --- a/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py +++ b/packages/google-cloud-bigtable/tests/unit/v2_client/_testing.py @@ -38,13 +38,11 @@ class _CredentialsWithScopesAndQuotaProject( pass credentials = mock.Mock(spec=_CredentialsWithScopesAndQuotaProject) - credentials.universe_domain = BigtableClient._DEFAULT_UNIVERSE # Needed to mock universe domain and quota project for new data client tests credentials_with_scopes = mock.Mock(spec=_CredentialsWithScopesAndQuotaProject) credentials_with_scopes.universe_domain = BigtableClient._DEFAULT_UNIVERSE credentials_with_scopes.with_quota_project.return_value = credentials_with_scopes - credentials_with_scopes.with_scopes.return_value = credentials_with_scopes credentials.with_scopes.return_value = credentials_with_scopes return credentials diff --git a/packages/google-cloud-datastore/tests/unit/test_client.py b/packages/google-cloud-datastore/tests/unit/test_client.py index fccf5daeb306..caaeef3a03a7 100644 --- a/packages/google-cloud-datastore/tests/unit/test_client.py +++ b/packages/google-cloud-datastore/tests/unit/test_client.py @@ -1923,9 +1923,7 @@ def _make_datastore_api(*keys, **kwargs): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_entity_pb(project, kind, integer_id, name=None, str_val=None, database=None): diff --git a/packages/google-cloud-dns/tests/unit/test_client.py b/packages/google-cloud-dns/tests/unit/test_client.py index 96fd9da38da6..aa0a72b81694 100644 --- a/packages/google-cloud-dns/tests/unit/test_client.py +++ b/packages/google-cloud-dns/tests/unit/test_client.py @@ -20,9 +20,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class TestClient(unittest.TestCase): diff --git a/packages/google-cloud-error-reporting/tests/unit/test__logging.py b/packages/google-cloud-error-reporting/tests/unit/test__logging.py index e1ba04abe0fb..433c91929300 100644 --- a/packages/google-cloud-error-reporting/tests/unit/test__logging.py +++ b/packages/google-cloud-error-reporting/tests/unit/test__logging.py @@ -20,9 +20,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class Test_ErrorReportingLoggingAPI(unittest.TestCase): diff --git a/packages/google-cloud-error-reporting/tests/unit/test_client.py b/packages/google-cloud-error-reporting/tests/unit/test_client.py index 80e7cc272514..13abc8ba93d6 100644 --- a/packages/google-cloud-error-reporting/tests/unit/test_client.py +++ b/packages/google-cloud-error-reporting/tests/unit/test_client.py @@ -22,9 +22,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class TestClient(unittest.TestCase): diff --git a/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py b/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py index 36bf1ae8e55b..39f27ee8c2f2 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py +++ b/packages/google-cloud-firestore/tests/unit/v1/_test_helpers.py @@ -33,9 +33,7 @@ def make_test_credentials() -> google.auth.credentials.Credentials: # type: ignore import google.auth.credentials # type: ignore - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def make_client( diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py index cfa3a75e157f..43fa809819db 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_async_batch.py @@ -163,9 +163,7 @@ async def test_as_context_mgr_w_error(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py b/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py index 572a6a48a81e..3aeef8f9f9c0 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_async_client.py @@ -577,9 +577,7 @@ def test_asyncclient_pipeline(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_batch_response(**kwargs): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py b/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py index dc4136b79789..a09dd1c5b9ef 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_async_transaction.py @@ -926,9 +926,7 @@ def test_async_transactional_factory(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project="feral-tom-cat"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py index 6b1ee5a7c070..3bd7c7e80689 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_batch.py @@ -165,9 +165,7 @@ def _value_pb(**kwargs): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py index 19668f9fae72..3762af7815eb 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_client.py @@ -164,7 +164,8 @@ def test_baseclient__firestore_api_helper_async_wo_emulator(): def test_baseclient__firestore_api_helper_w_emulator(): emulator_host = "localhost:8081" - with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): + with mock.patch("os.getenv") as getenv: + getenv.return_value = emulator_host client = _make_default_base_client() client_options = client._client_options = mock.Mock() @@ -221,7 +222,9 @@ def test_baseclient___rpc_metadata_property(): def test_baseclient__rpc_metadata_property_with_emulator(): emulator_host = "localhost:8081" - with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): + with mock.patch("os.getenv") as getenv: + getenv.return_value = emulator_host + credentials = _make_credentials() database = "quanta" client = _make_base_client( @@ -245,7 +248,8 @@ def test_baseclient__emulator_channel(): emulator_host = "localhost:8081" credentials = _make_credentials() database = "quanta" - with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): + with mock.patch("os.getenv") as getenv: + getenv.return_value = emulator_host credentials.id_token = None client = _make_base_client( project=PROJECT, credentials=credentials, database=database @@ -262,7 +266,8 @@ def test_baseclient__emulator_channel(): # NOTE: On windows, emulation requires an insecure channel. If this is # altered to use a secure channel, start by verifying that it still # works as expected on windows. - with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): + with mock.patch("os.getenv") as getenv: + getenv.return_value = emulator_host credentials.id_token = "test" client = _make_base_client( project=PROJECT, credentials=credentials, database=database @@ -294,7 +299,8 @@ def test_baseclient__target_helper_w_emulator_host(): emulator_host = "localhost:8081" credentials = _make_credentials() database = "quanta" - with mock.patch("os.environ", {"FIRESTORE_EMULATOR_HOST": emulator_host}): + with mock.patch("os.getenv") as getenv: + getenv.return_value = emulator_host credentials.id_token = None client = _make_base_client( project=PROJECT, credentials=credentials, database=database @@ -539,9 +545,7 @@ def test__get_doc_mask_w_paths(): def _make_credentials(): import google.oauth2.credentials - return mock.Mock( - spec=google.oauth2.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.oauth2.credentials.Credentials) def _make_batch_response(**kwargs): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py index 2accb23e91c6..79cfc3ac88c5 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_collection.py @@ -468,9 +468,7 @@ def test__auto_id_fallback_to_random(mock_system_rand_choice, mock_rand_choice): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py b/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py index 43e2e6b6cd13..d22a37b07761 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_base_document.py @@ -546,9 +546,7 @@ def test__first_write_result_more_than_one(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project=DEFAULT_TEST_PROJECT): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_batch.py index 3b4c437ed733..5e51222981c9 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_batch.py @@ -157,9 +157,7 @@ def test_writebatch_as_context_mgr_w_error(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py index 265ada1699d5..bd23c61dcafd 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_batch.py @@ -88,9 +88,7 @@ def test_bulkwritebatch_write_w_retry_timeout(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project="seventy-nine"): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py index 6e0a8651387f..7fb6776e06eb 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_bulk_writer.py @@ -79,9 +79,7 @@ def _instantiate_executor(self): def _make_credentials(): from google.auth.credentials import Credentials - return mock.create_autospec( - Credentials, project_id="project-id", universe_domain="googleapis.com" - ) + return mock.create_autospec(Credentials, project_id="project-id") class _SyncClientMixin: diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_client.py b/packages/google-cloud-firestore/tests/unit/v1/test_client.py index dac67734209a..9d0199f9258b 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_client.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_client.py @@ -35,9 +35,7 @@ def _make_client(*args, **kwargs): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_default_client(*args, **kwargs): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py b/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py index 084f6110e17c..d2adeb2ba6b0 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_cross_language.py @@ -92,9 +92,7 @@ def _make_client_document(firestore_api, testcase): assert database == DEFAULT_DATABASE # Attach the fake GAPIC to a real client. - credentials = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + credentials = mock.Mock(spec=google.auth.credentials.Credentials) client = Client(project=project, credentials=credentials) client._firestore_api_internal = firestore_api return client, client.document(doc_path) @@ -225,9 +223,7 @@ def test_listen_testprotos(test_proto): # pragma: NO COVER testcase = test_proto.listen testname = test_proto.description - credentials = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + credentials = mock.Mock(spec=google.auth.credentials.Credentials) client = Client(project="project", credentials=credentials) # conformance data has db string as this db_str = "projects/projectID/databases/(default)" @@ -460,7 +456,7 @@ def parse_query(testcase): _directions = {"asc": Query.ASCENDING, "desc": Query.DESCENDING} - credentials = mock.create_autospec(Credentials, universe_domain="googleapis.com") + credentials = mock.create_autospec(Credentials) client = Client("projectID", credentials) path = parse_path(testcase.coll_path) collection = client.collection(*path) diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_document.py b/packages/google-cloud-firestore/tests/unit/v1/test_document.py index 087a737cff43..96e21cb6c320 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_document.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_document.py @@ -625,9 +625,7 @@ def test_documentreference_on_snapshot(watch): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project=DEFAULT_TEST_PROJECT, database=None): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py b/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py index 06c2efe294bf..7a93615b3ea4 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_transaction.py @@ -948,9 +948,7 @@ def test_transactional_factory(): def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) def _make_client(project="feral-tom-cat", database=None): diff --git a/packages/google-cloud-firestore/tests/unit/v1/test_vector.py b/packages/google-cloud-firestore/tests/unit/v1/test_vector.py index f499c8bc1569..d850fc1cfd16 100644 --- a/packages/google-cloud-firestore/tests/unit/v1/test_vector.py +++ b/packages/google-cloud-firestore/tests/unit/v1/test_vector.py @@ -42,9 +42,7 @@ def _make_firestore_api(): def _make_client(firestore_api): client = Client( project="dignity", - credentials=mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ), + credentials=mock.Mock(spec=google.auth.credentials.Credentials), database=None, ) client._firestore_api_internal = firestore_api diff --git a/packages/google-cloud-logging/tests/unit/test__gapic.py b/packages/google-cloud-logging/tests/unit/test__gapic.py index 7a358197acd7..340870572cc4 100644 --- a/packages/google-cloud-logging/tests/unit/test__gapic.py +++ b/packages/google-cloud-logging/tests/unit/test__gapic.py @@ -39,9 +39,7 @@ class Test_LoggingAPI(unittest.TestCase): @staticmethod def make_logging_api(): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + creds = mock.Mock(spec=google.auth.credentials.Credentials) # Pass those credentials to the GAPIC client gapic_client = LoggingServiceV2Client(credentials=creds) @@ -51,9 +49,7 @@ def make_logging_api(): def test_ctor(self): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + creds = mock.Mock(spec=google.auth.credentials.Credentials) # Pass those credentials to the GAPIC client gapic_client = LoggingServiceV2Client(credentials=creds) @@ -221,9 +217,7 @@ class Test_SinksAPI(unittest.TestCase): @staticmethod def make_sinks_api(): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + creds = mock.Mock(spec=google.auth.credentials.Credentials) # Pass those credentials to the GAPIC client gapic_client = ConfigServiceV2Client(credentials=creds) @@ -233,9 +227,7 @@ def make_sinks_api(): def test_ctor(self): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + creds = mock.Mock(spec=google.auth.credentials.Credentials) # Pass those credentials to the GAPIC client gapic_client = ConfigServiceV2Client(credentials=creds) @@ -441,9 +433,7 @@ class Test_MetricsAPI(unittest.TestCase): @staticmethod def make_metrics_api(): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + creds = mock.Mock(spec=google.auth.credentials.Credentials) # Pass those credentials to the GAPIC client gapic_client = MetricsServiceV2Client(credentials=creds) @@ -453,9 +443,7 @@ def make_metrics_api(): def test_ctor(self): # Create a dummy credentials object to help ensure unit test isolation - creds = mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + creds = mock.Mock(spec=google.auth.credentials.Credentials) # Pass those credentials to the GAPIC client gapic_client = MetricsServiceV2Client(credentials=creds) diff --git a/packages/google-cloud-logging/tests/unit/test__http.py b/packages/google-cloud-logging/tests/unit/test__http.py index 25149f3ba00e..02e34b48d1af 100644 --- a/packages/google-cloud-logging/tests/unit/test__http.py +++ b/packages/google-cloud-logging/tests/unit/test__http.py @@ -20,9 +20,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class TestConnection(unittest.TestCase): diff --git a/packages/google-cloud-logging/tests/unit/test_client.py b/packages/google-cloud-logging/tests/unit/test_client.py index 2cdb4230fc71..387253fc79d2 100644 --- a/packages/google-cloud-logging/tests/unit/test_client.py +++ b/packages/google-cloud-logging/tests/unit/test_client.py @@ -24,12 +24,10 @@ ) -def _make_credentials(universe_domain="googleapis.com"): +def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain=universe_domain - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class TestClient(unittest.TestCase): @@ -126,7 +124,7 @@ def test_ctor_default_universe_domain(self): ) def test_ctor_w_universe_domain_dict_http(self): - creds = _make_credentials(universe_domain="example.com") + creds = _make_credentials() client = self._make_one( project=self.PROJECT, credentials=creds, @@ -139,7 +137,7 @@ def test_ctor_w_universe_domain_dict_http(self): def test_ctor_w_universe_domain_client_options_object_http(self): from google.api_core.client_options import ClientOptions - creds = _make_credentials(universe_domain="example.com") + creds = _make_credentials() client_options = ClientOptions(universe_domain="example.com") client = self._make_one( project=self.PROJECT, @@ -153,7 +151,7 @@ def test_ctor_w_universe_domain_client_options_object_http(self): def test_ctor_w_universe_domain_env_var_http(self): import os - creds = _make_credentials(universe_domain="example.com") + creds = _make_credentials() with mock.patch.dict( os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "example.com"} ): @@ -168,7 +166,7 @@ def test_ctor_universe_domain_precedence(self): from google.api_core.client_options import ClientOptions - creds = _make_credentials(universe_domain="example.com") + creds = _make_credentials() with mock.patch.dict( os.environ, {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": "env-universe.example.com"} ): diff --git a/packages/google-cloud-logging/tests/unit/test_logger.py b/packages/google-cloud-logging/tests/unit/test_logger.py index 7d9d78f17c72..aac65c948f8a 100644 --- a/packages/google-cloud-logging/tests/unit/test_logger.py +++ b/packages/google-cloud-logging/tests/unit/test_logger.py @@ -21,9 +21,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class TestLogger(unittest.TestCase): diff --git a/packages/google-cloud-ndb/tests/unit/test_client.py b/packages/google-cloud-ndb/tests/unit/test_client.py index 8779ab7a011e..458716a813d9 100644 --- a/packages/google-cloud-ndb/tests/unit/test_client.py +++ b/packages/google-cloud-ndb/tests/unit/test_client.py @@ -28,7 +28,7 @@ @contextlib.contextmanager def patch_credentials(project): - creds = mock.Mock(spec=credentials.Credentials, universe_domain="googleapis.com") + creds = mock.Mock(spec=credentials.Credentials) patch = mock.patch("google.auth.default", return_value=(creds, project)) with patch: yield creds diff --git a/packages/google-cloud-runtimeconfig/tests/unit/test_client.py b/packages/google-cloud-runtimeconfig/tests/unit/test_client.py index 2f8d61e11353..2d1e0f69a30f 100644 --- a/packages/google-cloud-runtimeconfig/tests/unit/test_client.py +++ b/packages/google-cloud-runtimeconfig/tests/unit/test_client.py @@ -20,9 +20,7 @@ def _make_credentials(): import google.auth.credentials - return mock.Mock( - spec=google.auth.credentials.Credentials, universe_domain="googleapis.com" - ) + return mock.Mock(spec=google.auth.credentials.Credentials) class TestClient(unittest.TestCase):