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

fix(v2alpha): fix the HTTP format for merchant center link service #408

Merged
merged 2 commits into from
Apr 17, 2023
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 @@ -380,11 +380,8 @@ async def create_merchant_center_account_link(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation_async.AsyncOperation:
r"""Creates a MerchantCenterAccountLink.

[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
cannot be set to a different oneof field, if so an
INVALID_ARGUMENT is returned.
r"""Creates a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].

.. code-block:: python

Expand Down Expand Up @@ -497,14 +494,7 @@ async def sample_create_merchant_center_account_link():
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(
(
(
"merchant_center_account_link.name",
request.merchant_center_account_link.name,
),
)
),
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
Expand Down Expand Up @@ -540,7 +530,9 @@ async def delete_merchant_center_account_link(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
r"""Deletes a MerchantCenterAccountLink. If the
r"""Deletes a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].
If the
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
to delete does not exist, a NOT_FOUND error is returned.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,8 @@ def create_merchant_center_account_link(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation.Operation:
r"""Creates a MerchantCenterAccountLink.

[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
cannot be set to a different oneof field, if so an
INVALID_ARGUMENT is returned.
r"""Creates a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].

.. code-block:: python

Expand Down Expand Up @@ -745,14 +742,7 @@ def sample_create_merchant_center_account_link():
# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(
(
(
"merchant_center_account_link.name",
request.merchant_center_account_link.name,
),
)
),
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
Expand Down Expand Up @@ -788,7 +778,9 @@ def delete_merchant_center_account_link(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
r"""Deletes a MerchantCenterAccountLink. If the
r"""Deletes a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].
If the
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
to delete does not exist, a NOT_FOUND error is returned.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,8 @@ def create_merchant_center_account_link(
r"""Return a callable for the create merchant center account
link method over gRPC.

Creates a MerchantCenterAccountLink.

[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
cannot be set to a different oneof field, if so an
INVALID_ARGUMENT is returned.
Creates a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].

Returns:
Callable[[~.CreateMerchantCenterAccountLinkRequest],
Expand Down Expand Up @@ -330,7 +327,9 @@ def delete_merchant_center_account_link(
r"""Return a callable for the delete merchant center account
link method over gRPC.

Deletes a MerchantCenterAccountLink. If the
Deletes a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].
If the
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
to delete does not exist, a NOT_FOUND error is returned.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,8 @@ def create_merchant_center_account_link(
r"""Return a callable for the create merchant center account
link method over gRPC.

Creates a MerchantCenterAccountLink.

[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
cannot be set to a different oneof field, if so an
INVALID_ARGUMENT is returned.
Creates a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].

Returns:
Callable[[~.CreateMerchantCenterAccountLinkRequest],
Expand Down Expand Up @@ -337,7 +334,9 @@ def delete_merchant_center_account_link(
r"""Return a callable for the delete merchant center account
link method over gRPC.

Deletes a MerchantCenterAccountLink. If the
Deletes a
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink].
If the
[MerchantCenterAccountLink][google.cloud.retail.v2alpha.MerchantCenterAccountLink]
to delete does not exist, a NOT_FOUND error is returned.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,7 @@ class _CreateMerchantCenterAccountLink(MerchantCenterAccountLinkServiceRestStub)
def __hash__(self):
return hash("CreateMerchantCenterAccountLink")

__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {
"parent": "",
}
__REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {}

@classmethod
def _get_unset_required_fields(cls, message_dict):
Expand Down Expand Up @@ -430,7 +428,7 @@ def __call__(
http_options: List[Dict[str, str]] = [
{
"method": "post",
"uri": "/v2alpha/{merchant_center_account_link.name=projects/*/locations/*/catalogs/*/merchantCenterAccountLinks/*}",
"uri": "/v2alpha/{parent=projects/*/locations/*/catalogs/*}/merchantCenterAccountLinks",
"body": "merchant_center_account_link",
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-retail",
"version": "1.16.0"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-retail",
"version": "1.16.0"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-retail",
"version": "1.16.0"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ def test_create_merchant_center_account_link_field_headers():
merchant_center_account_link_service.CreateMerchantCenterAccountLinkRequest()
)

request.merchant_center_account_link.name = "name_value"
request.parent = "parent_value"

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
Expand All @@ -1179,7 +1179,7 @@ def test_create_merchant_center_account_link_field_headers():
_, _, kw = call.mock_calls[0]
assert (
"x-goog-request-params",
"merchant_center_account_link.name=name_value",
"parent=parent_value",
) in kw["metadata"]


Expand All @@ -1195,7 +1195,7 @@ async def test_create_merchant_center_account_link_field_headers_async():
merchant_center_account_link_service.CreateMerchantCenterAccountLinkRequest()
)

request.merchant_center_account_link.name = "name_value"
request.parent = "parent_value"

# Mock the actual call within the gRPC stub, and fake the request.
with mock.patch.object(
Expand All @@ -1215,7 +1215,7 @@ async def test_create_merchant_center_account_link_field_headers_async():
_, _, kw = call.mock_calls[0]
assert (
"x-goog-request-params",
"merchant_center_account_link.name=name_value",
"parent=parent_value",
) in kw["metadata"]


Expand Down Expand Up @@ -1882,13 +1882,9 @@ def test_create_merchant_center_account_link_rest(request_type):
)

# send a request that will satisfy transcoding
request_init = {
"merchant_center_account_link": {
"name": "projects/sample1/locations/sample2/catalogs/sample3/merchantCenterAccountLinks/sample4"
}
}
request_init = {"parent": "projects/sample1/locations/sample2/catalogs/sample3"}
request_init["merchant_center_account_link"] = {
"name": "projects/sample1/locations/sample2/catalogs/sample3/merchantCenterAccountLinks/sample4",
"name": "name_value",
"id": "id_value",
"merchant_center_account_id": 2730,
"branch_id": "branch_id_value",
Expand Down Expand Up @@ -1938,24 +1934,19 @@ def test_create_merchant_center_account_link_rest_required_fields(
)

# verify fields with default values are dropped
assert "parent" not in jsonified_request

unset_fields = transport_class(
credentials=ga_credentials.AnonymousCredentials()
).create_merchant_center_account_link._get_unset_required_fields(jsonified_request)
jsonified_request.update(unset_fields)

# verify required fields with default values are now present
assert "parent" in jsonified_request
assert jsonified_request["parent"] == request_init["parent"]

jsonified_request["parent"] = "parent_value"

unset_fields = transport_class(
credentials=ga_credentials.AnonymousCredentials()
).create_merchant_center_account_link._get_unset_required_fields(jsonified_request)
# Check that path parameters and body parameters are not mixing in.
assert not set(unset_fields) - set(("parent",))
jsonified_request.update(unset_fields)

# verify required fields with non-default values are left alone
Expand Down Expand Up @@ -1996,13 +1987,7 @@ def test_create_merchant_center_account_link_rest_required_fields(

response = client.create_merchant_center_account_link(request)

expected_params = [
(
"parent",
"",
),
("$alt", "json;enum-encoding=int"),
]
expected_params = [("$alt", "json;enum-encoding=int")]
actual_params = req.call_args.kwargs["params"]
assert expected_params == actual_params

Expand All @@ -2016,7 +2001,7 @@ def test_create_merchant_center_account_link_rest_unset_required_fields():
transport.create_merchant_center_account_link._get_unset_required_fields({})
)
assert set(unset_fields) == (
set(("parent",))
set(())
& set(
(
"parent",
Expand Down Expand Up @@ -2099,13 +2084,9 @@ def test_create_merchant_center_account_link_rest_bad_request(
)

# send a request that will satisfy transcoding
request_init = {
"merchant_center_account_link": {
"name": "projects/sample1/locations/sample2/catalogs/sample3/merchantCenterAccountLinks/sample4"
}
}
request_init = {"parent": "projects/sample1/locations/sample2/catalogs/sample3"}
request_init["merchant_center_account_link"] = {
"name": "projects/sample1/locations/sample2/catalogs/sample3/merchantCenterAccountLinks/sample4",
"name": "name_value",
"id": "id_value",
"merchant_center_account_id": 2730,
"branch_id": "branch_id_value",
Expand Down Expand Up @@ -2144,9 +2125,7 @@ def test_create_merchant_center_account_link_rest_flattened():

# get arguments that satisfy an http rule for this method
sample_request = {
"merchant_center_account_link": {
"name": "projects/sample1/locations/sample2/catalogs/sample3/merchantCenterAccountLinks/sample4"
}
"parent": "projects/sample1/locations/sample2/catalogs/sample3"
}

# get truthy value for each flattened field
Expand All @@ -2172,7 +2151,7 @@ def test_create_merchant_center_account_link_rest_flattened():
assert len(req.mock_calls) == 1
_, args, _ = req.mock_calls[0]
assert path_template.validate(
"%s/v2alpha/{merchant_center_account_link.name=projects/*/locations/*/catalogs/*/merchantCenterAccountLinks/*}"
"%s/v2alpha/{parent=projects/*/locations/*/catalogs/*}/merchantCenterAccountLinks"
% client.transport._host,
args[1],
)
Expand Down