Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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
Expand Down
71 changes: 25 additions & 46 deletions tests/unit/gapic/budgets_v1/test_budget_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,20 @@ def test_budget_service_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,
Expand Down Expand Up @@ -325,7 +325,7 @@ def test_budget_service_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
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_budget_service_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,
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_budget_service_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",
Expand Down Expand Up @@ -484,9 +484,8 @@ def test_budget_service_client_client_options_from_dict():
)


def test_create_budget(
transport: str = "grpc", request_type=budget_service.CreateBudgetRequest
):
@pytest.mark.parametrize("request_type", [budget_service.CreateBudgetRequest, dict,])
def test_create_budget(request_type, transport: str = "grpc"):
client = BudgetServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -515,10 +514,6 @@ def test_create_budget(
assert response.etag == "etag_value"


def test_create_budget_from_dict():
test_create_budget(request_type=dict)


def test_create_budget_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.
Expand Down Expand Up @@ -708,9 +703,8 @@ async def test_create_budget_flattened_error_async():
)


def test_update_budget(
transport: str = "grpc", request_type=budget_service.UpdateBudgetRequest
):
@pytest.mark.parametrize("request_type", [budget_service.UpdateBudgetRequest, dict,])
def test_update_budget(request_type, transport: str = "grpc"):
client = BudgetServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -739,10 +733,6 @@ def test_update_budget(
assert response.etag == "etag_value"


def test_update_budget_from_dict():
test_update_budget(request_type=dict)


def test_update_budget_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.
Expand Down Expand Up @@ -934,9 +924,8 @@ async def test_update_budget_flattened_error_async():
)


def test_get_budget(
transport: str = "grpc", request_type=budget_service.GetBudgetRequest
):
@pytest.mark.parametrize("request_type", [budget_service.GetBudgetRequest, dict,])
def test_get_budget(request_type, transport: str = "grpc"):
client = BudgetServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -965,10 +954,6 @@ def test_get_budget(
assert response.etag == "etag_value"


def test_get_budget_from_dict():
test_get_budget(request_type=dict)


def test_get_budget_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.
Expand Down Expand Up @@ -1144,9 +1129,8 @@ async def test_get_budget_flattened_error_async():
)


def test_list_budgets(
transport: str = "grpc", request_type=budget_service.ListBudgetsRequest
):
@pytest.mark.parametrize("request_type", [budget_service.ListBudgetsRequest, dict,])
def test_list_budgets(request_type, transport: str = "grpc"):
client = BudgetServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand All @@ -1173,10 +1157,6 @@ def test_list_budgets(
assert response.next_page_token == "next_page_token_value"


def test_list_budgets_from_dict():
test_list_budgets(request_type=dict)


def test_list_budgets_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.
Expand Down Expand Up @@ -1352,8 +1332,10 @@ async def test_list_budgets_flattened_error_async():
)


def test_list_budgets_pager():
client = BudgetServiceClient(credentials=ga_credentials.AnonymousCredentials,)
def test_list_budgets_pager(transport_name: str = "grpc"):
client = BudgetServiceClient(
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_budgets), "__call__") as call:
Expand Down Expand Up @@ -1390,8 +1372,10 @@ def test_list_budgets_pager():
assert all(isinstance(i, budget_model.Budget) for i in results)


def test_list_budgets_pages():
client = BudgetServiceClient(credentials=ga_credentials.AnonymousCredentials,)
def test_list_budgets_pages(transport_name: str = "grpc"):
client = BudgetServiceClient(
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_budgets), "__call__") as call:
Expand Down Expand Up @@ -1490,9 +1474,8 @@ async def test_list_budgets_async_pages():
assert page_.raw_page.next_page_token == token


def test_delete_budget(
transport: str = "grpc", request_type=budget_service.DeleteBudgetRequest
):
@pytest.mark.parametrize("request_type", [budget_service.DeleteBudgetRequest, dict,])
def test_delete_budget(request_type, transport: str = "grpc"):
client = BudgetServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand All @@ -1516,10 +1499,6 @@ def test_delete_budget(
assert response is None


def test_delete_budget_from_dict():
test_delete_budget(request_type=dict)


def test_delete_budget_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.
Expand Down Expand Up @@ -2214,7 +2193,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(
Expand Down
Loading