diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py index 960adf75d302..27d6fe08f93a 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/transports/base.py @@ -101,7 +101,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py index ca2dc417e174..9d8e470ac6b4 100644 --- a/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py +++ b/packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_catalog/transports/base.py @@ -99,7 +99,6 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id diff --git a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py index 661e4d6cf2a8..c03ffa5af712 100644 --- a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py +++ b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_billing.py @@ -242,20 +242,20 @@ def test_cloud_billing_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -312,7 +312,7 @@ def test_cloud_billing_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -407,7 +407,7 @@ def test_cloud_billing_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -438,7 +438,7 @@ def test_cloud_billing_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -469,9 +469,10 @@ def test_cloud_billing_client_client_options_from_dict(): ) -def test_get_billing_account( - transport: str = "grpc", request_type=cloud_billing.GetBillingAccountRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.GetBillingAccountRequest, dict,] +) +def test_get_billing_account(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -506,10 +507,6 @@ def test_get_billing_account( assert response.master_billing_account == "master_billing_account_value" -def test_get_billing_account_from_dict(): - test_get_billing_account(request_type=dict) - - def test_get_billing_account_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -699,9 +696,10 @@ async def test_get_billing_account_flattened_error_async(): ) -def test_list_billing_accounts( - transport: str = "grpc", request_type=cloud_billing.ListBillingAccountsRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.ListBillingAccountsRequest, dict,] +) +def test_list_billing_accounts(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -730,10 +728,6 @@ def test_list_billing_accounts( assert response.next_page_token == "next_page_token_value" -def test_list_billing_accounts_from_dict(): - test_list_billing_accounts(request_type=dict) - - def test_list_billing_accounts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -791,8 +785,10 @@ async def test_list_billing_accounts_async_from_dict(): await test_list_billing_accounts_async(request_type=dict) -def test_list_billing_accounts_pager(): - client = CloudBillingClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_billing_accounts_pager(transport_name: str = "grpc"): + client = CloudBillingClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -834,8 +830,10 @@ def test_list_billing_accounts_pager(): assert all(isinstance(i, cloud_billing.BillingAccount) for i in results) -def test_list_billing_accounts_pages(): - client = CloudBillingClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_billing_accounts_pages(transport_name: str = "grpc"): + client = CloudBillingClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -958,9 +956,10 @@ async def test_list_billing_accounts_async_pages(): assert page_.raw_page.next_page_token == token -def test_update_billing_account( - transport: str = "grpc", request_type=cloud_billing.UpdateBillingAccountRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.UpdateBillingAccountRequest, dict,] +) +def test_update_billing_account(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -995,10 +994,6 @@ def test_update_billing_account( assert response.master_billing_account == "master_billing_account_value" -def test_update_billing_account_from_dict(): - test_update_billing_account(request_type=dict) - - def test_update_billing_account_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1203,9 +1198,10 @@ async def test_update_billing_account_flattened_error_async(): ) -def test_create_billing_account( - transport: str = "grpc", request_type=cloud_billing.CreateBillingAccountRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.CreateBillingAccountRequest, dict,] +) +def test_create_billing_account(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1240,10 +1236,6 @@ def test_create_billing_account( assert response.master_billing_account == "master_billing_account_value" -def test_create_billing_account_from_dict(): - test_create_billing_account(request_type=dict) - - def test_create_billing_account_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1385,9 +1377,10 @@ async def test_create_billing_account_flattened_error_async(): ) -def test_list_project_billing_info( - transport: str = "grpc", request_type=cloud_billing.ListProjectBillingInfoRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.ListProjectBillingInfoRequest, dict,] +) +def test_list_project_billing_info(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1416,10 +1409,6 @@ def test_list_project_billing_info( assert response.next_page_token == "next_page_token_value" -def test_list_project_billing_info_from_dict(): - test_list_project_billing_info(request_type=dict) - - def test_list_project_billing_info_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -1604,8 +1593,10 @@ async def test_list_project_billing_info_flattened_error_async(): ) -def test_list_project_billing_info_pager(): - client = CloudBillingClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_project_billing_info_pager(transport_name: str = "grpc"): + client = CloudBillingClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1650,8 +1641,10 @@ def test_list_project_billing_info_pager(): assert all(isinstance(i, cloud_billing.ProjectBillingInfo) for i in results) -def test_list_project_billing_info_pages(): - client = CloudBillingClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_project_billing_info_pages(transport_name: str = "grpc"): + client = CloudBillingClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1774,9 +1767,10 @@ async def test_list_project_billing_info_async_pages(): assert page_.raw_page.next_page_token == token -def test_get_project_billing_info( - transport: str = "grpc", request_type=cloud_billing.GetProjectBillingInfoRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.GetProjectBillingInfoRequest, dict,] +) +def test_get_project_billing_info(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -1811,10 +1805,6 @@ def test_get_project_billing_info( assert response.billing_enabled is True -def test_get_project_billing_info_from_dict(): - test_get_project_billing_info(request_type=dict) - - def test_get_project_billing_info_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2005,9 +1995,10 @@ async def test_get_project_billing_info_flattened_error_async(): ) -def test_update_project_billing_info( - transport: str = "grpc", request_type=cloud_billing.UpdateProjectBillingInfoRequest -): +@pytest.mark.parametrize( + "request_type", [cloud_billing.UpdateProjectBillingInfoRequest, dict,] +) +def test_update_project_billing_info(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2042,10 +2033,6 @@ def test_update_project_billing_info( assert response.billing_enabled is True -def test_update_project_billing_info_from_dict(): - test_update_project_billing_info(request_type=dict) - - def test_update_project_billing_info_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2252,9 +2239,8 @@ async def test_update_project_billing_info_flattened_error_async(): ) -def test_get_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.GetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.GetIamPolicyRequest, dict,]) +def test_get_iam_policy(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2280,10 +2266,6 @@ def test_get_iam_policy( assert response.etag == b"etag_blob" -def test_get_iam_policy_from_dict(): - test_get_iam_policy(request_type=dict) - - def test_get_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2465,9 +2447,8 @@ async def test_get_iam_policy_flattened_error_async(): ) -def test_set_iam_policy( - transport: str = "grpc", request_type=iam_policy_pb2.SetIamPolicyRequest -): +@pytest.mark.parametrize("request_type", [iam_policy_pb2.SetIamPolicyRequest, dict,]) +def test_set_iam_policy(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2493,10 +2474,6 @@ def test_set_iam_policy( assert response.etag == b"etag_blob" -def test_set_iam_policy_from_dict(): - test_set_iam_policy(request_type=dict) - - def test_set_iam_policy_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -2678,9 +2655,10 @@ async def test_set_iam_policy_flattened_error_async(): ) -def test_test_iam_permissions( - transport: str = "grpc", request_type=iam_policy_pb2.TestIamPermissionsRequest -): +@pytest.mark.parametrize( + "request_type", [iam_policy_pb2.TestIamPermissionsRequest, dict,] +) +def test_test_iam_permissions(request_type, transport: str = "grpc"): client = CloudBillingClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -2709,10 +2687,6 @@ def test_test_iam_permissions( assert response.permissions == ["permissions_value"] -def test_test_iam_permissions_from_dict(): - test_test_iam_permissions(request_type=dict) - - def test_test_iam_permissions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -3416,7 +3390,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( diff --git a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py index bd21e65c317f..88429e613908 100644 --- a/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py +++ b/packages/google-cloud-billing/tests/unit/gapic/billing_v1/test_cloud_catalog.py @@ -238,20 +238,20 @@ def test_cloud_catalog_client_client_options( # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -308,7 +308,7 @@ def test_cloud_catalog_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -403,7 +403,7 @@ def test_cloud_catalog_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -434,7 +434,7 @@ def test_cloud_catalog_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(transport=transport_name, client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -465,9 +465,8 @@ def test_cloud_catalog_client_client_options_from_dict(): ) -def test_list_services( - transport: str = "grpc", request_type=cloud_catalog.ListServicesRequest -): +@pytest.mark.parametrize("request_type", [cloud_catalog.ListServicesRequest, dict,]) +def test_list_services(request_type, transport: str = "grpc"): client = CloudCatalogClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -494,10 +493,6 @@ def test_list_services( assert response.next_page_token == "next_page_token_value" -def test_list_services_from_dict(): - test_list_services(request_type=dict) - - def test_list_services_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -548,8 +543,10 @@ async def test_list_services_async_from_dict(): await test_list_services_async(request_type=dict) -def test_list_services_pager(): - client = CloudCatalogClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_services_pager(transport_name: str = "grpc"): + client = CloudCatalogClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: @@ -583,8 +580,10 @@ def test_list_services_pager(): assert all(isinstance(i, cloud_catalog.Service) for i in results) -def test_list_services_pages(): - client = CloudCatalogClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_services_pages(transport_name: str = "grpc"): + client = CloudCatalogClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_services), "__call__") as call: @@ -683,7 +682,8 @@ async def test_list_services_async_pages(): assert page_.raw_page.next_page_token == token -def test_list_skus(transport: str = "grpc", request_type=cloud_catalog.ListSkusRequest): +@pytest.mark.parametrize("request_type", [cloud_catalog.ListSkusRequest, dict,]) +def test_list_skus(request_type, transport: str = "grpc"): client = CloudCatalogClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) @@ -710,10 +710,6 @@ def test_list_skus(transport: str = "grpc", request_type=cloud_catalog.ListSkusR assert response.next_page_token == "next_page_token_value" -def test_list_skus_from_dict(): - test_list_skus(request_type=dict) - - def test_list_skus_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @@ -883,8 +879,10 @@ async def test_list_skus_flattened_error_async(): ) -def test_list_skus_pager(): - client = CloudCatalogClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_skus_pager(transport_name: str = "grpc"): + client = CloudCatalogClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_skus), "__call__") as call: @@ -917,8 +915,10 @@ def test_list_skus_pager(): assert all(isinstance(i, cloud_catalog.Sku) for i in results) -def test_list_skus_pages(): - client = CloudCatalogClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_skus_pages(transport_name: str = "grpc"): + client = CloudCatalogClient( + credentials=ga_credentials.AnonymousCredentials, transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_skus), "__call__") as call: @@ -1523,7 +1523,7 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object(