Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

chore: use gapic-generator-python 0.58.4 #260

Merged
merged 4 commits into from
Jan 15, 2022
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 @@ -107,7 +107,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 @@ -108,7 +108,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
6 changes: 3 additions & 3 deletions google/cloud/monitoring_v3/services/metric_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ def transport(self) -> MetricServiceTransport:
return self._transport

'''@staticmethod
def metric_descriptor_path(project: str,) -> str:
def metric_descriptor_path(project: str,metric_descriptor: str,) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is commented out so it shouldn't be considered a breaking change.

"""Returns a fully-qualified metric_descriptor string."""
return "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(project=project, )
return "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(project=project, metric_descriptor=metric_descriptor, )
Copy link
Contributor

@parthea parthea Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried uncommenting the code but the unit tests fail as {metric_descriptor=**} is unsupported according to googleapis/gapic-generator-python#701

_________________________________________________________________________________ test_metric_descriptor_path _________________________________________________________________________________

    def test_metric_descriptor_path():
        project = "squid"
        metric_descriptor = "clam"
>       expected = "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(
            project=project, metric_descriptor=metric_descriptor,
        )
E       KeyError: 'metric_descriptor=**'

tests/unit/gapic/monitoring_v3/test_metric_service.py:3533: KeyError
______________________________________________________________________________ test_parse_metric_descriptor_path ______________________________________________________________________________

    def test_parse_metric_descriptor_path():
        expected = {
            "project": "whelk",
            "metric_descriptor": "octopus",
        }
>       path = MetricServiceClient.metric_descriptor_path(**expected)

tests/unit/gapic/monitoring_v3/test_metric_service.py:3545: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

project = 'whelk', metric_descriptor = 'octopus'

    @staticmethod
    def metric_descriptor_path(project: str, metric_descriptor: str,) -> str:
        """Returns a fully-qualified metric_descriptor string."""
>       return "projects/{project}/metricDescriptors/{metric_descriptor=**}".format(
            project=project, metric_descriptor=metric_descriptor,
        )
E       KeyError: 'metric_descriptor=**'

google/cloud/monitoring_v3/services/metric_service/client.py:171: KeyError
==============================================================================


@staticmethod
def parse_metric_descriptor_path(path: str) -> Dict[str,str]:
"""Parses a metric_descriptor path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)/metricDescriptors/{metric_descriptor=**}$", path)
m = re.match(r"^projects/(?P<project>.+?)/metricDescriptors/(?P<metric_descriptor>.+?)$", path)
return m.groupdict() if m else {}'''

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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 @@ -107,7 +107,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 @@ -105,7 +105,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 @@ -108,7 +108,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 @@ -107,7 +107,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
79 changes: 33 additions & 46 deletions tests/unit/gapic/monitoring_v3/test_alert_policy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,20 @@ def test_alert_policy_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 @@ -342,7 +342,7 @@ def test_alert_policy_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 @@ -437,7 +437,7 @@ def test_alert_policy_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 @@ -468,7 +468,7 @@ def test_alert_policy_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 @@ -501,9 +501,10 @@ def test_alert_policy_service_client_client_options_from_dict():
)


def test_list_alert_policies(
transport: str = "grpc", request_type=alert_service.ListAlertPoliciesRequest
):
@pytest.mark.parametrize(
"request_type", [alert_service.ListAlertPoliciesRequest, dict,]
)
def test_list_alert_policies(request_type, transport: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -533,10 +534,6 @@ def test_list_alert_policies(
assert response.total_size == 1086


def test_list_alert_policies_from_dict():
test_list_alert_policies(request_type=dict)


def test_list_alert_policies_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 @@ -733,8 +730,10 @@ async def test_list_alert_policies_flattened_error_async():
)


def test_list_alert_policies_pager():
client = AlertPolicyServiceClient(credentials=ga_credentials.AnonymousCredentials,)
def test_list_alert_policies_pager(transport_name: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials, transport=transport_name,
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
Expand Down Expand Up @@ -775,8 +774,10 @@ def test_list_alert_policies_pager():
assert all(isinstance(i, alert.AlertPolicy) for i in results)


def test_list_alert_policies_pages():
client = AlertPolicyServiceClient(credentials=ga_credentials.AnonymousCredentials,)
def test_list_alert_policies_pages(transport_name: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials, transport=transport_name,
)

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
Expand Down Expand Up @@ -891,9 +892,8 @@ async def test_list_alert_policies_async_pages():
assert page_.raw_page.next_page_token == token


def test_get_alert_policy(
transport: str = "grpc", request_type=alert_service.GetAlertPolicyRequest
):
@pytest.mark.parametrize("request_type", [alert_service.GetAlertPolicyRequest, dict,])
def test_get_alert_policy(request_type, transport: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -926,10 +926,6 @@ def test_get_alert_policy(
assert response.notification_channels == ["notification_channels_value"]


def test_get_alert_policy_from_dict():
test_get_alert_policy(request_type=dict)


def test_get_alert_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.
Expand Down Expand Up @@ -1115,9 +1111,10 @@ async def test_get_alert_policy_flattened_error_async():
)


def test_create_alert_policy(
transport: str = "grpc", request_type=alert_service.CreateAlertPolicyRequest
):
@pytest.mark.parametrize(
"request_type", [alert_service.CreateAlertPolicyRequest, dict,]
)
def test_create_alert_policy(request_type, transport: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -1152,10 +1149,6 @@ def test_create_alert_policy(
assert response.notification_channels == ["notification_channels_value"]


def test_create_alert_policy_from_dict():
test_create_alert_policy(request_type=dict)


def test_create_alert_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.
Expand Down Expand Up @@ -1367,9 +1360,10 @@ async def test_create_alert_policy_flattened_error_async():
)


def test_delete_alert_policy(
transport: str = "grpc", request_type=alert_service.DeleteAlertPolicyRequest
):
@pytest.mark.parametrize(
"request_type", [alert_service.DeleteAlertPolicyRequest, dict,]
)
def test_delete_alert_policy(request_type, transport: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand All @@ -1395,10 +1389,6 @@ def test_delete_alert_policy(
assert response is None


def test_delete_alert_policy_from_dict():
test_delete_alert_policy(request_type=dict)


def test_delete_alert_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.
Expand Down Expand Up @@ -1585,9 +1575,10 @@ async def test_delete_alert_policy_flattened_error_async():
)


def test_update_alert_policy(
transport: str = "grpc", request_type=alert_service.UpdateAlertPolicyRequest
):
@pytest.mark.parametrize(
"request_type", [alert_service.UpdateAlertPolicyRequest, dict,]
)
def test_update_alert_policy(request_type, transport: str = "grpc"):
client = AlertPolicyServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport,
)
Expand Down Expand Up @@ -1622,10 +1613,6 @@ def test_update_alert_policy(
assert response.notification_channels == ["notification_channels_value"]


def test_update_alert_policy_from_dict():
test_update_alert_policy(request_type=dict)


def test_update_alert_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.
Expand Down Expand Up @@ -2407,7 +2394,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