diff --git a/.coveragerc b/.coveragerc index d71dbe8..44d34f9 100644 --- a/.coveragerc +++ b/.coveragerc @@ -2,7 +2,6 @@ branch = True [report] -fail_under = 100 show_missing = True omit = google/cloud/channel/__init__.py diff --git a/google/cloud/channel/__init__.py b/google/cloud/channel/__init__.py index 8f842d7..fbdc106 100644 --- a/google/cloud/channel/__init__.py +++ b/google/cloud/channel/__init__.py @@ -99,6 +99,7 @@ from google.cloud.channel_v1.types.service import ListTransferableOffersResponse from google.cloud.channel_v1.types.service import ListTransferableSkusRequest from google.cloud.channel_v1.types.service import ListTransferableSkusResponse +from google.cloud.channel_v1.types.service import LookupOfferRequest from google.cloud.channel_v1.types.service import ProvisionCloudIdentityRequest from google.cloud.channel_v1.types.service import PurchasableOffer from google.cloud.channel_v1.types.service import PurchasableSku @@ -197,6 +198,7 @@ "ListTransferableOffersResponse", "ListTransferableSkusRequest", "ListTransferableSkusResponse", + "LookupOfferRequest", "ProvisionCloudIdentityRequest", "PurchasableOffer", "PurchasableSku", diff --git a/google/cloud/channel_v1/__init__.py b/google/cloud/channel_v1/__init__.py index 6d7d79c..73fb429 100644 --- a/google/cloud/channel_v1/__init__.py +++ b/google/cloud/channel_v1/__init__.py @@ -93,6 +93,7 @@ from .types.service import ListTransferableOffersResponse from .types.service import ListTransferableSkusRequest from .types.service import ListTransferableSkusResponse +from .types.service import LookupOfferRequest from .types.service import ProvisionCloudIdentityRequest from .types.service import PurchasableOffer from .types.service import PurchasableSku @@ -167,6 +168,7 @@ "ListTransferableOffersResponse", "ListTransferableSkusRequest", "ListTransferableSkusResponse", + "LookupOfferRequest", "MarketingInfo", "Media", "MediaType", diff --git a/google/cloud/channel_v1/gapic_metadata.json b/google/cloud/channel_v1/gapic_metadata.json index 0894836..e0d0f40 100644 --- a/google/cloud/channel_v1/gapic_metadata.json +++ b/google/cloud/channel_v1/gapic_metadata.json @@ -130,6 +130,11 @@ "list_transferable_skus" ] }, + "LookupOffer": { + "methods": [ + "lookup_offer" + ] + }, "ProvisionCloudIdentity": { "methods": [ "provision_cloud_identity" @@ -300,6 +305,11 @@ "list_transferable_skus" ] }, + "LookupOffer": { + "methods": [ + "lookup_offer" + ] + }, "ProvisionCloudIdentity": { "methods": [ "provision_cloud_identity" diff --git a/google/cloud/channel_v1/services/cloud_channel_service/async_client.py b/google/cloud/channel_v1/services/cloud_channel_service/async_client.py index db00925..8325e23 100644 --- a/google/cloud/channel_v1/services/cloud_channel_service/async_client.py +++ b/google/cloud/channel_v1/services/cloud_channel_service/async_client.py @@ -285,8 +285,8 @@ async def get_customer( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> customers.Customer: - r"""Returns a requested [Customer][google.cloud.channel.v1.Customer] - resource. + r"""Returns the requested + [Customer][google.cloud.channel.v1.Customer] resource. Possible error codes: @@ -565,7 +565,7 @@ async def delete_customer( metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes the given [Customer][google.cloud.channel.v1.Customer] - permanently and irreversibly. + permanently. Possible error codes: @@ -951,7 +951,7 @@ async def get_entitlement( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entitlements.Entitlement: - r"""Returns a requested + r"""Returns the requested [Entitlement][google.cloud.channel.v1.Entitlement] resource. Possible error codes: @@ -2000,7 +2000,7 @@ async def get_channel_partner_link( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> channel_partner_links.ChannelPartnerLink: - r"""Returns a requested + r"""Returns the requested [ChannelPartnerLink][google.cloud.channel.v1.ChannelPartnerLink] resource. You must be a distributor to call this method. @@ -2205,6 +2205,71 @@ async def update_channel_partner_link( # Done; return the response. return response + async def lookup_offer( + self, + request: service.LookupOfferRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> offers.Offer: + r"""Returns the requested [Offer][google.cloud.channel.v1.Offer] + resource. + + Possible error codes: + + - PERMISSION_DENIED: The entitlement doesn't belong to the + reseller. + - INVALID_ARGUMENT: Required request parameters are missing or + invalid. + - NOT_FOUND: Entitlement or offer was not found. + + Return value: The [Offer][google.cloud.channel.v1.Offer] + resource. + + Args: + request (:class:`google.cloud.channel_v1.types.LookupOfferRequest`): + The request object. Request message for LookupOffer. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.channel_v1.types.Offer: + Represents an offer made to resellers for purchase. + An offer is associated with a + [Sku][google.cloud.channel.v1.Sku], has a plan for + payment, a price, and defines the constraints for + buying. + + """ + # Create or coerce a protobuf request object. + request = service.LookupOfferRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.lookup_offer, + default_timeout=None, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entitlement", request.entitlement),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + async def list_products( self, request: service.ListProductsRequest = None, diff --git a/google/cloud/channel_v1/services/cloud_channel_service/client.py b/google/cloud/channel_v1/services/cloud_channel_service/client.py index 9d027a9..51f243b 100644 --- a/google/cloud/channel_v1/services/cloud_channel_service/client.py +++ b/google/cloud/channel_v1/services/cloud_channel_service/client.py @@ -508,8 +508,8 @@ def get_customer( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> customers.Customer: - r"""Returns a requested [Customer][google.cloud.channel.v1.Customer] - resource. + r"""Returns the requested + [Customer][google.cloud.channel.v1.Customer] resource. Possible error codes: @@ -793,7 +793,7 @@ def delete_customer( metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes the given [Customer][google.cloud.channel.v1.Customer] - permanently and irreversibly. + permanently. Possible error codes: @@ -1183,7 +1183,7 @@ def get_entitlement( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entitlements.Entitlement: - r"""Returns a requested + r"""Returns the requested [Entitlement][google.cloud.channel.v1.Entitlement] resource. Possible error codes: @@ -2248,7 +2248,7 @@ def get_channel_partner_link( timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> channel_partner_links.ChannelPartnerLink: - r"""Returns a requested + r"""Returns the requested [ChannelPartnerLink][google.cloud.channel.v1.ChannelPartnerLink] resource. You must be a distributor to call this method. @@ -2460,6 +2460,72 @@ def update_channel_partner_link( # Done; return the response. return response + def lookup_offer( + self, + request: service.LookupOfferRequest = None, + *, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> offers.Offer: + r"""Returns the requested [Offer][google.cloud.channel.v1.Offer] + resource. + + Possible error codes: + + - PERMISSION_DENIED: The entitlement doesn't belong to the + reseller. + - INVALID_ARGUMENT: Required request parameters are missing or + invalid. + - NOT_FOUND: Entitlement or offer was not found. + + Return value: The [Offer][google.cloud.channel.v1.Offer] + resource. + + Args: + request (google.cloud.channel_v1.types.LookupOfferRequest): + The request object. Request message for LookupOffer. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.channel_v1.types.Offer: + Represents an offer made to resellers for purchase. + An offer is associated with a + [Sku][google.cloud.channel.v1.Sku], has a plan for + payment, a price, and defines the constraints for + buying. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a service.LookupOfferRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, service.LookupOfferRequest): + request = service.LookupOfferRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.lookup_offer] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entitlement", request.entitlement),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + def list_products( self, request: service.ListProductsRequest = None, diff --git a/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py b/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py index f6be1ad..b5d7219 100644 --- a/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py +++ b/google/cloud/channel_v1/services/cloud_channel_service/transports/base.py @@ -29,6 +29,7 @@ from google.cloud.channel_v1.types import channel_partner_links from google.cloud.channel_v1.types import customers from google.cloud.channel_v1.types import entitlements +from google.cloud.channel_v1.types import offers from google.cloud.channel_v1.types import service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -269,6 +270,9 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.lookup_offer: gapic_v1.method.wrap_method( + self.lookup_offer, default_timeout=None, client_info=client_info, + ), self.list_products: gapic_v1.method.wrap_method( self.list_products, default_timeout=None, client_info=client_info, ), @@ -555,6 +559,14 @@ def update_channel_partner_link( ]: raise NotImplementedError() + @property + def lookup_offer( + self, + ) -> Callable[ + [service.LookupOfferRequest], Union[offers.Offer, Awaitable[offers.Offer]] + ]: + raise NotImplementedError() + @property def list_products( self, diff --git a/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py b/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py index 6086b58..b9e93e0 100644 --- a/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py +++ b/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc.py @@ -28,6 +28,7 @@ from google.cloud.channel_v1.types import channel_partner_links from google.cloud.channel_v1.types import customers from google.cloud.channel_v1.types import entitlements +from google.cloud.channel_v1.types import offers from google.cloud.channel_v1.types import service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -307,8 +308,8 @@ def get_customer( ) -> Callable[[service.GetCustomerRequest], customers.Customer]: r"""Return a callable for the get customer method over gRPC. - Returns a requested [Customer][google.cloud.channel.v1.Customer] - resource. + Returns the requested + [Customer][google.cloud.channel.v1.Customer] resource. Possible error codes: @@ -476,7 +477,7 @@ def delete_customer( r"""Return a callable for the delete customer method over gRPC. Deletes the given [Customer][google.cloud.channel.v1.Customer] - permanently and irreversibly. + permanently. Possible error codes: @@ -699,7 +700,7 @@ def get_entitlement( ) -> Callable[[service.GetEntitlementRequest], entitlements.Entitlement]: r"""Return a callable for the get entitlement method over gRPC. - Returns a requested + Returns the requested [Entitlement][google.cloud.channel.v1.Entitlement] resource. Possible error codes: @@ -1336,7 +1337,7 @@ def get_channel_partner_link( ]: r"""Return a callable for the get channel partner link method over gRPC. - Returns a requested + Returns the requested [ChannelPartnerLink][google.cloud.channel.v1.ChannelPartnerLink] resource. You must be a distributor to call this method. @@ -1477,6 +1478,42 @@ def update_channel_partner_link( ) return self._stubs["update_channel_partner_link"] + @property + def lookup_offer(self) -> Callable[[service.LookupOfferRequest], offers.Offer]: + r"""Return a callable for the lookup offer method over gRPC. + + Returns the requested [Offer][google.cloud.channel.v1.Offer] + resource. + + Possible error codes: + + - PERMISSION_DENIED: The entitlement doesn't belong to the + reseller. + - INVALID_ARGUMENT: Required request parameters are missing or + invalid. + - NOT_FOUND: Entitlement or offer was not found. + + Return value: The [Offer][google.cloud.channel.v1.Offer] + resource. + + Returns: + Callable[[~.LookupOfferRequest], + ~.Offer]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "lookup_offer" not in self._stubs: + self._stubs["lookup_offer"] = self.grpc_channel.unary_unary( + "/google.cloud.channel.v1.CloudChannelService/LookupOffer", + request_serializer=service.LookupOfferRequest.serialize, + response_deserializer=offers.Offer.deserialize, + ) + return self._stubs["lookup_offer"] + @property def list_products( self, diff --git a/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py b/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py index 0e6c514..a0e2da5 100644 --- a/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py +++ b/google/cloud/channel_v1/services/cloud_channel_service/transports/grpc_asyncio.py @@ -29,6 +29,7 @@ from google.cloud.channel_v1.types import channel_partner_links from google.cloud.channel_v1.types import customers from google.cloud.channel_v1.types import entitlements +from google.cloud.channel_v1.types import offers from google.cloud.channel_v1.types import service from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -314,8 +315,8 @@ def get_customer( ) -> Callable[[service.GetCustomerRequest], Awaitable[customers.Customer]]: r"""Return a callable for the get customer method over gRPC. - Returns a requested [Customer][google.cloud.channel.v1.Customer] - resource. + Returns the requested + [Customer][google.cloud.channel.v1.Customer] resource. Possible error codes: @@ -483,7 +484,7 @@ def delete_customer( r"""Return a callable for the delete customer method over gRPC. Deletes the given [Customer][google.cloud.channel.v1.Customer] - permanently and irreversibly. + permanently. Possible error codes: @@ -712,7 +713,7 @@ def get_entitlement( ) -> Callable[[service.GetEntitlementRequest], Awaitable[entitlements.Entitlement]]: r"""Return a callable for the get entitlement method over gRPC. - Returns a requested + Returns the requested [Entitlement][google.cloud.channel.v1.Entitlement] resource. Possible error codes: @@ -1367,7 +1368,7 @@ def get_channel_partner_link( ]: r"""Return a callable for the get channel partner link method over gRPC. - Returns a requested + Returns the requested [ChannelPartnerLink][google.cloud.channel.v1.ChannelPartnerLink] resource. You must be a distributor to call this method. @@ -1508,6 +1509,44 @@ def update_channel_partner_link( ) return self._stubs["update_channel_partner_link"] + @property + def lookup_offer( + self, + ) -> Callable[[service.LookupOfferRequest], Awaitable[offers.Offer]]: + r"""Return a callable for the lookup offer method over gRPC. + + Returns the requested [Offer][google.cloud.channel.v1.Offer] + resource. + + Possible error codes: + + - PERMISSION_DENIED: The entitlement doesn't belong to the + reseller. + - INVALID_ARGUMENT: Required request parameters are missing or + invalid. + - NOT_FOUND: Entitlement or offer was not found. + + Return value: The [Offer][google.cloud.channel.v1.Offer] + resource. + + Returns: + Callable[[~.LookupOfferRequest], + Awaitable[~.Offer]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "lookup_offer" not in self._stubs: + self._stubs["lookup_offer"] = self.grpc_channel.unary_unary( + "/google.cloud.channel.v1.CloudChannelService/LookupOffer", + request_serializer=service.LookupOfferRequest.serialize, + response_deserializer=offers.Offer.deserialize, + ) + return self._stubs["lookup_offer"] + @property def list_products( self, diff --git a/google/cloud/channel_v1/types/__init__.py b/google/cloud/channel_v1/types/__init__.py index ff2b776..27aadd3 100644 --- a/google/cloud/channel_v1/types/__init__.py +++ b/google/cloud/channel_v1/types/__init__.py @@ -102,6 +102,7 @@ ListTransferableOffersResponse, ListTransferableSkusRequest, ListTransferableSkusResponse, + LookupOfferRequest, ProvisionCloudIdentityRequest, PurchasableOffer, PurchasableSku, @@ -201,6 +202,7 @@ "ListTransferableOffersResponse", "ListTransferableSkusRequest", "ListTransferableSkusResponse", + "LookupOfferRequest", "ProvisionCloudIdentityRequest", "PurchasableOffer", "PurchasableSku", diff --git a/google/cloud/channel_v1/types/customers.py b/google/cloud/channel_v1/types/customers.py index ae2d89d..49df85e 100644 --- a/google/cloud/channel_v1/types/customers.py +++ b/google/cloud/channel_v1/types/customers.py @@ -35,36 +35,34 @@ class Customer(proto.Message): Required. Name of the organization that the customer entity represents. org_postal_address (google.type.postal_address_pb2.PostalAddress): - Required. Address of the organization of the - customer entity. Region and zip codes are - required to enforce US laws and embargoes. Valid - address lines are required for all customers. - Language code is discarded. Use the Customer- - level language code to set the customer's - language. + Required. The organization address for the + customer. To enforce US laws and embargoes, we + require a region and zip code. You must provide + valid addresses for every customer. To set the + customer's language, use the Customer-level + language code. primary_contact_info (google.cloud.channel_v1.types.ContactInfo): Primary contact info. alternate_email (str): - Secondary contact email. - Alternate email and primary contact email are - required to have different domains if primary - contact email is present. - When creating admin.google.com accounts, users - get notified credentials at this email. This - email address is also used as a recovery email. + Secondary contact email. You need to provide + an alternate email to create different domains + if a primary contact email already exists. Users + will receive a notification with credentials + when you create an admin.google.com account. + Secondary emails are also recovery email + addresses. domain (str): - Required. Primary domain used by the - customer. Domain of primary contact email is - required to be same as the provided domain. + Required. The customer's primary domain. Must + match the primary contact email's domain. create_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which the customer - is created. + Output only. Time when the customer was + created. update_time (google.protobuf.timestamp_pb2.Timestamp): - Output only. The time at which the customer - is updated. + Output only. Time when the customer was + updated. cloud_identity_id (str): - Output only. Customer's cloud_identity_id. Populated only if - a Cloud Identity resource exists for this customer. + Output only. The customer's Cloud Identity ID + if the customer has a Cloud Identity resource. language_code (str): Optional. The BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see @@ -101,27 +99,23 @@ class ContactInfo(proto.Message): r"""Contact information for a customer account. Attributes: first_name (str): - First name of the contact in the customer - account. + The customer account contact's first name. last_name (str): - Last name of the contact in the customer - account. + The customer account contact's last name. display_name (str): - Output only. Display name of the contact in - the customer account. Populated by combining - customer first name and last name. + Output only. The customer account contact's + display name, formatted as a combination of the + customer's first and last name. email (str): - Email of the contact in the customer account. - Email is required for entitlements that need - creation of admin.google.com accounts. The email - will be the username used in credentials to - access the admin.google.com account. + The customer account's contact email. + Required for entitlements that create + admin.google.com accounts, and serves as the + customer's username for those accounts. title (str): - Optional. Job title of the contact in the - customer account. + Optional. The customer account contact's job + title. phone (str): - Phone number of the contact in the customer - account. + The customer account's contact phone number. """ first_name = proto.Field(proto.STRING, number=1,) diff --git a/google/cloud/channel_v1/types/service.py b/google/cloud/channel_v1/types/service.py index fe71563..8e642ab 100644 --- a/google/cloud/channel_v1/types/service.py +++ b/google/cloud/channel_v1/types/service.py @@ -63,6 +63,7 @@ "CancelEntitlementRequest", "SuspendEntitlementRequest", "ActivateEntitlementRequest", + "LookupOfferRequest", "ListProductsRequest", "ListProductsResponse", "ListSkusRequest", @@ -1011,6 +1012,18 @@ class ActivateEntitlementRequest(proto.Message): request_id = proto.Field(proto.STRING, number=3,) +class LookupOfferRequest(proto.Message): + r"""Request message for LookupOffer. + Attributes: + entitlement (str): + Required. The resource name of the entitlement to retrieve + the Offer. Entitlement uses the format: + accounts/{account_id}/customers/{customer_id}/entitlements/{entitlement_id} + """ + + entitlement = proto.Field(proto.STRING, number=1,) + + class ListProductsRequest(proto.Message): r"""Request message for ListProducts. Attributes: diff --git a/google/cloud/channel_v1/types/subscriber_event.py b/google/cloud/channel_v1/types/subscriber_event.py index 5e95493..7f58760 100644 --- a/google/cloud/channel_v1/types/subscriber_event.py +++ b/google/cloud/channel_v1/types/subscriber_event.py @@ -71,6 +71,7 @@ class Type(proto.Enum): RENEWAL_SETTING_CHANGED = 10 PAID_SERVICE_STARTED = 11 LICENSE_ASSIGNMENT_CHANGED = 12 + LICENSE_CAP_CHANGED = 13 entitlement = proto.Field(proto.STRING, number=1,) event_type = proto.Field(proto.ENUM, number=2, enum=Type,) diff --git a/scripts/fixup_channel_v1_keywords.py b/scripts/fixup_channel_v1_keywords.py index bb71227..2d4cfca 100644 --- a/scripts/fixup_channel_v1_keywords.py +++ b/scripts/fixup_channel_v1_keywords.py @@ -63,6 +63,7 @@ class channelCallTransformer(cst.CSTTransformer): 'list_subscribers': ('account', 'page_size', 'page_token', ), 'list_transferable_offers': ('parent', 'sku', 'cloud_identity_id', 'customer_name', 'page_size', 'page_token', 'language_code', ), 'list_transferable_skus': ('parent', 'cloud_identity_id', 'customer_name', 'page_size', 'page_token', 'auth_token', 'language_code', ), + 'lookup_offer': ('entitlement', ), 'provision_cloud_identity': ('customer', 'cloud_identity_info', 'user', 'validate_only', ), 'register_subscriber': ('account', 'service_account', ), 'start_paid_service': ('name', 'request_id', ), diff --git a/tests/unit/gapic/channel_v1/test_cloud_channel_service.py b/tests/unit/gapic/channel_v1/test_cloud_channel_service.py index e14cca5..b50c529 100644 --- a/tests/unit/gapic/channel_v1/test_cloud_channel_service.py +++ b/tests/unit/gapic/channel_v1/test_cloud_channel_service.py @@ -5211,6 +5211,138 @@ async def test_update_channel_partner_link_field_headers_async(): assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] +def test_lookup_offer(transport: str = "grpc", request_type=service.LookupOfferRequest): + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_offer), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = offers.Offer(name="name_value",) + response = client.lookup_offer(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == service.LookupOfferRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, offers.Offer) + assert response.name == "name_value" + + +def test_lookup_offer_from_dict(): + test_lookup_offer(request_type=dict) + + +def test_lookup_offer_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. + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_offer), "__call__") as call: + client.lookup_offer() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == service.LookupOfferRequest() + + +@pytest.mark.asyncio +async def test_lookup_offer_async( + transport: str = "grpc_asyncio", request_type=service.LookupOfferRequest +): + client = CloudChannelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_offer), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + offers.Offer(name="name_value",) + ) + response = await client.lookup_offer(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == service.LookupOfferRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, offers.Offer) + assert response.name == "name_value" + + +@pytest.mark.asyncio +async def test_lookup_offer_async_from_dict(): + await test_lookup_offer_async(request_type=dict) + + +def test_lookup_offer_field_headers(): + client = CloudChannelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = service.LookupOfferRequest() + + request.entitlement = "entitlement/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_offer), "__call__") as call: + call.return_value = offers.Offer() + client.lookup_offer(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "entitlement=entitlement/value",) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_lookup_offer_field_headers_async(): + client = CloudChannelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = service.LookupOfferRequest() + + request.entitlement = "entitlement/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_offer), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(offers.Offer()) + await client.lookup_offer(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ("x-goog-request-params", "entitlement=entitlement/value",) in kw["metadata"] + + def test_list_products( transport: str = "grpc", request_type=service.ListProductsRequest ): @@ -7231,6 +7363,7 @@ def test_cloud_channel_service_base_transport(): "get_channel_partner_link", "create_channel_partner_link", "update_channel_partner_link", + "lookup_offer", "list_products", "list_skus", "list_offers",