diff --git a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/gapic_metadata.json b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/gapic_metadata.json index 51d9ffec66d1..92a8e4a173a8 100644 --- a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/gapic_metadata.json +++ b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/gapic_metadata.json @@ -316,6 +316,161 @@ ] } } + }, + "rest": { + "libraryClient": "VideoStitcherServiceClient", + "rpcs": { + "CreateCdnKey": { + "methods": [ + "create_cdn_key" + ] + }, + "CreateLiveConfig": { + "methods": [ + "create_live_config" + ] + }, + "CreateLiveSession": { + "methods": [ + "create_live_session" + ] + }, + "CreateSlate": { + "methods": [ + "create_slate" + ] + }, + "CreateVodConfig": { + "methods": [ + "create_vod_config" + ] + }, + "CreateVodSession": { + "methods": [ + "create_vod_session" + ] + }, + "DeleteCdnKey": { + "methods": [ + "delete_cdn_key" + ] + }, + "DeleteLiveConfig": { + "methods": [ + "delete_live_config" + ] + }, + "DeleteSlate": { + "methods": [ + "delete_slate" + ] + }, + "DeleteVodConfig": { + "methods": [ + "delete_vod_config" + ] + }, + "GetCdnKey": { + "methods": [ + "get_cdn_key" + ] + }, + "GetLiveAdTagDetail": { + "methods": [ + "get_live_ad_tag_detail" + ] + }, + "GetLiveConfig": { + "methods": [ + "get_live_config" + ] + }, + "GetLiveSession": { + "methods": [ + "get_live_session" + ] + }, + "GetSlate": { + "methods": [ + "get_slate" + ] + }, + "GetVodAdTagDetail": { + "methods": [ + "get_vod_ad_tag_detail" + ] + }, + "GetVodConfig": { + "methods": [ + "get_vod_config" + ] + }, + "GetVodSession": { + "methods": [ + "get_vod_session" + ] + }, + "GetVodStitchDetail": { + "methods": [ + "get_vod_stitch_detail" + ] + }, + "ListCdnKeys": { + "methods": [ + "list_cdn_keys" + ] + }, + "ListLiveAdTagDetails": { + "methods": [ + "list_live_ad_tag_details" + ] + }, + "ListLiveConfigs": { + "methods": [ + "list_live_configs" + ] + }, + "ListSlates": { + "methods": [ + "list_slates" + ] + }, + "ListVodAdTagDetails": { + "methods": [ + "list_vod_ad_tag_details" + ] + }, + "ListVodConfigs": { + "methods": [ + "list_vod_configs" + ] + }, + "ListVodStitchDetails": { + "methods": [ + "list_vod_stitch_details" + ] + }, + "UpdateCdnKey": { + "methods": [ + "update_cdn_key" + ] + }, + "UpdateLiveConfig": { + "methods": [ + "update_live_config" + ] + }, + "UpdateSlate": { + "methods": [ + "update_slate" + ] + }, + "UpdateVodConfig": { + "methods": [ + "update_vod_config" + ] + } + } } } } diff --git a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/client.py b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/client.py index 8e528af94ec0..41f3a6dbe14b 100644 --- a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/client.py +++ b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/client.py @@ -83,6 +83,7 @@ from .transports.base import DEFAULT_CLIENT_INFO, VideoStitcherServiceTransport from .transports.grpc import VideoStitcherServiceGrpcTransport from .transports.grpc_asyncio import VideoStitcherServiceGrpcAsyncIOTransport +from .transports.rest import VideoStitcherServiceRestTransport class VideoStitcherServiceClientMeta(type): @@ -98,6 +99,7 @@ class VideoStitcherServiceClientMeta(type): ) # type: Dict[str, Type[VideoStitcherServiceTransport]] _transport_registry["grpc"] = VideoStitcherServiceGrpcTransport _transport_registry["grpc_asyncio"] = VideoStitcherServiceGrpcAsyncIOTransport + _transport_registry["rest"] = VideoStitcherServiceRestTransport def get_transport_class( cls, diff --git a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/__init__.py b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/__init__.py index a54e61f317b5..90203be46261 100644 --- a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/__init__.py +++ b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/__init__.py @@ -19,6 +19,7 @@ from .base import VideoStitcherServiceTransport from .grpc import VideoStitcherServiceGrpcTransport from .grpc_asyncio import VideoStitcherServiceGrpcAsyncIOTransport +from .rest import VideoStitcherServiceRestInterceptor, VideoStitcherServiceRestTransport # Compile a registry of transports. _transport_registry = ( @@ -26,9 +27,12 @@ ) # type: Dict[str, Type[VideoStitcherServiceTransport]] _transport_registry["grpc"] = VideoStitcherServiceGrpcTransport _transport_registry["grpc_asyncio"] = VideoStitcherServiceGrpcAsyncIOTransport +_transport_registry["rest"] = VideoStitcherServiceRestTransport __all__ = ( "VideoStitcherServiceTransport", "VideoStitcherServiceGrpcTransport", "VideoStitcherServiceGrpcAsyncIOTransport", + "VideoStitcherServiceRestTransport", + "VideoStitcherServiceRestInterceptor", ) diff --git a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest.py b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest.py index 55831c29048c..9d93ccd186aa 100644 --- a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest.py +++ b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2022 Google LLC +# Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,49 +13,59 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import dataclasses import json # type: ignore -import re +import logging from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union import warnings -from google.api_core import gapic_v1, path_template, rest_helpers, rest_streaming +from google.api_core import gapic_v1, operations_v1, rest_helpers, rest_streaming from google.api_core import exceptions as core_exceptions from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore from google.auth.transport.requests import AuthorizedSession # type: ignore +from google.longrunning import operations_pb2 # type: ignore +import google.protobuf from google.protobuf import json_format -import grpc # type: ignore from requests import __version__ as requests_version -try: - OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] -except AttributeError: # pragma: NO COVER - OptionalRetry = Union[retries.Retry, object] # type: ignore - - -from google.protobuf import empty_pb2 # type: ignore - from google.cloud.video.stitcher_v1.types import ( ad_tag_details, cdn_keys, + live_configs, sessions, slates, stitch_details, video_stitcher_service, + vod_configs, ) from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO -from .base import VideoStitcherServiceTransport +from .rest_base import _BaseVideoStitcherServiceRestTransport + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object, None] # type: ignore + +try: + from google.api_core import client_logging # type: ignore + + CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER +except ImportError: # pragma: NO COVER + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = logging.getLogger(__name__) DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, grpc_version=None, - rest_version=requests_version, + rest_version=f"requests@{requests_version}", ) +if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER + DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ + class VideoStitcherServiceRestInterceptor: """Interceptor for VideoStitcherService. @@ -80,6 +90,14 @@ def post_create_cdn_key(self, response): logging.log(f"Received response: {response}") return response + def pre_create_live_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_live_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_create_live_session(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -96,6 +114,14 @@ def post_create_slate(self, response): logging.log(f"Received response: {response}") return response + def pre_create_vod_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_create_vod_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_create_vod_session(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -108,10 +134,34 @@ def pre_delete_cdn_key(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata + def post_delete_cdn_key(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_delete_live_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_delete_live_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_delete_slate(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata + def post_delete_slate(self, response): + logging.log(f"Received response: {response}") + return response + + def pre_delete_vod_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_delete_vod_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_cdn_key(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -128,6 +178,14 @@ def post_get_live_ad_tag_detail(self, response): logging.log(f"Received response: {response}") return response + def pre_get_live_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_live_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_live_session(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -152,6 +210,14 @@ def post_get_vod_ad_tag_detail(self, response): logging.log(f"Received response: {response}") return response + def pre_get_vod_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_get_vod_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_get_vod_session(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -184,6 +250,14 @@ def post_list_live_ad_tag_details(self, response): logging.log(f"Received response: {response}") return response + def pre_list_live_configs(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_live_configs(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_slates(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -200,6 +274,14 @@ def post_list_vod_ad_tag_details(self, response): logging.log(f"Received response: {response}") return response + def pre_list_vod_configs(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_list_vod_configs(self, response): + logging.log(f"Received response: {response}") + return response + def pre_list_vod_stitch_details(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -216,6 +298,14 @@ def post_update_cdn_key(self, response): logging.log(f"Received response: {response}") return response + def pre_update_live_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_live_config(self, response): + logging.log(f"Received response: {response}") + return response + def pre_update_slate(self, request, metadata): logging.log(f"Received request: {request}") return request, metadata @@ -224,6 +314,14 @@ def post_update_slate(self, response): logging.log(f"Received response: {response}") return response + def pre_update_vod_config(self, request, metadata): + logging.log(f"Received request: {request}") + return request, metadata + + def post_update_vod_config(self, response): + logging.log(f"Received response: {response}") + return response + transport = VideoStitcherServiceRestTransport(interceptor=MyCustomVideoStitcherServiceInterceptor()) client = VideoStitcherServiceClient(transport=transport) @@ -233,8 +331,11 @@ def post_update_slate(self, response): def pre_create_cdn_key( self, request: video_stitcher_service.CreateCdnKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.CreateCdnKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.CreateCdnKeyRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_cdn_key Override in a subclass to manipulate the request or metadata @@ -242,21 +343,96 @@ def pre_create_cdn_key( """ return request, metadata - def post_create_cdn_key(self, response: cdn_keys.CdnKey) -> cdn_keys.CdnKey: + def post_create_cdn_key( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: """Post-rpc interceptor for create_cdn_key - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_create_cdn_key_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_create_cdn_key` interceptor runs + before the `post_create_cdn_key_with_metadata` interceptor. + """ + return response + + def post_create_cdn_key_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_cdn_key + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_create_cdn_key_with_metadata` + interceptor in new development instead of the `post_create_cdn_key` interceptor. + When both interceptors are used, this `post_create_cdn_key_with_metadata` interceptor runs after the + `post_create_cdn_key` interceptor. The (possibly modified) response returned by + `post_create_cdn_key` will be passed to + `post_create_cdn_key_with_metadata`. + """ + return response, metadata + + def pre_create_live_config( + self, + request: video_stitcher_service.CreateLiveConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.CreateLiveConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for create_live_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_create_live_config( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for create_live_config + + DEPRECATED. Please use the `post_create_live_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_create_live_config` interceptor runs + before the `post_create_live_config_with_metadata` interceptor. """ return response + def post_create_live_config_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_live_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_create_live_config_with_metadata` + interceptor in new development instead of the `post_create_live_config` interceptor. + When both interceptors are used, this `post_create_live_config_with_metadata` interceptor runs after the + `post_create_live_config` interceptor. The (possibly modified) response returned by + `post_create_live_config` will be passed to + `post_create_live_config_with_metadata`. + """ + return response, metadata + def pre_create_live_session( self, request: video_stitcher_service.CreateLiveSessionRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.CreateLiveSessionRequest, Sequence[Tuple[str, str]] + video_stitcher_service.CreateLiveSessionRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_live_session @@ -270,17 +446,43 @@ def post_create_live_session( ) -> sessions.LiveSession: """Post-rpc interceptor for create_live_session - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_create_live_session_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_create_live_session` interceptor runs + before the `post_create_live_session_with_metadata` interceptor. """ return response + def post_create_live_session_with_metadata( + self, + response: sessions.LiveSession, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[sessions.LiveSession, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_live_session + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_create_live_session_with_metadata` + interceptor in new development instead of the `post_create_live_session` interceptor. + When both interceptors are used, this `post_create_live_session_with_metadata` interceptor runs after the + `post_create_live_session` interceptor. The (possibly modified) response returned by + `post_create_live_session` will be passed to + `post_create_live_session_with_metadata`. + """ + return response, metadata + def pre_create_slate( self, request: video_stitcher_service.CreateSlateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.CreateSlateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.CreateSlateRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for create_slate Override in a subclass to manipulate the request or metadata @@ -288,21 +490,96 @@ def pre_create_slate( """ return request, metadata - def post_create_slate(self, response: slates.Slate) -> slates.Slate: + def post_create_slate( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: """Post-rpc interceptor for create_slate - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_create_slate_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_create_slate` interceptor runs + before the `post_create_slate_with_metadata` interceptor. + """ + return response + + def post_create_slate_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_slate + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_create_slate_with_metadata` + interceptor in new development instead of the `post_create_slate` interceptor. + When both interceptors are used, this `post_create_slate_with_metadata` interceptor runs after the + `post_create_slate` interceptor. The (possibly modified) response returned by + `post_create_slate` will be passed to + `post_create_slate_with_metadata`. + """ + return response, metadata + + def pre_create_vod_config( + self, + request: video_stitcher_service.CreateVodConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.CreateVodConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for create_vod_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_create_vod_config( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for create_vod_config + + DEPRECATED. Please use the `post_create_vod_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_create_vod_config` interceptor runs + before the `post_create_vod_config_with_metadata` interceptor. """ return response + def post_create_vod_config_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_vod_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_create_vod_config_with_metadata` + interceptor in new development instead of the `post_create_vod_config` interceptor. + When both interceptors are used, this `post_create_vod_config_with_metadata` interceptor runs after the + `post_create_vod_config` interceptor. The (possibly modified) response returned by + `post_create_vod_config` will be passed to + `post_create_vod_config_with_metadata`. + """ + return response, metadata + def pre_create_vod_session( self, request: video_stitcher_service.CreateVodSessionRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.CreateVodSessionRequest, Sequence[Tuple[str, str]] + video_stitcher_service.CreateVodSessionRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for create_vod_session @@ -316,17 +593,43 @@ def post_create_vod_session( ) -> sessions.VodSession: """Post-rpc interceptor for create_vod_session - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_create_vod_session_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_create_vod_session` interceptor runs + before the `post_create_vod_session_with_metadata` interceptor. """ return response + def post_create_vod_session_with_metadata( + self, + response: sessions.VodSession, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[sessions.VodSession, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for create_vod_session + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_create_vod_session_with_metadata` + interceptor in new development instead of the `post_create_vod_session` interceptor. + When both interceptors are used, this `post_create_vod_session_with_metadata` interceptor runs after the + `post_create_vod_session` interceptor. The (possibly modified) response returned by + `post_create_vod_session` will be passed to + `post_create_vod_session_with_metadata`. + """ + return response, metadata + def pre_delete_cdn_key( self, request: video_stitcher_service.DeleteCdnKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.DeleteCdnKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.DeleteCdnKeyRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for delete_cdn_key Override in a subclass to manipulate the request or metadata @@ -334,139 +637,531 @@ def pre_delete_cdn_key( """ return request, metadata - def pre_delete_slate( - self, - request: video_stitcher_service.DeleteSlateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.DeleteSlateRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for delete_slate + def post_delete_cdn_key( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for delete_cdn_key - Override in a subclass to manipulate the request or metadata - before they are sent to the VideoStitcherService server. + DEPRECATED. Please use the `post_delete_cdn_key_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_delete_cdn_key` interceptor runs + before the `post_delete_cdn_key_with_metadata` interceptor. """ - return request, metadata + return response - def pre_get_cdn_key( + def post_delete_cdn_key_with_metadata( self, - request: video_stitcher_service.GetCdnKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.GetCdnKeyRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_cdn_key + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for delete_cdn_key + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_delete_cdn_key_with_metadata` + interceptor in new development instead of the `post_delete_cdn_key` interceptor. + When both interceptors are used, this `post_delete_cdn_key_with_metadata` interceptor runs after the + `post_delete_cdn_key` interceptor. The (possibly modified) response returned by + `post_delete_cdn_key` will be passed to + `post_delete_cdn_key_with_metadata`. + """ + return response, metadata + + def pre_delete_live_config( + self, + request: video_stitcher_service.DeleteLiveConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.DeleteLiveConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for delete_live_config Override in a subclass to manipulate the request or metadata before they are sent to the VideoStitcherService server. """ return request, metadata - def post_get_cdn_key(self, response: cdn_keys.CdnKey) -> cdn_keys.CdnKey: - """Post-rpc interceptor for get_cdn_key + def post_delete_live_config( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for delete_live_config - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_delete_live_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_delete_live_config` interceptor runs + before the `post_delete_live_config_with_metadata` interceptor. """ return response - def pre_get_live_ad_tag_detail( + def post_delete_live_config_with_metadata( self, - request: video_stitcher_service.GetLiveAdTagDetailRequest, - metadata: Sequence[Tuple[str, str]], + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for delete_live_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_delete_live_config_with_metadata` + interceptor in new development instead of the `post_delete_live_config` interceptor. + When both interceptors are used, this `post_delete_live_config_with_metadata` interceptor runs after the + `post_delete_live_config` interceptor. The (possibly modified) response returned by + `post_delete_live_config` will be passed to + `post_delete_live_config_with_metadata`. + """ + return response, metadata + + def pre_delete_slate( + self, + request: video_stitcher_service.DeleteSlateRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.GetLiveAdTagDetailRequest, Sequence[Tuple[str, str]] + video_stitcher_service.DeleteSlateRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: - """Pre-rpc interceptor for get_live_ad_tag_detail + """Pre-rpc interceptor for delete_slate Override in a subclass to manipulate the request or metadata before they are sent to the VideoStitcherService server. """ return request, metadata - def post_get_live_ad_tag_detail( - self, response: ad_tag_details.LiveAdTagDetail - ) -> ad_tag_details.LiveAdTagDetail: - """Post-rpc interceptor for get_live_ad_tag_detail + def post_delete_slate( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for delete_slate - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_delete_slate_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_delete_slate` interceptor runs + before the `post_delete_slate_with_metadata` interceptor. """ return response - def pre_get_live_session( + def post_delete_slate_with_metadata( self, - request: video_stitcher_service.GetLiveSessionRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.GetLiveSessionRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_live_session + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for delete_slate + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_delete_slate_with_metadata` + interceptor in new development instead of the `post_delete_slate` interceptor. + When both interceptors are used, this `post_delete_slate_with_metadata` interceptor runs after the + `post_delete_slate` interceptor. The (possibly modified) response returned by + `post_delete_slate` will be passed to + `post_delete_slate_with_metadata`. + """ + return response, metadata + + def pre_delete_vod_config( + self, + request: video_stitcher_service.DeleteVodConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.DeleteVodConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for delete_vod_config Override in a subclass to manipulate the request or metadata before they are sent to the VideoStitcherService server. """ return request, metadata - def post_get_live_session( - self, response: sessions.LiveSession - ) -> sessions.LiveSession: - """Post-rpc interceptor for get_live_session + def post_delete_vod_config( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for delete_vod_config - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_delete_vod_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_delete_vod_config` interceptor runs + before the `post_delete_vod_config_with_metadata` interceptor. """ return response - def pre_get_slate( + def post_delete_vod_config_with_metadata( self, - request: video_stitcher_service.GetSlateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.GetSlateRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_slate + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for delete_vod_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_delete_vod_config_with_metadata` + interceptor in new development instead of the `post_delete_vod_config` interceptor. + When both interceptors are used, this `post_delete_vod_config_with_metadata` interceptor runs after the + `post_delete_vod_config` interceptor. The (possibly modified) response returned by + `post_delete_vod_config` will be passed to + `post_delete_vod_config_with_metadata`. + """ + return response, metadata + + def pre_get_cdn_key( + self, + request: video_stitcher_service.GetCdnKeyRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetCdnKeyRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for get_cdn_key Override in a subclass to manipulate the request or metadata before they are sent to the VideoStitcherService server. """ return request, metadata - def post_get_slate(self, response: slates.Slate) -> slates.Slate: - """Post-rpc interceptor for get_slate + def post_get_cdn_key(self, response: cdn_keys.CdnKey) -> cdn_keys.CdnKey: + """Post-rpc interceptor for get_cdn_key - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_get_cdn_key_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_get_cdn_key` interceptor runs + before the `post_get_cdn_key_with_metadata` interceptor. """ return response - def pre_get_vod_ad_tag_detail( + def post_get_cdn_key_with_metadata( self, - request: video_stitcher_service.GetVodAdTagDetailRequest, - metadata: Sequence[Tuple[str, str]], + response: cdn_keys.CdnKey, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[cdn_keys.CdnKey, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_cdn_key + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_cdn_key_with_metadata` + interceptor in new development instead of the `post_get_cdn_key` interceptor. + When both interceptors are used, this `post_get_cdn_key_with_metadata` interceptor runs after the + `post_get_cdn_key` interceptor. The (possibly modified) response returned by + `post_get_cdn_key` will be passed to + `post_get_cdn_key_with_metadata`. + """ + return response, metadata + + def pre_get_live_ad_tag_detail( + self, + request: video_stitcher_service.GetLiveAdTagDetailRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.GetVodAdTagDetailRequest, Sequence[Tuple[str, str]] + video_stitcher_service.GetLiveAdTagDetailRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: - """Pre-rpc interceptor for get_vod_ad_tag_detail + """Pre-rpc interceptor for get_live_ad_tag_detail Override in a subclass to manipulate the request or metadata before they are sent to the VideoStitcherService server. """ return request, metadata - def post_get_vod_ad_tag_detail( - self, response: ad_tag_details.VodAdTagDetail - ) -> ad_tag_details.VodAdTagDetail: - """Post-rpc interceptor for get_vod_ad_tag_detail + def post_get_live_ad_tag_detail( + self, response: ad_tag_details.LiveAdTagDetail + ) -> ad_tag_details.LiveAdTagDetail: + """Post-rpc interceptor for get_live_ad_tag_detail - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_get_live_ad_tag_detail_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_get_live_ad_tag_detail` interceptor runs + before the `post_get_live_ad_tag_detail_with_metadata` interceptor. """ return response - def pre_get_vod_session( + def post_get_live_ad_tag_detail_with_metadata( self, - request: video_stitcher_service.GetVodSessionRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.GetVodSessionRequest, Sequence[Tuple[str, str]]]: - """Pre-rpc interceptor for get_vod_session + response: ad_tag_details.LiveAdTagDetail, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ad_tag_details.LiveAdTagDetail, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_live_ad_tag_detail + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_live_ad_tag_detail_with_metadata` + interceptor in new development instead of the `post_get_live_ad_tag_detail` interceptor. + When both interceptors are used, this `post_get_live_ad_tag_detail_with_metadata` interceptor runs after the + `post_get_live_ad_tag_detail` interceptor. The (possibly modified) response returned by + `post_get_live_ad_tag_detail` will be passed to + `post_get_live_ad_tag_detail_with_metadata`. + """ + return response, metadata + + def pre_get_live_config( + self, + request: video_stitcher_service.GetLiveConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetLiveConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for get_live_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_get_live_config( + self, response: live_configs.LiveConfig + ) -> live_configs.LiveConfig: + """Post-rpc interceptor for get_live_config + + DEPRECATED. Please use the `post_get_live_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_get_live_config` interceptor runs + before the `post_get_live_config_with_metadata` interceptor. + """ + return response + + def post_get_live_config_with_metadata( + self, + response: live_configs.LiveConfig, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[live_configs.LiveConfig, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_live_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_live_config_with_metadata` + interceptor in new development instead of the `post_get_live_config` interceptor. + When both interceptors are used, this `post_get_live_config_with_metadata` interceptor runs after the + `post_get_live_config` interceptor. The (possibly modified) response returned by + `post_get_live_config` will be passed to + `post_get_live_config_with_metadata`. + """ + return response, metadata + + def pre_get_live_session( + self, + request: video_stitcher_service.GetLiveSessionRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetLiveSessionRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for get_live_session + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_get_live_session( + self, response: sessions.LiveSession + ) -> sessions.LiveSession: + """Post-rpc interceptor for get_live_session + + DEPRECATED. Please use the `post_get_live_session_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_get_live_session` interceptor runs + before the `post_get_live_session_with_metadata` interceptor. + """ + return response + + def post_get_live_session_with_metadata( + self, + response: sessions.LiveSession, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[sessions.LiveSession, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_live_session + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_live_session_with_metadata` + interceptor in new development instead of the `post_get_live_session` interceptor. + When both interceptors are used, this `post_get_live_session_with_metadata` interceptor runs after the + `post_get_live_session` interceptor. The (possibly modified) response returned by + `post_get_live_session` will be passed to + `post_get_live_session_with_metadata`. + """ + return response, metadata + + def pre_get_slate( + self, + request: video_stitcher_service.GetSlateRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetSlateRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for get_slate + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_get_slate(self, response: slates.Slate) -> slates.Slate: + """Post-rpc interceptor for get_slate + + DEPRECATED. Please use the `post_get_slate_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_get_slate` interceptor runs + before the `post_get_slate_with_metadata` interceptor. + """ + return response + + def post_get_slate_with_metadata( + self, response: slates.Slate, metadata: Sequence[Tuple[str, Union[str, bytes]]] + ) -> Tuple[slates.Slate, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_slate + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_slate_with_metadata` + interceptor in new development instead of the `post_get_slate` interceptor. + When both interceptors are used, this `post_get_slate_with_metadata` interceptor runs after the + `post_get_slate` interceptor. The (possibly modified) response returned by + `post_get_slate` will be passed to + `post_get_slate_with_metadata`. + """ + return response, metadata + + def pre_get_vod_ad_tag_detail( + self, + request: video_stitcher_service.GetVodAdTagDetailRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetVodAdTagDetailRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for get_vod_ad_tag_detail + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_get_vod_ad_tag_detail( + self, response: ad_tag_details.VodAdTagDetail + ) -> ad_tag_details.VodAdTagDetail: + """Post-rpc interceptor for get_vod_ad_tag_detail + + DEPRECATED. Please use the `post_get_vod_ad_tag_detail_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_get_vod_ad_tag_detail` interceptor runs + before the `post_get_vod_ad_tag_detail_with_metadata` interceptor. + """ + return response + + def post_get_vod_ad_tag_detail_with_metadata( + self, + response: ad_tag_details.VodAdTagDetail, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ad_tag_details.VodAdTagDetail, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_vod_ad_tag_detail + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_vod_ad_tag_detail_with_metadata` + interceptor in new development instead of the `post_get_vod_ad_tag_detail` interceptor. + When both interceptors are used, this `post_get_vod_ad_tag_detail_with_metadata` interceptor runs after the + `post_get_vod_ad_tag_detail` interceptor. The (possibly modified) response returned by + `post_get_vod_ad_tag_detail` will be passed to + `post_get_vod_ad_tag_detail_with_metadata`. + """ + return response, metadata + + def pre_get_vod_config( + self, + request: video_stitcher_service.GetVodConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetVodConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for get_vod_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_get_vod_config( + self, response: vod_configs.VodConfig + ) -> vod_configs.VodConfig: + """Post-rpc interceptor for get_vod_config + + DEPRECATED. Please use the `post_get_vod_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_get_vod_config` interceptor runs + before the `post_get_vod_config_with_metadata` interceptor. + """ + return response + + def post_get_vod_config_with_metadata( + self, + response: vod_configs.VodConfig, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[vod_configs.VodConfig, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_vod_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_vod_config_with_metadata` + interceptor in new development instead of the `post_get_vod_config` interceptor. + When both interceptors are used, this `post_get_vod_config_with_metadata` interceptor runs after the + `post_get_vod_config` interceptor. The (possibly modified) response returned by + `post_get_vod_config` will be passed to + `post_get_vod_config_with_metadata`. + """ + return response, metadata + + def pre_get_vod_session( + self, + request: video_stitcher_service.GetVodSessionRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.GetVodSessionRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for get_vod_session Override in a subclass to manipulate the request or metadata before they are sent to the VideoStitcherService server. @@ -478,18 +1173,42 @@ def post_get_vod_session( ) -> sessions.VodSession: """Post-rpc interceptor for get_vod_session - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_get_vod_session_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_get_vod_session` interceptor runs + before the `post_get_vod_session_with_metadata` interceptor. """ return response + def post_get_vod_session_with_metadata( + self, + response: sessions.VodSession, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[sessions.VodSession, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_vod_session + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_vod_session_with_metadata` + interceptor in new development instead of the `post_get_vod_session` interceptor. + When both interceptors are used, this `post_get_vod_session_with_metadata` interceptor runs after the + `post_get_vod_session` interceptor. The (possibly modified) response returned by + `post_get_vod_session` will be passed to + `post_get_vod_session_with_metadata`. + """ + return response, metadata + def pre_get_vod_stitch_detail( self, request: video_stitcher_service.GetVodStitchDetailRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.GetVodStitchDetailRequest, Sequence[Tuple[str, str]] + video_stitcher_service.GetVodStitchDetailRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for get_vod_stitch_detail @@ -503,17 +1222,43 @@ def post_get_vod_stitch_detail( ) -> stitch_details.VodStitchDetail: """Post-rpc interceptor for get_vod_stitch_detail - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_get_vod_stitch_detail_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_get_vod_stitch_detail` interceptor runs + before the `post_get_vod_stitch_detail_with_metadata` interceptor. """ return response + def post_get_vod_stitch_detail_with_metadata( + self, + response: stitch_details.VodStitchDetail, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[stitch_details.VodStitchDetail, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for get_vod_stitch_detail + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_get_vod_stitch_detail_with_metadata` + interceptor in new development instead of the `post_get_vod_stitch_detail` interceptor. + When both interceptors are used, this `post_get_vod_stitch_detail_with_metadata` interceptor runs after the + `post_get_vod_stitch_detail` interceptor. The (possibly modified) response returned by + `post_get_vod_stitch_detail` will be passed to + `post_get_vod_stitch_detail_with_metadata`. + """ + return response, metadata + def pre_list_cdn_keys( self, request: video_stitcher_service.ListCdnKeysRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.ListCdnKeysRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListCdnKeysRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_cdn_keys Override in a subclass to manipulate the request or metadata @@ -526,18 +1271,45 @@ def post_list_cdn_keys( ) -> video_stitcher_service.ListCdnKeysResponse: """Post-rpc interceptor for list_cdn_keys - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_list_cdn_keys_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_list_cdn_keys` interceptor runs + before the `post_list_cdn_keys_with_metadata` interceptor. """ return response + def post_list_cdn_keys_with_metadata( + self, + response: video_stitcher_service.ListCdnKeysResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListCdnKeysResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_cdn_keys + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_cdn_keys_with_metadata` + interceptor in new development instead of the `post_list_cdn_keys` interceptor. + When both interceptors are used, this `post_list_cdn_keys_with_metadata` interceptor runs after the + `post_list_cdn_keys` interceptor. The (possibly modified) response returned by + `post_list_cdn_keys` will be passed to + `post_list_cdn_keys_with_metadata`. + """ + return response, metadata + def pre_list_live_ad_tag_details( self, request: video_stitcher_service.ListLiveAdTagDetailsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.ListLiveAdTagDetailsRequest, Sequence[Tuple[str, str]] + video_stitcher_service.ListLiveAdTagDetailsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_live_ad_tag_details @@ -551,17 +1323,98 @@ def post_list_live_ad_tag_details( ) -> video_stitcher_service.ListLiveAdTagDetailsResponse: """Post-rpc interceptor for list_live_ad_tag_details - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_list_live_ad_tag_details_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_list_live_ad_tag_details` interceptor runs + before the `post_list_live_ad_tag_details_with_metadata` interceptor. + """ + return response + + def post_list_live_ad_tag_details_with_metadata( + self, + response: video_stitcher_service.ListLiveAdTagDetailsResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListLiveAdTagDetailsResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_live_ad_tag_details + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_live_ad_tag_details_with_metadata` + interceptor in new development instead of the `post_list_live_ad_tag_details` interceptor. + When both interceptors are used, this `post_list_live_ad_tag_details_with_metadata` interceptor runs after the + `post_list_live_ad_tag_details` interceptor. The (possibly modified) response returned by + `post_list_live_ad_tag_details` will be passed to + `post_list_live_ad_tag_details_with_metadata`. + """ + return response, metadata + + def pre_list_live_configs( + self, + request: video_stitcher_service.ListLiveConfigsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListLiveConfigsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for list_live_configs + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_list_live_configs( + self, response: video_stitcher_service.ListLiveConfigsResponse + ) -> video_stitcher_service.ListLiveConfigsResponse: + """Post-rpc interceptor for list_live_configs + + DEPRECATED. Please use the `post_list_live_configs_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_list_live_configs` interceptor runs + before the `post_list_live_configs_with_metadata` interceptor. """ return response + def post_list_live_configs_with_metadata( + self, + response: video_stitcher_service.ListLiveConfigsResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListLiveConfigsResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_live_configs + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_live_configs_with_metadata` + interceptor in new development instead of the `post_list_live_configs` interceptor. + When both interceptors are used, this `post_list_live_configs_with_metadata` interceptor runs after the + `post_list_live_configs` interceptor. The (possibly modified) response returned by + `post_list_live_configs` will be passed to + `post_list_live_configs_with_metadata`. + """ + return response, metadata + def pre_list_slates( self, request: video_stitcher_service.ListSlatesRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.ListSlatesRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListSlatesRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for list_slates Override in a subclass to manipulate the request or metadata @@ -574,18 +1427,45 @@ def post_list_slates( ) -> video_stitcher_service.ListSlatesResponse: """Post-rpc interceptor for list_slates - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_list_slates_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_list_slates` interceptor runs + before the `post_list_slates_with_metadata` interceptor. """ return response + def post_list_slates_with_metadata( + self, + response: video_stitcher_service.ListSlatesResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListSlatesResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_slates + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_slates_with_metadata` + interceptor in new development instead of the `post_list_slates` interceptor. + When both interceptors are used, this `post_list_slates_with_metadata` interceptor runs after the + `post_list_slates` interceptor. The (possibly modified) response returned by + `post_list_slates` will be passed to + `post_list_slates_with_metadata`. + """ + return response, metadata + def pre_list_vod_ad_tag_details( self, request: video_stitcher_service.ListVodAdTagDetailsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.ListVodAdTagDetailsRequest, Sequence[Tuple[str, str]] + video_stitcher_service.ListVodAdTagDetailsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_vod_ad_tag_details @@ -599,18 +1479,97 @@ def post_list_vod_ad_tag_details( ) -> video_stitcher_service.ListVodAdTagDetailsResponse: """Post-rpc interceptor for list_vod_ad_tag_details - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_list_vod_ad_tag_details_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_list_vod_ad_tag_details` interceptor runs + before the `post_list_vod_ad_tag_details_with_metadata` interceptor. + """ + return response + + def post_list_vod_ad_tag_details_with_metadata( + self, + response: video_stitcher_service.ListVodAdTagDetailsResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListVodAdTagDetailsResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_vod_ad_tag_details + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_vod_ad_tag_details_with_metadata` + interceptor in new development instead of the `post_list_vod_ad_tag_details` interceptor. + When both interceptors are used, this `post_list_vod_ad_tag_details_with_metadata` interceptor runs after the + `post_list_vod_ad_tag_details` interceptor. The (possibly modified) response returned by + `post_list_vod_ad_tag_details` will be passed to + `post_list_vod_ad_tag_details_with_metadata`. + """ + return response, metadata + + def pre_list_vod_configs( + self, + request: video_stitcher_service.ListVodConfigsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListVodConfigsRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for list_vod_configs + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_list_vod_configs( + self, response: video_stitcher_service.ListVodConfigsResponse + ) -> video_stitcher_service.ListVodConfigsResponse: + """Post-rpc interceptor for list_vod_configs + + DEPRECATED. Please use the `post_list_vod_configs_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_list_vod_configs` interceptor runs + before the `post_list_vod_configs_with_metadata` interceptor. """ return response + def post_list_vod_configs_with_metadata( + self, + response: video_stitcher_service.ListVodConfigsResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListVodConfigsResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_vod_configs + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_vod_configs_with_metadata` + interceptor in new development instead of the `post_list_vod_configs` interceptor. + When both interceptors are used, this `post_list_vod_configs_with_metadata` interceptor runs after the + `post_list_vod_configs` interceptor. The (possibly modified) response returned by + `post_list_vod_configs` will be passed to + `post_list_vod_configs_with_metadata`. + """ + return response, metadata + def pre_list_vod_stitch_details( self, request: video_stitcher_service.ListVodStitchDetailsRequest, - metadata: Sequence[Tuple[str, str]], + metadata: Sequence[Tuple[str, Union[str, bytes]]], ) -> Tuple[ - video_stitcher_service.ListVodStitchDetailsRequest, Sequence[Tuple[str, str]] + video_stitcher_service.ListVodStitchDetailsRequest, + Sequence[Tuple[str, Union[str, bytes]]], ]: """Pre-rpc interceptor for list_vod_stitch_details @@ -624,17 +1583,46 @@ def post_list_vod_stitch_details( ) -> video_stitcher_service.ListVodStitchDetailsResponse: """Post-rpc interceptor for list_vod_stitch_details - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_list_vod_stitch_details_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_list_vod_stitch_details` interceptor runs + before the `post_list_vod_stitch_details_with_metadata` interceptor. """ return response + def post_list_vod_stitch_details_with_metadata( + self, + response: video_stitcher_service.ListVodStitchDetailsResponse, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.ListVodStitchDetailsResponse, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Post-rpc interceptor for list_vod_stitch_details + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_list_vod_stitch_details_with_metadata` + interceptor in new development instead of the `post_list_vod_stitch_details` interceptor. + When both interceptors are used, this `post_list_vod_stitch_details_with_metadata` interceptor runs after the + `post_list_vod_stitch_details` interceptor. The (possibly modified) response returned by + `post_list_vod_stitch_details` will be passed to + `post_list_vod_stitch_details_with_metadata`. + """ + return response, metadata + def pre_update_cdn_key( self, request: video_stitcher_service.UpdateCdnKeyRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.UpdateCdnKeyRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.UpdateCdnKeyRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_cdn_key Override in a subclass to manipulate the request or metadata @@ -642,20 +1630,97 @@ def pre_update_cdn_key( """ return request, metadata - def post_update_cdn_key(self, response: cdn_keys.CdnKey) -> cdn_keys.CdnKey: + def post_update_cdn_key( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: """Post-rpc interceptor for update_cdn_key - Override in a subclass to manipulate the response + DEPRECATED. Please use the `post_update_cdn_key_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response after it is returned by the VideoStitcherService server but before - it is returned to user code. + it is returned to user code. This `post_update_cdn_key` interceptor runs + before the `post_update_cdn_key_with_metadata` interceptor. + """ + return response + + def post_update_cdn_key_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for update_cdn_key + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_update_cdn_key_with_metadata` + interceptor in new development instead of the `post_update_cdn_key` interceptor. + When both interceptors are used, this `post_update_cdn_key_with_metadata` interceptor runs after the + `post_update_cdn_key` interceptor. The (possibly modified) response returned by + `post_update_cdn_key` will be passed to + `post_update_cdn_key_with_metadata`. + """ + return response, metadata + + def pre_update_live_config( + self, + request: video_stitcher_service.UpdateLiveConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.UpdateLiveConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for update_live_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_update_live_config( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for update_live_config + + DEPRECATED. Please use the `post_update_live_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_update_live_config` interceptor runs + before the `post_update_live_config_with_metadata` interceptor. """ return response + def post_update_live_config_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for update_live_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_update_live_config_with_metadata` + interceptor in new development instead of the `post_update_live_config` interceptor. + When both interceptors are used, this `post_update_live_config_with_metadata` interceptor runs after the + `post_update_live_config` interceptor. The (possibly modified) response returned by + `post_update_live_config` will be passed to + `post_update_live_config_with_metadata`. + """ + return response, metadata + def pre_update_slate( self, request: video_stitcher_service.UpdateSlateRequest, - metadata: Sequence[Tuple[str, str]], - ) -> Tuple[video_stitcher_service.UpdateSlateRequest, Sequence[Tuple[str, str]]]: + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.UpdateSlateRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: """Pre-rpc interceptor for update_slate Override in a subclass to manipulate the request or metadata @@ -663,9 +1728,179 @@ def pre_update_slate( """ return request, metadata - def post_update_slate(self, response: slates.Slate) -> slates.Slate: + def post_update_slate( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for update_slate + + DEPRECATED. Please use the `post_update_slate_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_update_slate` interceptor runs + before the `post_update_slate_with_metadata` interceptor. + """ + return response + + def post_update_slate_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: """Post-rpc interceptor for update_slate + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_update_slate_with_metadata` + interceptor in new development instead of the `post_update_slate` interceptor. + When both interceptors are used, this `post_update_slate_with_metadata` interceptor runs after the + `post_update_slate` interceptor. The (possibly modified) response returned by + `post_update_slate` will be passed to + `post_update_slate_with_metadata`. + """ + return response, metadata + + def pre_update_vod_config( + self, + request: video_stitcher_service.UpdateVodConfigRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + video_stitcher_service.UpdateVodConfigRequest, + Sequence[Tuple[str, Union[str, bytes]]], + ]: + """Pre-rpc interceptor for update_vod_config + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_update_vod_config( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for update_vod_config + + DEPRECATED. Please use the `post_update_vod_config_with_metadata` + interceptor instead. + + Override in a subclass to read or manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. This `post_update_vod_config` interceptor runs + before the `post_update_vod_config_with_metadata` interceptor. + """ + return response + + def post_update_vod_config_with_metadata( + self, + response: operations_pb2.Operation, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[operations_pb2.Operation, Sequence[Tuple[str, Union[str, bytes]]]]: + """Post-rpc interceptor for update_vod_config + + Override in a subclass to read or manipulate the response or metadata after it + is returned by the VideoStitcherService server but before it is returned to user code. + + We recommend only using this `post_update_vod_config_with_metadata` + interceptor in new development instead of the `post_update_vod_config` interceptor. + When both interceptors are used, this `post_update_vod_config_with_metadata` interceptor runs after the + `post_update_vod_config` interceptor. The (possibly modified) response returned by + `post_update_vod_config` will be passed to + `post_update_vod_config_with_metadata`. + """ + return response, metadata + + def pre_cancel_operation( + self, + request: operations_pb2.CancelOperationRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.CancelOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_cancel_operation(self, response: None) -> None: + """Post-rpc interceptor for cancel_operation + + Override in a subclass to manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. + """ + return response + + def pre_delete_operation( + self, + request: operations_pb2.DeleteOperationRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.DeleteOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for delete_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_delete_operation(self, response: None) -> None: + """Post-rpc interceptor for delete_operation + + Override in a subclass to manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. + """ + return response + + def pre_get_operation( + self, + request: operations_pb2.GetOperationRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.GetOperationRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for get_operation + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_get_operation( + self, response: operations_pb2.Operation + ) -> operations_pb2.Operation: + """Post-rpc interceptor for get_operation + + Override in a subclass to manipulate the response + after it is returned by the VideoStitcherService server but before + it is returned to user code. + """ + return response + + def pre_list_operations( + self, + request: operations_pb2.ListOperationsRequest, + metadata: Sequence[Tuple[str, Union[str, bytes]]], + ) -> Tuple[ + operations_pb2.ListOperationsRequest, Sequence[Tuple[str, Union[str, bytes]]] + ]: + """Pre-rpc interceptor for list_operations + + Override in a subclass to manipulate the request or metadata + before they are sent to the VideoStitcherService server. + """ + return request, metadata + + def post_list_operations( + self, response: operations_pb2.ListOperationsResponse + ) -> operations_pb2.ListOperationsResponse: + """Post-rpc interceptor for list_operations + Override in a subclass to manipulate the response after it is returned by the VideoStitcherService server but before it is returned to user code. @@ -680,8 +1915,8 @@ class VideoStitcherServiceRestStub: _interceptor: VideoStitcherServiceRestInterceptor -class VideoStitcherServiceRestTransport(VideoStitcherServiceTransport): - """REST backend transport for VideoStitcherService. +class VideoStitcherServiceRestTransport(_BaseVideoStitcherServiceRestTransport): + """REST backend synchronous transport for VideoStitcherService. Video-On-Demand content stitching API allows you to insert ads into (VoD) video on demand files. You will be able to render @@ -694,7 +1929,6 @@ class VideoStitcherServiceRestTransport(VideoStitcherServiceTransport): and call it. It sends JSON representations of protocol buffers over HTTP/1.1 - """ def __init__( @@ -716,99 +1950,1689 @@ def __init__( Args: host (Optional[str]): - The hostname to connect to. + The hostname to connect to (default: 'videostitcher.googleapis.com'). credentials (Optional[google.auth.credentials.Credentials]): The authorization credentials to attach to requests. These credentials identify the application to the service; if none are specified, the client will attempt to ascertain the credentials from the environment. - credentials_file (Optional[str]): A file with credentials that can - be loaded with :func:`google.auth.load_credentials_from_file`. - This argument is ignored if ``channel`` is provided. - scopes (Optional(Sequence[str])): A list of scopes. This argument is - ignored if ``channel`` is provided. - client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client - certificate to configure mutual TLS HTTP channel. It is ignored - if ``channel`` is provided. - quota_project_id (Optional[str]): An optional project to use for billing - and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you are developing - your own client library. - always_use_jwt_access (Optional[bool]): Whether self signed JWT should - be used for service account credentials. - url_scheme: the protocol scheme for the API endpoint. Normally - "https", but for testing or local servers, - "http" can be specified. - """ - # Run the base constructor - # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. - # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the - # credentials object - maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) - if maybe_url_match is None: - raise ValueError( - f"Unexpected hostname structure: {host}" - ) # pragma: NO COVER + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client + certificate to configure mutual TLS HTTP channel. It is ignored + if ``channel`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc. + # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the + # credentials object + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + url_scheme=url_scheme, + api_audience=api_audience, + ) + self._session = AuthorizedSession( + self._credentials, default_host=self.DEFAULT_HOST + ) + self._operations_client: Optional[operations_v1.AbstractOperationsClient] = None + if client_cert_source_for_mtls: + self._session.configure_mtls_channel(client_cert_source_for_mtls) + self._interceptor = interceptor or VideoStitcherServiceRestInterceptor() + self._prep_wrapped_messages(client_info) + + @property + def operations_client(self) -> operations_v1.AbstractOperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Only create a new client if we do not already have one. + if self._operations_client is None: + http_options: Dict[str, List[Dict[str, str]]] = { + "google.longrunning.Operations.CancelOperation": [ + { + "method": "post", + "uri": "/v1/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ], + "google.longrunning.Operations.DeleteOperation": [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/operations/*}", + }, + ], + "google.longrunning.Operations.GetOperation": [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/operations/*}", + }, + ], + "google.longrunning.Operations.ListOperations": [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*}/operations", + }, + ], + } + + rest_transport = operations_v1.OperationsRestTransport( + host=self._host, + # use the credentials which are saved + credentials=self._credentials, + scopes=self._scopes, + http_options=http_options, + path_prefix="v1", + ) + + self._operations_client = operations_v1.AbstractOperationsClient( + transport=rest_transport + ) + + # Return the client from cache. + return self._operations_client + + class _CreateCdnKey( + _BaseVideoStitcherServiceRestTransport._BaseCreateCdnKey, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CreateCdnKey") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: video_stitcher_service.CreateCdnKeyRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the create cdn key method over HTTP. + + Args: + request (~.video_stitcher_service.CreateCdnKeyRequest): + The request object. Request message for + VideoStitcherService.createCdnKey. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCreateCdnKey._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_cdn_key(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCreateCdnKey._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCreateCdnKey._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCreateCdnKey._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CreateCdnKey", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateCdnKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._CreateCdnKey._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_cdn_key(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_cdn_key_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.create_cdn_key", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateCdnKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _CreateLiveConfig( + _BaseVideoStitcherServiceRestTransport._BaseCreateLiveConfig, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CreateLiveConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: video_stitcher_service.CreateLiveConfigRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the create live config method over HTTP. + + Args: + request (~.video_stitcher_service.CreateLiveConfigRequest): + The request object. Request message for + VideoStitcherService.createLiveConfig + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCreateLiveConfig._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_live_config( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCreateLiveConfig._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCreateLiveConfig._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCreateLiveConfig._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CreateLiveConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateLiveConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ( + VideoStitcherServiceRestTransport._CreateLiveConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_live_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_live_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.create_live_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateLiveConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _CreateLiveSession( + _BaseVideoStitcherServiceRestTransport._BaseCreateLiveSession, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CreateLiveSession") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: video_stitcher_service.CreateLiveSessionRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> sessions.LiveSession: + r"""Call the create live session method over HTTP. + + Args: + request (~.video_stitcher_service.CreateLiveSessionRequest): + The request object. Request message for + VideoStitcherService.createLiveSession. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.sessions.LiveSession: + Metadata for a live session. The + session expires 5 minutes after the + client stops fetching the session's + playlists. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCreateLiveSession._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_live_session( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCreateLiveSession._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCreateLiveSession._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCreateLiveSession._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CreateLiveSession", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateLiveSession", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ( + VideoStitcherServiceRestTransport._CreateLiveSession._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = sessions.LiveSession() + pb_resp = sessions.LiveSession.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_live_session(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_live_session_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = sessions.LiveSession.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.create_live_session", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateLiveSession", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _CreateSlate( + _BaseVideoStitcherServiceRestTransport._BaseCreateSlate, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CreateSlate") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: video_stitcher_service.CreateSlateRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the create slate method over HTTP. + + Args: + request (~.video_stitcher_service.CreateSlateRequest): + The request object. Request message for + VideoStitcherService.createSlate. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCreateSlate._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_slate(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCreateSlate._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCreateSlate._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCreateSlate._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CreateSlate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateSlate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._CreateSlate._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_slate(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_slate_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.create_slate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateSlate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _CreateVodConfig( + _BaseVideoStitcherServiceRestTransport._BaseCreateVodConfig, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CreateVodConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: video_stitcher_service.CreateVodConfigRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the create vod config method over HTTP. + + Args: + request (~.video_stitcher_service.CreateVodConfigRequest): + The request object. Request message for + VideoStitcherService.createVodConfig + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCreateVodConfig._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_vod_config( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCreateVodConfig._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCreateVodConfig._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCreateVodConfig._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CreateVodConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateVodConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._CreateVodConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_vod_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_vod_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.create_vod_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateVodConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _CreateVodSession( + _BaseVideoStitcherServiceRestTransport._BaseCreateVodSession, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CreateVodSession") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: video_stitcher_service.CreateVodSessionRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> sessions.VodSession: + r"""Call the create vod session method over HTTP. + + Args: + request (~.video_stitcher_service.CreateVodSessionRequest): + The request object. Request message for + VideoStitcherService.createVodSession + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.sessions.VodSession: + Metadata for a VOD session. The + session expires 4 hours after its + creation. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCreateVodSession._get_http_options() + ) + + request, metadata = self._interceptor.pre_create_vod_session( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCreateVodSession._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCreateVodSession._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCreateVodSession._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CreateVodSession", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateVodSession", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ( + VideoStitcherServiceRestTransport._CreateVodSession._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = sessions.VodSession() + pb_resp = sessions.VodSession.pb(resp) + + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_create_vod_session(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_create_vod_session_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = sessions.VodSession.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.create_vod_session", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CreateVodSession", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _DeleteCdnKey( + _BaseVideoStitcherServiceRestTransport._BaseDeleteCdnKey, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.DeleteCdnKey") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: video_stitcher_service.DeleteCdnKeyRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the delete cdn key method over HTTP. + + Args: + request (~.video_stitcher_service.DeleteCdnKeyRequest): + The request object. Request message for + VideoStitcherService.deleteCdnKey. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseDeleteCdnKey._get_http_options() + ) + + request, metadata = self._interceptor.pre_delete_cdn_key(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseDeleteCdnKey._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseDeleteCdnKey._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.DeleteCdnKey", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteCdnKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._DeleteCdnKey._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_delete_cdn_key(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_delete_cdn_key_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.delete_cdn_key", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteCdnKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _DeleteLiveConfig( + _BaseVideoStitcherServiceRestTransport._BaseDeleteLiveConfig, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.DeleteLiveConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: video_stitcher_service.DeleteLiveConfigRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the delete live config method over HTTP. + + Args: + request (~.video_stitcher_service.DeleteLiveConfigRequest): + The request object. Request message for + VideoStitcherService.deleteLiveConfig. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseDeleteLiveConfig._get_http_options() + ) + + request, metadata = self._interceptor.pre_delete_live_config( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseDeleteLiveConfig._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseDeleteLiveConfig._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.DeleteLiveConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteLiveConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = ( + VideoStitcherServiceRestTransport._DeleteLiveConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_delete_live_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_delete_live_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.delete_live_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteLiveConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _DeleteSlate( + _BaseVideoStitcherServiceRestTransport._BaseDeleteSlate, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.DeleteSlate") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: video_stitcher_service.DeleteSlateRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the delete slate method over HTTP. + + Args: + request (~.video_stitcher_service.DeleteSlateRequest): + The request object. Request message for + VideoStitcherService.deleteSlate. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseDeleteSlate._get_http_options() + ) + + request, metadata = self._interceptor.pre_delete_slate(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseDeleteSlate._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseDeleteSlate._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.DeleteSlate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteSlate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._DeleteSlate._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) + + resp = self._interceptor.post_delete_slate(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_delete_slate_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.delete_slate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteSlate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _DeleteVodConfig( + _BaseVideoStitcherServiceRestTransport._BaseDeleteVodConfig, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.DeleteVodConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: video_stitcher_service.DeleteVodConfigRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the delete vod config method over HTTP. + + Args: + request (~.video_stitcher_service.DeleteVodConfigRequest): + The request object. Request message for + VideoStitcherService.deleteVodConfig. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseDeleteVodConfig._get_http_options() + ) + + request, metadata = self._interceptor.pre_delete_vod_config( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseDeleteVodConfig._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseDeleteVodConfig._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.DeleteVodConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteVodConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._DeleteVodConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) - url_match_items = maybe_url_match.groupdict() + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) - host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + # Return the response + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) - super().__init__( - host=host, - credentials=credentials, - client_info=client_info, - always_use_jwt_access=always_use_jwt_access, - api_audience=api_audience, - ) - self._session = AuthorizedSession( - self._credentials, default_host=self.DEFAULT_HOST - ) - if client_cert_source_for_mtls: - self._session.configure_mtls_channel(client_cert_source_for_mtls) - self._interceptor = interceptor or VideoStitcherServiceRestInterceptor() - self._prep_wrapped_messages(client_info) + resp = self._interceptor.post_delete_vod_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_delete_vod_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.delete_vod_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteVodConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp - class _CreateCdnKey(VideoStitcherServiceRestStub): + class _GetCdnKey( + _BaseVideoStitcherServiceRestTransport._BaseGetCdnKey, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("CreateCdnKey") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "cdnKeyId": "", - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetCdnKey") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.CreateCdnKeyRequest, + request: video_stitcher_service.GetCdnKeyRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), ) -> cdn_keys.CdnKey: - r"""Call the create cdn key method over HTTP. + r"""Call the get cdn key method over HTTP. Args: - request (~.video_stitcher_service.CreateCdnKeyRequest): + request (~.video_stitcher_service.GetCdnKeyRequest): The request object. Request message for - VideoStitcherService.createCdnKey. - + VideoStitcherService.getCdnKey. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: ~.cdn_keys.CdnKey: @@ -819,48 +3643,55 @@ def __call__( """ - http_options: List[Dict[str, str]] = [ - { - "method": "post", - "uri": "/v1/{parent=projects/*/locations/*}/cdnKeys", - "body": "cdn_key", - }, - ] - request, metadata = self._interceptor.pre_create_cdn_key(request, metadata) - pb_request = video_stitcher_service.CreateCdnKeyRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetCdnKey._get_http_options() + ) - body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + request, metadata = self._interceptor.pre_get_cdn_key(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetCdnKey._get_transcoded_request( + http_options, request ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetCdnKey._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetCdnKey", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetCdnKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, + response = VideoStitcherServiceRestTransport._GetCdnKey._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -873,93 +3704,149 @@ def __call__( pb_resp = cdn_keys.CdnKey.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_cdn_key(resp) + + resp = self._interceptor.post_get_cdn_key(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_cdn_key_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = cdn_keys.CdnKey.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_cdn_key", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetCdnKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _CreateLiveSession(VideoStitcherServiceRestStub): + class _GetLiveAdTagDetail( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveAdTagDetail, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("CreateLiveSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetLiveAdTagDetail") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.CreateLiveSessionRequest, + request: video_stitcher_service.GetLiveAdTagDetailRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> sessions.LiveSession: - r"""Call the create live session method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> ad_tag_details.LiveAdTagDetail: + r"""Call the get live ad tag detail method over HTTP. Args: - request (~.video_stitcher_service.CreateLiveSessionRequest): + request (~.video_stitcher_service.GetLiveAdTagDetailRequest): The request object. Request message for - VideoStitcherService.createLiveSession. - + VideoStitcherService.getLiveAdTagDetail 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.sessions.LiveSession: - Metadata for a live session. + ~.ad_tag_details.LiveAdTagDetail: + Information related to the details + for one ad tag. This resource is only + available for live sessions that do not + implement Google Ad Manager ad + insertion. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "post", - "uri": "/v1/{parent=projects/*/locations/*}/liveSessions", - "body": "live_session", - }, - ] - request, metadata = self._interceptor.pre_create_live_session( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveAdTagDetail._get_http_options() ) - pb_request = video_stitcher_service.CreateLiveSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + request, metadata = self._interceptor.pre_get_live_ad_tag_detail( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetLiveAdTagDetail._get_transcoded_request( + http_options, request ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetLiveAdTagDetail._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetLiveAdTagDetail", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetLiveAdTagDetail", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, + response = ( + VideoStitcherServiceRestTransport._GetLiveAdTagDetail._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -968,97 +3855,146 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = sessions.LiveSession() - pb_resp = sessions.LiveSession.pb(resp) + resp = ad_tag_details.LiveAdTagDetail() + pb_resp = ad_tag_details.LiveAdTagDetail.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_live_session(resp) + + resp = self._interceptor.post_get_live_ad_tag_detail(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_live_ad_tag_detail_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ad_tag_details.LiveAdTagDetail.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_live_ad_tag_detail", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetLiveAdTagDetail", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _CreateSlate(VideoStitcherServiceRestStub): + class _GetLiveConfig( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveConfig, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("CreateSlate") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "slateId": "", - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetLiveConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.CreateSlateRequest, + request: video_stitcher_service.GetLiveConfigRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> slates.Slate: - r"""Call the create slate method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> live_configs.LiveConfig: + r"""Call the get live config method over HTTP. Args: - request (~.video_stitcher_service.CreateSlateRequest): + request (~.video_stitcher_service.GetLiveConfigRequest): The request object. Request message for - VideoStitcherService.createSlate. - + VideoStitcherService.getLiveConfig. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.slates.Slate: - Slate object - """ + ~.live_configs.LiveConfig: + Metadata for used to register live + configs. - http_options: List[Dict[str, str]] = [ - { - "method": "post", - "uri": "/v1/{parent=projects/*/locations/*}/slates", - "body": "slate", - }, - ] - request, metadata = self._interceptor.pre_create_slate(request, metadata) - pb_request = video_stitcher_service.CreateSlateRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + """ - # Jsonify the request body + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveConfig._get_http_options() + ) - body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + request, metadata = self._interceptor.pre_get_live_config(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetLiveConfig._get_transcoded_request( + http_options, request ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetLiveConfig._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetLiveConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetLiveConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, + response = VideoStitcherServiceRestTransport._GetLiveConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1067,97 +4003,150 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = slates.Slate() - pb_resp = slates.Slate.pb(resp) + resp = live_configs.LiveConfig() + pb_resp = live_configs.LiveConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_slate(resp) + + resp = self._interceptor.post_get_live_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_live_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = live_configs.LiveConfig.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_live_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetLiveConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _CreateVodSession(VideoStitcherServiceRestStub): + class _GetLiveSession( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveSession, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("CreateVodSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetLiveSession") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.CreateVodSessionRequest, + request: video_stitcher_service.GetLiveSessionRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> sessions.VodSession: - r"""Call the create vod session method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> sessions.LiveSession: + r"""Call the get live session method over HTTP. Args: - request (~.video_stitcher_service.CreateVodSessionRequest): + request (~.video_stitcher_service.GetLiveSessionRequest): The request object. Request message for - VideoStitcherService.createVodSession - + VideoStitcherService.getSession. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.sessions.VodSession: - Metadata for a VOD session. + ~.sessions.LiveSession: + Metadata for a live session. The + session expires 5 minutes after the + client stops fetching the session's + playlists. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "post", - "uri": "/v1/{parent=projects/*/locations/*}/vodSessions", - "body": "vod_session", - }, - ] - request, metadata = self._interceptor.pre_create_vod_session( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveSession._get_http_options() ) - pb_request = video_stitcher_service.CreateVodSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - - # Jsonify the request body - body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + request, metadata = self._interceptor.pre_get_live_session( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetLiveSession._get_transcoded_request( + http_options, request ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetLiveSession._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetLiveSession", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetLiveSession", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, + response = VideoStitcherServiceRestTransport._GetLiveSession._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1166,82 +4155,144 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = sessions.VodSession() - pb_resp = sessions.VodSession.pb(resp) + resp = sessions.LiveSession() + pb_resp = sessions.LiveSession.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_create_vod_session(resp) + + resp = self._interceptor.post_get_live_session(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_live_session_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = sessions.LiveSession.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_live_session", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetLiveSession", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _DeleteCdnKey(VideoStitcherServiceRestStub): + class _GetSlate( + _BaseVideoStitcherServiceRestTransport._BaseGetSlate, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("DeleteCdnKey") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetSlate") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.DeleteCdnKeyRequest, + request: video_stitcher_service.GetSlateRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ): - r"""Call the delete cdn key method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> slates.Slate: + r"""Call the get slate method over HTTP. Args: - request (~.video_stitcher_service.DeleteCdnKeyRequest): + request (~.video_stitcher_service.GetSlateRequest): The request object. Request message for - VideoStitcherService.deleteCdnKey. - + VideoStitcherService.getSlate. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.slates.Slate: + Slate object """ - http_options: List[Dict[str, str]] = [ - { - "method": "delete", - "uri": "/v1/{name=projects/*/locations/*/cdnKeys/*}", - }, - ] - request, metadata = self._interceptor.pre_delete_cdn_key(request, metadata) - pb_request = video_stitcher_service.DeleteCdnKeyRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetSlate._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_get_slate(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetSlate._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetSlate._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetSlate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetSlate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._GetSlate._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1249,75 +4300,154 @@ def __call__( if response.status_code >= 400: raise core_exceptions.from_http_response(response) - class _DeleteSlate(VideoStitcherServiceRestStub): - def __hash__(self): - return hash("DeleteSlate") + # Return the response + resp = slates.Slate() + pb_resp = slates.Slate.pb(resp) - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + resp = self._interceptor.post_get_slate(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_slate_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = slates.Slate.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_slate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetSlate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _GetVodAdTagDetail( + _BaseVideoStitcherServiceRestTransport._BaseGetVodAdTagDetail, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.GetVodAdTagDetail") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.DeleteSlateRequest, + request: video_stitcher_service.GetVodAdTagDetailRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ): - r"""Call the delete slate method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> ad_tag_details.VodAdTagDetail: + r"""Call the get vod ad tag detail method over HTTP. Args: - request (~.video_stitcher_service.DeleteSlateRequest): + request (~.video_stitcher_service.GetVodAdTagDetailRequest): The request object. Request message for - VideoStitcherService.deleteSlate. - + VideoStitcherService.getVodAdTagDetail 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + ~.ad_tag_details.VodAdTagDetail: + Information related to the details + for one ad tag. This resource is only + available for VOD sessions that do not + implement Google Ad Manager ad + insertion. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "delete", - "uri": "/v1/{name=projects/*/locations/*/slates/*}", - }, - ] - request, metadata = self._interceptor.pre_delete_slate(request, metadata) - pb_request = video_stitcher_service.DeleteSlateRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetVodAdTagDetail._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_get_vod_ad_tag_detail( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetVodAdTagDetail._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetVodAdTagDetail._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetVodAdTagDetail", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodAdTagDetail", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = ( + VideoStitcherServiceRestTransport._GetVodAdTagDetail._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1325,83 +4455,147 @@ def __call__( if response.status_code >= 400: raise core_exceptions.from_http_response(response) - class _GetCdnKey(VideoStitcherServiceRestStub): - def __hash__(self): - return hash("GetCdnKey") + # Return the response + resp = ad_tag_details.VodAdTagDetail() + pb_resp = ad_tag_details.VodAdTagDetail.pb(resp) - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + resp = self._interceptor.post_get_vod_ad_tag_detail(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_vod_ad_tag_detail_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ad_tag_details.VodAdTagDetail.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_vod_ad_tag_detail", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodAdTagDetail", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) + return resp + + class _GetVodConfig( + _BaseVideoStitcherServiceRestTransport._BaseGetVodConfig, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.GetVodConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetCdnKeyRequest, + request: video_stitcher_service.GetVodConfigRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> cdn_keys.CdnKey: - r"""Call the get cdn key method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> vod_configs.VodConfig: + r"""Call the get vod config method over HTTP. Args: - request (~.video_stitcher_service.GetCdnKeyRequest): + request (~.video_stitcher_service.GetVodConfigRequest): The request object. Request message for - VideoStitcherService.getCdnKey. - + VideoStitcherService.getVodConfig. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.cdn_keys.CdnKey: - Configuration for a CDN key. Used by - the Video Stitcher to sign URIs for - fetching video manifests and signing - media segments for playback. + ~.vod_configs.VodConfig: + Metadata used to register VOD + configs. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/cdnKeys/*}", - }, - ] - request, metadata = self._interceptor.pre_get_cdn_key(request, metadata) - pb_request = video_stitcher_service.GetCdnKeyRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetVodConfig._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_get_vod_config(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetVodConfig._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetVodConfig._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetVodConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._GetVodConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1410,90 +4604,147 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = cdn_keys.CdnKey() - pb_resp = cdn_keys.CdnKey.pb(resp) + resp = vod_configs.VodConfig() + pb_resp = vod_configs.VodConfig.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_cdn_key(resp) + + resp = self._interceptor.post_get_vod_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_vod_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = vod_configs.VodConfig.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_vod_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _GetLiveAdTagDetail(VideoStitcherServiceRestStub): + class _GetVodSession( + _BaseVideoStitcherServiceRestTransport._BaseGetVodSession, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("GetLiveAdTagDetail") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetVodSession") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetLiveAdTagDetailRequest, + request: video_stitcher_service.GetVodSessionRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> ad_tag_details.LiveAdTagDetail: - r"""Call the get live ad tag detail method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> sessions.VodSession: + r"""Call the get vod session method over HTTP. Args: - request (~.video_stitcher_service.GetLiveAdTagDetailRequest): + request (~.video_stitcher_service.GetVodSessionRequest): The request object. Request message for - VideoStitcherService.getLiveAdTagDetail - + VideoStitcherService.getVodSession 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.ad_tag_details.LiveAdTagDetail: - Container for a live session's ad tag - detail. + ~.sessions.VodSession: + Metadata for a VOD session. The + session expires 4 hours after its + creation. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/liveSessions/*/liveAdTagDetails/*}", - }, - ] - request, metadata = self._interceptor.pre_get_live_ad_tag_detail( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetVodSession._get_http_options() ) - pb_request = video_stitcher_service.GetLiveAdTagDetailRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_get_vod_session(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetVodSession._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetVodSession._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetVodSession", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodSession", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._GetVodSession._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1502,88 +4753,153 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = ad_tag_details.LiveAdTagDetail() - pb_resp = ad_tag_details.LiveAdTagDetail.pb(resp) + resp = sessions.VodSession() + pb_resp = sessions.VodSession.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_live_ad_tag_detail(resp) + + resp = self._interceptor.post_get_vod_session(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_vod_session_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = sessions.VodSession.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_vod_session", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodSession", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _GetLiveSession(VideoStitcherServiceRestStub): + class _GetVodStitchDetail( + _BaseVideoStitcherServiceRestTransport._BaseGetVodStitchDetail, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("GetLiveSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.GetVodStitchDetail") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetLiveSessionRequest, + request: video_stitcher_service.GetVodStitchDetailRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> sessions.LiveSession: - r"""Call the get live session method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> stitch_details.VodStitchDetail: + r"""Call the get vod stitch detail method over HTTP. Args: - request (~.video_stitcher_service.GetLiveSessionRequest): + request (~.video_stitcher_service.GetVodStitchDetailRequest): The request object. Request message for - VideoStitcherService.getSession. - + VideoStitcherService.getVodStitchDetail. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.sessions.LiveSession: - Metadata for a live session. + ~.stitch_details.VodStitchDetail: + Information related to the + interstitial of a VOD session. This + resource is only available for VOD + sessions that do not implement Google Ad + Manager ad insertion. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/liveSessions/*}", - }, - ] - request, metadata = self._interceptor.pre_get_live_session( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetVodStitchDetail._get_http_options() ) - pb_request = video_stitcher_service.GetLiveSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_get_vod_stitch_detail( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetVodStitchDetail._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetVodStitchDetail._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetVodStitchDetail", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodStitchDetail", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = ( + VideoStitcherServiceRestTransport._GetVodStitchDetail._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1592,86 +4908,146 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = sessions.LiveSession() - pb_resp = sessions.LiveSession.pb(resp) + resp = stitch_details.VodStitchDetail() + pb_resp = stitch_details.VodStitchDetail.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_live_session(resp) + + resp = self._interceptor.post_get_vod_stitch_detail(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_get_vod_stitch_detail_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = stitch_details.VodStitchDetail.to_json(response) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.get_vod_stitch_detail", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetVodStitchDetail", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _GetSlate(VideoStitcherServiceRestStub): + class _ListCdnKeys( + _BaseVideoStitcherServiceRestTransport._BaseListCdnKeys, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("GetSlate") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListCdnKeys") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetSlateRequest, + request: video_stitcher_service.ListCdnKeysRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> slates.Slate: - r"""Call the get slate method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListCdnKeysResponse: + r"""Call the list cdn keys method over HTTP. Args: - request (~.video_stitcher_service.GetSlateRequest): + request (~.video_stitcher_service.ListCdnKeysRequest): The request object. Request message for - VideoStitcherService.getSlate. - + VideoStitcherService.listCdnKeys. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.slates.Slate: - Slate object + ~.video_stitcher_service.ListCdnKeysResponse: + Response message for + VideoStitcher.ListCdnKeys. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/slates/*}", - }, - ] - request, metadata = self._interceptor.pre_get_slate(request, metadata) - pb_request = video_stitcher_service.GetSlateRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListCdnKeys._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_cdn_keys(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListCdnKeys._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListCdnKeys._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListCdnKeys", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListCdnKeys", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._ListCdnKeys._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1680,90 +5056,152 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = slates.Slate() - pb_resp = slates.Slate.pb(resp) + resp = video_stitcher_service.ListCdnKeysResponse() + pb_resp = video_stitcher_service.ListCdnKeysResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_slate(resp) + + resp = self._interceptor.post_list_cdn_keys(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_cdn_keys_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListCdnKeysResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_cdn_keys", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListCdnKeys", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _GetVodAdTagDetail(VideoStitcherServiceRestStub): + class _ListLiveAdTagDetails( + _BaseVideoStitcherServiceRestTransport._BaseListLiveAdTagDetails, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("GetVodAdTagDetail") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListLiveAdTagDetails") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetVodAdTagDetailRequest, + request: video_stitcher_service.ListLiveAdTagDetailsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> ad_tag_details.VodAdTagDetail: - r"""Call the get vod ad tag detail method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListLiveAdTagDetailsResponse: + r"""Call the list live ad tag details method over HTTP. Args: - request (~.video_stitcher_service.GetVodAdTagDetailRequest): + request (~.video_stitcher_service.ListLiveAdTagDetailsRequest): The request object. Request message for - VideoStitcherService.getVodAdTagDetail - + VideoStitcherService.listLiveAdTagDetails. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.ad_tag_details.VodAdTagDetail: - Information related to the details - for one ad tag. + ~.video_stitcher_service.ListLiveAdTagDetailsResponse: + Response message for + VideoStitcherService.listLiveAdTagDetails. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/vodSessions/*/vodAdTagDetails/*}", - }, - ] - request, metadata = self._interceptor.pre_get_vod_ad_tag_detail( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListLiveAdTagDetails._get_http_options() ) - pb_request = video_stitcher_service.GetVodAdTagDetailRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_live_ad_tag_details( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListLiveAdTagDetails._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListLiveAdTagDetails._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListLiveAdTagDetails", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListLiveAdTagDetails", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = ( + VideoStitcherServiceRestTransport._ListLiveAdTagDetails._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1772,86 +5210,152 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = ad_tag_details.VodAdTagDetail() - pb_resp = ad_tag_details.VodAdTagDetail.pb(resp) + resp = video_stitcher_service.ListLiveAdTagDetailsResponse() + pb_resp = video_stitcher_service.ListLiveAdTagDetailsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_vod_ad_tag_detail(resp) + + resp = self._interceptor.post_list_live_ad_tag_details(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_live_ad_tag_details_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListLiveAdTagDetailsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_live_ad_tag_details", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListLiveAdTagDetails", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _GetVodSession(VideoStitcherServiceRestStub): + class _ListLiveConfigs( + _BaseVideoStitcherServiceRestTransport._BaseListLiveConfigs, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("GetVodSession") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListLiveConfigs") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetVodSessionRequest, + request: video_stitcher_service.ListLiveConfigsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> sessions.VodSession: - r"""Call the get vod session method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListLiveConfigsResponse: + r"""Call the list live configs method over HTTP. Args: - request (~.video_stitcher_service.GetVodSessionRequest): + request (~.video_stitcher_service.ListLiveConfigsRequest): The request object. Request message for - VideoStitcherService.getVodSession - + VideoStitcherService.listLiveConfig. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.sessions.VodSession: - Metadata for a VOD session. + ~.video_stitcher_service.ListLiveConfigsResponse: + Response message for + VideoStitcher.ListLiveConfig. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/vodSessions/*}", - }, - ] - request, metadata = self._interceptor.pre_get_vod_session(request, metadata) - pb_request = video_stitcher_service.GetVodSessionRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListLiveConfigs._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_live_configs( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListLiveConfigs._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListLiveConfigs._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListLiveConfigs", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListLiveConfigs", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._ListLiveConfigs._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1860,90 +5364,148 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = sessions.VodSession() - pb_resp = sessions.VodSession.pb(resp) + resp = video_stitcher_service.ListLiveConfigsResponse() + pb_resp = video_stitcher_service.ListLiveConfigsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_vod_session(resp) + + resp = self._interceptor.post_list_live_configs(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_live_configs_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListLiveConfigsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_live_configs", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListLiveConfigs", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _GetVodStitchDetail(VideoStitcherServiceRestStub): + class _ListSlates( + _BaseVideoStitcherServiceRestTransport._BaseListSlates, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("GetVodStitchDetail") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListSlates") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.GetVodStitchDetailRequest, + request: video_stitcher_service.ListSlatesRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> stitch_details.VodStitchDetail: - r"""Call the get vod stitch detail method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListSlatesResponse: + r"""Call the list slates method over HTTP. Args: - request (~.video_stitcher_service.GetVodStitchDetailRequest): + request (~.video_stitcher_service.ListSlatesRequest): The request object. Request message for - VideoStitcherService.getVodStitchDetail. - + VideoStitcherService.listSlates. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.stitch_details.VodStitchDetail: - Detailed information related to the - interstitial of a VOD session. + ~.video_stitcher_service.ListSlatesResponse: + Response message for + VideoStitcherService.listSlates. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{name=projects/*/locations/*/vodSessions/*/vodStitchDetails/*}", - }, - ] - request, metadata = self._interceptor.pre_get_vod_stitch_detail( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListSlates._get_http_options() ) - pb_request = video_stitcher_service.GetVodStitchDetailRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_slates(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListSlates._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListSlates._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListSlates", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListSlates", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._ListSlates._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -1952,88 +5514,152 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = stitch_details.VodStitchDetail() - pb_resp = stitch_details.VodStitchDetail.pb(resp) + resp = video_stitcher_service.ListSlatesResponse() + pb_resp = video_stitcher_service.ListSlatesResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_get_vod_stitch_detail(resp) + + resp = self._interceptor.post_list_slates(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_slates_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListSlatesResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_slates", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListSlates", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _ListCdnKeys(VideoStitcherServiceRestStub): + class _ListVodAdTagDetails( + _BaseVideoStitcherServiceRestTransport._BaseListVodAdTagDetails, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("ListCdnKeys") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListVodAdTagDetails") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.ListCdnKeysRequest, + request: video_stitcher_service.ListVodAdTagDetailsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> video_stitcher_service.ListCdnKeysResponse: - r"""Call the list cdn keys method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListVodAdTagDetailsResponse: + r"""Call the list vod ad tag details method over HTTP. Args: - request (~.video_stitcher_service.ListCdnKeysRequest): + request (~.video_stitcher_service.ListVodAdTagDetailsRequest): The request object. Request message for - VideoStitcherService.listCdnKeys. - + VideoStitcherService.listVodAdTagDetails. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.video_stitcher_service.ListCdnKeysResponse: + ~.video_stitcher_service.ListVodAdTagDetailsResponse: Response message for - VideoStitcher.ListCdnKeys. + VideoStitcherService.listVodAdTagDetails. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{parent=projects/*/locations/*}/cdnKeys", - }, - ] - request, metadata = self._interceptor.pre_list_cdn_keys(request, metadata) - pb_request = video_stitcher_service.ListCdnKeysRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListVodAdTagDetails._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_vod_ad_tag_details( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListVodAdTagDetails._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListVodAdTagDetails._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListVodAdTagDetails", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListVodAdTagDetails", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = ( + VideoStitcherServiceRestTransport._ListVodAdTagDetails._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2042,90 +5668,152 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = video_stitcher_service.ListCdnKeysResponse() - pb_resp = video_stitcher_service.ListCdnKeysResponse.pb(resp) + resp = video_stitcher_service.ListVodAdTagDetailsResponse() + pb_resp = video_stitcher_service.ListVodAdTagDetailsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_cdn_keys(resp) + + resp = self._interceptor.post_list_vod_ad_tag_details(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_vod_ad_tag_details_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListVodAdTagDetailsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_vod_ad_tag_details", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListVodAdTagDetails", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _ListLiveAdTagDetails(VideoStitcherServiceRestStub): + class _ListVodConfigs( + _BaseVideoStitcherServiceRestTransport._BaseListVodConfigs, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("ListLiveAdTagDetails") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListVodConfigs") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.ListLiveAdTagDetailsRequest, + request: video_stitcher_service.ListVodConfigsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> video_stitcher_service.ListLiveAdTagDetailsResponse: - r"""Call the list live ad tag details method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListVodConfigsResponse: + r"""Call the list vod configs method over HTTP. Args: - request (~.video_stitcher_service.ListLiveAdTagDetailsRequest): + request (~.video_stitcher_service.ListVodConfigsRequest): The request object. Request message for - VideoStitcherService.listLiveAdTagDetails. - + VideoStitcherService.listVodConfig. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.video_stitcher_service.ListLiveAdTagDetailsResponse: + ~.video_stitcher_service.ListVodConfigsResponse: Response message for - VideoStitcherService.listLiveAdTagDetails. + VideoStitcher.ListVodConfig. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{parent=projects/*/locations/*/liveSessions/*}/liveAdTagDetails", - }, - ] - request, metadata = self._interceptor.pre_list_live_ad_tag_details( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListVodConfigs._get_http_options() ) - pb_request = video_stitcher_service.ListLiveAdTagDetailsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_vod_configs( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListVodConfigs._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListVodConfigs._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListVodConfigs", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListVodConfigs", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._ListVodConfigs._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2134,88 +5822,152 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = video_stitcher_service.ListLiveAdTagDetailsResponse() - pb_resp = video_stitcher_service.ListLiveAdTagDetailsResponse.pb(resp) + resp = video_stitcher_service.ListVodConfigsResponse() + pb_resp = video_stitcher_service.ListVodConfigsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_live_ad_tag_details(resp) + + resp = self._interceptor.post_list_vod_configs(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_vod_configs_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListVodConfigsResponse.to_json(response) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_vod_configs", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListVodConfigs", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _ListSlates(VideoStitcherServiceRestStub): + class _ListVodStitchDetails( + _BaseVideoStitcherServiceRestTransport._BaseListVodStitchDetails, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("ListSlates") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.ListVodStitchDetails") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response def __call__( self, - request: video_stitcher_service.ListSlatesRequest, + request: video_stitcher_service.ListVodStitchDetailsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> video_stitcher_service.ListSlatesResponse: - r"""Call the list slates method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> video_stitcher_service.ListVodStitchDetailsResponse: + r"""Call the list vod stitch details method over HTTP. Args: - request (~.video_stitcher_service.ListSlatesRequest): + request (~.video_stitcher_service.ListVodStitchDetailsRequest): The request object. Request message for - VideoStitcherService.listSlates. - + VideoStitcherService.listVodStitchDetails. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.video_stitcher_service.ListSlatesResponse: + ~.video_stitcher_service.ListVodStitchDetailsResponse: Response message for - VideoStitcherService.listSlates. + VideoStitcherService.listVodStitchDetails. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{parent=projects/*/locations/*}/slates", - }, - ] - request, metadata = self._interceptor.pre_list_slates(request, metadata) - pb_request = video_stitcher_service.ListSlatesRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListVodStitchDetails._get_http_options() + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_list_vod_stitch_details( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListVodStitchDetails._get_transcoded_request( + http_options, request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseListVodStitchDetails._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = type(request).to_json(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListVodStitchDetails", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListVodStitchDetails", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = ( + VideoStitcherServiceRestTransport._ListVodStitchDetails._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2224,90 +5976,157 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = video_stitcher_service.ListSlatesResponse() - pb_resp = video_stitcher_service.ListSlatesResponse.pb(resp) + resp = video_stitcher_service.ListVodStitchDetailsResponse() + pb_resp = video_stitcher_service.ListVodStitchDetailsResponse.pb(resp) json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_slates(resp) + + resp = self._interceptor.post_list_vod_stitch_details(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_list_vod_stitch_details_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = ( + video_stitcher_service.ListVodStitchDetailsResponse.to_json( + response + ) + ) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.list_vod_stitch_details", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListVodStitchDetails", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _ListVodAdTagDetails(VideoStitcherServiceRestStub): + class _UpdateCdnKey( + _BaseVideoStitcherServiceRestTransport._BaseUpdateCdnKey, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("ListVodAdTagDetails") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.UpdateCdnKey") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response def __call__( self, - request: video_stitcher_service.ListVodAdTagDetailsRequest, + request: video_stitcher_service.UpdateCdnKeyRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> video_stitcher_service.ListVodAdTagDetailsResponse: - r"""Call the list vod ad tag details method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the update cdn key method over HTTP. Args: - request (~.video_stitcher_service.ListVodAdTagDetailsRequest): + request (~.video_stitcher_service.UpdateCdnKeyRequest): The request object. Request message for - VideoStitcherService.listVodAdTagDetails. - + VideoStitcherService.updateCdnKey. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.video_stitcher_service.ListVodAdTagDetailsResponse: - Response message for - VideoStitcherService.listVodAdTagDetails. + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{parent=projects/*/locations/*/vodSessions/*}/vodAdTagDetails", - }, - ] - request, metadata = self._interceptor.pre_list_vod_ad_tag_details( - request, metadata + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseUpdateCdnKey._get_http_options() ) - pb_request = video_stitcher_service.ListVodAdTagDetailsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + request, metadata = self._interceptor.pre_update_cdn_key(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseUpdateCdnKey._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseUpdateCdnKey._get_request_body_json( + transcoded_request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseUpdateCdnKey._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.UpdateCdnKey", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateCdnKey", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = VideoStitcherServiceRestTransport._UpdateCdnKey._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2316,90 +6135,155 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = video_stitcher_service.ListVodAdTagDetailsResponse() - pb_resp = video_stitcher_service.ListVodAdTagDetailsResponse.pb(resp) + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_vod_ad_tag_details(resp) + resp = self._interceptor.post_update_cdn_key(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_cdn_key_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.update_cdn_key", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateCdnKey", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _ListVodStitchDetails(VideoStitcherServiceRestStub): + class _UpdateLiveConfig( + _BaseVideoStitcherServiceRestTransport._BaseUpdateLiveConfig, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("ListVodStitchDetails") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.UpdateLiveConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response def __call__( self, - request: video_stitcher_service.ListVodStitchDetailsRequest, + request: video_stitcher_service.UpdateLiveConfigRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> video_stitcher_service.ListVodStitchDetailsResponse: - r"""Call the list vod stitch details method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the update live config method over HTTP. Args: - request (~.video_stitcher_service.ListVodStitchDetailsRequest): + request (~.video_stitcher_service.UpdateLiveConfigRequest): The request object. Request message for - VideoStitcherService.listVodStitchDetails. - + VideoStitcherService.updateLiveConfig. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.video_stitcher_service.ListVodStitchDetailsResponse: - Response message for - VideoStitcherService.listVodStitchDetails. + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. """ - http_options: List[Dict[str, str]] = [ - { - "method": "get", - "uri": "/v1/{parent=projects/*/locations/*/vodSessions/*}/vodStitchDetails", - }, - ] - request, metadata = self._interceptor.pre_list_vod_stitch_details( + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseUpdateLiveConfig._get_http_options() + ) + + request, metadata = self._interceptor.pre_update_live_config( request, metadata ) - pb_request = video_stitcher_service.ListVodStitchDetailsRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseUpdateLiveConfig._get_transcoded_request( + http_options, request + ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] + body = _BaseVideoStitcherServiceRestTransport._BaseUpdateLiveConfig._get_request_body_json( + transcoded_request + ) # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseUpdateLiveConfig._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.UpdateLiveConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateLiveConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), + response = ( + VideoStitcherServiceRestTransport._UpdateLiveConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2408,101 +6292,151 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = video_stitcher_service.ListVodStitchDetailsResponse() - pb_resp = video_stitcher_service.ListVodStitchDetailsResponse.pb(resp) + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_list_vod_stitch_details(resp) + resp = self._interceptor.post_update_live_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_live_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.update_live_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateLiveConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _UpdateCdnKey(VideoStitcherServiceRestStub): + class _UpdateSlate( + _BaseVideoStitcherServiceRestTransport._BaseUpdateSlate, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("UpdateCdnKey") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "updateMask": {}, - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.UpdateSlate") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response def __call__( self, - request: video_stitcher_service.UpdateCdnKeyRequest, + request: video_stitcher_service.UpdateSlateRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> cdn_keys.CdnKey: - r"""Call the update cdn key method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the update slate method over HTTP. Args: - request (~.video_stitcher_service.UpdateCdnKeyRequest): + request (~.video_stitcher_service.UpdateSlateRequest): The request object. Request message for - VideoStitcherService.updateCdnKey. - + VideoStitcherService.updateSlate. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.cdn_keys.CdnKey: - Configuration for a CDN key. Used by - the Video Stitcher to sign URIs for - fetching video manifests and signing - media segments for playback. + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. """ - http_options: List[Dict[str, str]] = [ - { - "method": "patch", - "uri": "/v1/{cdn_key.name=projects/*/locations/*/cdnKeys/*}", - "body": "cdn_key", - }, - ] - request, metadata = self._interceptor.pre_update_cdn_key(request, metadata) - pb_request = video_stitcher_service.UpdateCdnKeyRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseUpdateSlate._get_http_options() + ) - # Jsonify the request body + request, metadata = self._interceptor.pre_update_slate(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseUpdateSlate._get_transcoded_request( + http_options, request + ) - body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + body = _BaseVideoStitcherServiceRestTransport._BaseUpdateSlate._get_request_body_json( + transcoded_request ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseUpdateSlate._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.UpdateSlate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateSlate", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, + response = VideoStitcherServiceRestTransport._UpdateSlate._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2511,97 +6445,153 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = cdn_keys.CdnKey() - pb_resp = cdn_keys.CdnKey.pb(resp) + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_cdn_key(resp) + resp = self._interceptor.post_update_slate(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_slate_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.update_slate", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateSlate", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp - class _UpdateSlate(VideoStitcherServiceRestStub): + class _UpdateVodConfig( + _BaseVideoStitcherServiceRestTransport._BaseUpdateVodConfig, + VideoStitcherServiceRestStub, + ): def __hash__(self): - return hash("UpdateSlate") - - __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { - "updateMask": {}, - } - - @classmethod - def _get_unset_required_fields(cls, message_dict): - return { - k: v - for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() - if k not in message_dict - } + return hash("VideoStitcherServiceRestTransport.UpdateVodConfig") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response def __call__( self, - request: video_stitcher_service.UpdateSlateRequest, + request: video_stitcher_service.UpdateVodConfigRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, - metadata: Sequence[Tuple[str, str]] = (), - ) -> slates.Slate: - r"""Call the update slate method over HTTP. + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the update vod config method over HTTP. Args: - request (~.video_stitcher_service.UpdateSlateRequest): + request (~.video_stitcher_service.UpdateVodConfigRequest): The request object. Request message for - VideoStitcherService.updateSlate. - + VideoStitcherService.updateVodConfig. 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. + metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. Returns: - ~.slates.Slate: - Slate object + ~.operations_pb2.Operation: + This resource represents a + long-running operation that is the + result of a network API call. + """ - http_options: List[Dict[str, str]] = [ - { - "method": "patch", - "uri": "/v1/{slate.name=projects/*/locations/*/slates/*}", - "body": "slate", - }, - ] - request, metadata = self._interceptor.pre_update_slate(request, metadata) - pb_request = video_stitcher_service.UpdateSlateRequest.pb(request) - transcoded_request = path_template.transcode(http_options, pb_request) + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseUpdateVodConfig._get_http_options() + ) - # Jsonify the request body + request, metadata = self._interceptor.pre_update_vod_config( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseUpdateVodConfig._get_transcoded_request( + http_options, request + ) - body = json_format.MessageToJson( - transcoded_request["body"], - including_default_value_fields=False, - use_integers_for_enums=True, + body = _BaseVideoStitcherServiceRestTransport._BaseUpdateVodConfig._get_request_body_json( + transcoded_request ) - uri = transcoded_request["uri"] - method = transcoded_request["method"] # Jsonify the query params - query_params = json.loads( - json_format.MessageToJson( - transcoded_request["query_params"], - including_default_value_fields=False, - use_integers_for_enums=True, - ) + query_params = _BaseVideoStitcherServiceRestTransport._BaseUpdateVodConfig._get_query_params_json( + transcoded_request ) - query_params.update(self._get_unset_required_fields(query_params)) - query_params["$alt"] = "json;enum-encoding=int" + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.UpdateVodConfig", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateVodConfig", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) # Send the request - headers = dict(metadata) - headers["Content-Type"] = "application/json" - response = getattr(self._session, method)( - "{host}{uri}".format(host=self._host, uri=uri), - timeout=timeout, - headers=headers, - params=rest_helpers.flatten_query_params(query_params, strict=True), - data=body, + response = VideoStitcherServiceRestTransport._UpdateVodConfig._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception @@ -2610,21 +6600,57 @@ def __call__( raise core_exceptions.from_http_response(response) # Return the response - resp = slates.Slate() - pb_resp = slates.Slate.pb(resp) + resp = operations_pb2.Operation() + json_format.Parse(response.content, resp, ignore_unknown_fields=True) - json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True) - resp = self._interceptor.post_update_slate(resp) + resp = self._interceptor.post_update_vod_config(resp) + response_metadata = [(k, str(v)) for k, v in response.headers.items()] + resp, _ = self._interceptor.post_update_vod_config_with_metadata( + resp, response_metadata + ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.update_vod_config", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "UpdateVodConfig", + "metadata": http_response["headers"], + "httpResponse": http_response, + }, + ) return resp @property def create_cdn_key( self, - ) -> Callable[[video_stitcher_service.CreateCdnKeyRequest], cdn_keys.CdnKey]: + ) -> Callable[ + [video_stitcher_service.CreateCdnKeyRequest], operations_pb2.Operation + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast return self._CreateCdnKey(self._session, self._host, self._interceptor) # type: ignore + @property + def create_live_config( + self, + ) -> Callable[ + [video_stitcher_service.CreateLiveConfigRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateLiveConfig(self._session, self._host, self._interceptor) # type: ignore + @property def create_live_session( self, @@ -2638,10 +6664,22 @@ def create_live_session( @property def create_slate( self, - ) -> Callable[[video_stitcher_service.CreateSlateRequest], slates.Slate]: + ) -> Callable[ + [video_stitcher_service.CreateSlateRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._CreateSlate(self._session, self._host, self._interceptor) # type: ignore + + @property + def create_vod_config( + self, + ) -> Callable[ + [video_stitcher_service.CreateVodConfigRequest], operations_pb2.Operation + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast - return self._CreateSlate(self._session, self._host, self._interceptor) # type: ignore + return self._CreateVodConfig(self._session, self._host, self._interceptor) # type: ignore @property def create_vod_session( @@ -2656,19 +6694,43 @@ def create_vod_session( @property def delete_cdn_key( self, - ) -> Callable[[video_stitcher_service.DeleteCdnKeyRequest], empty_pb2.Empty]: + ) -> Callable[ + [video_stitcher_service.DeleteCdnKeyRequest], operations_pb2.Operation + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast return self._DeleteCdnKey(self._session, self._host, self._interceptor) # type: ignore + @property + def delete_live_config( + self, + ) -> Callable[ + [video_stitcher_service.DeleteLiveConfigRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteLiveConfig(self._session, self._host, self._interceptor) # type: ignore + @property def delete_slate( self, - ) -> Callable[[video_stitcher_service.DeleteSlateRequest], empty_pb2.Empty]: + ) -> Callable[ + [video_stitcher_service.DeleteSlateRequest], operations_pb2.Operation + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast return self._DeleteSlate(self._session, self._host, self._interceptor) # type: ignore + @property + def delete_vod_config( + self, + ) -> Callable[ + [video_stitcher_service.DeleteVodConfigRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._DeleteVodConfig(self._session, self._host, self._interceptor) # type: ignore + @property def get_cdn_key( self, @@ -2688,6 +6750,16 @@ def get_live_ad_tag_detail( # In C++ this would require a dynamic_cast return self._GetLiveAdTagDetail(self._session, self._host, self._interceptor) # type: ignore + @property + def get_live_config( + self, + ) -> Callable[ + [video_stitcher_service.GetLiveConfigRequest], live_configs.LiveConfig + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetLiveConfig(self._session, self._host, self._interceptor) # type: ignore + @property def get_live_session( self, @@ -2714,6 +6786,14 @@ def get_vod_ad_tag_detail( # In C++ this would require a dynamic_cast return self._GetVodAdTagDetail(self._session, self._host, self._interceptor) # type: ignore + @property + def get_vod_config( + self, + ) -> Callable[[video_stitcher_service.GetVodConfigRequest], vod_configs.VodConfig]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._GetVodConfig(self._session, self._host, self._interceptor) # type: ignore + @property def get_vod_session( self, @@ -2755,6 +6835,17 @@ def list_live_ad_tag_details( # In C++ this would require a dynamic_cast return self._ListLiveAdTagDetails(self._session, self._host, self._interceptor) # type: ignore + @property + def list_live_configs( + self, + ) -> Callable[ + [video_stitcher_service.ListLiveConfigsRequest], + video_stitcher_service.ListLiveConfigsResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListLiveConfigs(self._session, self._host, self._interceptor) # type: ignore + @property def list_slates( self, @@ -2777,6 +6868,17 @@ def list_vod_ad_tag_details( # In C++ this would require a dynamic_cast return self._ListVodAdTagDetails(self._session, self._host, self._interceptor) # type: ignore + @property + def list_vod_configs( + self, + ) -> Callable[ + [video_stitcher_service.ListVodConfigsRequest], + video_stitcher_service.ListVodConfigsResponse, + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._ListVodConfigs(self._session, self._host, self._interceptor) # type: ignore + @property def list_vod_stitch_details( self, @@ -2791,19 +6893,561 @@ def list_vod_stitch_details( @property def update_cdn_key( self, - ) -> Callable[[video_stitcher_service.UpdateCdnKeyRequest], cdn_keys.CdnKey]: + ) -> Callable[ + [video_stitcher_service.UpdateCdnKeyRequest], operations_pb2.Operation + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast return self._UpdateCdnKey(self._session, self._host, self._interceptor) # type: ignore + @property + def update_live_config( + self, + ) -> Callable[ + [video_stitcher_service.UpdateLiveConfigRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateLiveConfig(self._session, self._host, self._interceptor) # type: ignore + @property def update_slate( self, - ) -> Callable[[video_stitcher_service.UpdateSlateRequest], slates.Slate]: + ) -> Callable[ + [video_stitcher_service.UpdateSlateRequest], operations_pb2.Operation + ]: # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. # In C++ this would require a dynamic_cast return self._UpdateSlate(self._session, self._host, self._interceptor) # type: ignore + @property + def update_vod_config( + self, + ) -> Callable[ + [video_stitcher_service.UpdateVodConfigRequest], operations_pb2.Operation + ]: + # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here. + # In C++ this would require a dynamic_cast + return self._UpdateVodConfig(self._session, self._host, self._interceptor) # type: ignore + + @property + def cancel_operation(self): + return self._CancelOperation(self._session, self._host, self._interceptor) # type: ignore + + class _CancelOperation( + _BaseVideoStitcherServiceRestTransport._BaseCancelOperation, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.CancelOperation") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + data=body, + ) + return response + + def __call__( + self, + request: operations_pb2.CancelOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: + r"""Call the cancel operation method over HTTP. + + Args: + request (operations_pb2.CancelOperationRequest): + The request object for CancelOperation method. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseCancelOperation._get_http_options() + ) + + request, metadata = self._interceptor.pre_cancel_operation( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseCancelOperation._get_transcoded_request( + http_options, request + ) + + body = _BaseVideoStitcherServiceRestTransport._BaseCancelOperation._get_request_body_json( + transcoded_request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseCancelOperation._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.CancelOperation", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "CancelOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._CancelOperation._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + body, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_cancel_operation(None) + + @property + def delete_operation(self): + return self._DeleteOperation(self._session, self._host, self._interceptor) # type: ignore + + class _DeleteOperation( + _BaseVideoStitcherServiceRestTransport._BaseDeleteOperation, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.DeleteOperation") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: operations_pb2.DeleteOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> None: + r"""Call the delete operation method over HTTP. + + Args: + request (operations_pb2.DeleteOperationRequest): + The request object for DeleteOperation method. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseDeleteOperation._get_http_options() + ) + + request, metadata = self._interceptor.pre_delete_operation( + request, metadata + ) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseDeleteOperation._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseDeleteOperation._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.DeleteOperation", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "DeleteOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._DeleteOperation._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + return self._interceptor.post_delete_operation(None) + + @property + def get_operation(self): + return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore + + class _GetOperation( + _BaseVideoStitcherServiceRestTransport._BaseGetOperation, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.GetOperation") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: operations_pb2.GetOperationRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.Operation: + r"""Call the get operation method over HTTP. + + Args: + request (operations_pb2.GetOperationRequest): + The request object for GetOperation method. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + operations_pb2.Operation: Response from GetOperation method. + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseGetOperation._get_http_options() + ) + + request, metadata = self._interceptor.pre_get_operation(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseGetOperation._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseGetOperation._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.GetOperation", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetOperation", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._GetOperation._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + content = response.content.decode("utf-8") + resp = operations_pb2.Operation() + resp = json_format.Parse(content, resp) + resp = self._interceptor.post_get_operation(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceAsyncClient.GetOperation", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "GetOperation", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) + return resp + + @property + def list_operations(self): + return self._ListOperations(self._session, self._host, self._interceptor) # type: ignore + + class _ListOperations( + _BaseVideoStitcherServiceRestTransport._BaseListOperations, + VideoStitcherServiceRestStub, + ): + def __hash__(self): + return hash("VideoStitcherServiceRestTransport.ListOperations") + + @staticmethod + def _get_response( + host, + metadata, + query_params, + session, + timeout, + transcoded_request, + body=None, + ): + uri = transcoded_request["uri"] + method = transcoded_request["method"] + headers = dict(metadata) + headers["Content-Type"] = "application/json" + response = getattr(session, method)( + "{host}{uri}".format(host=host, uri=uri), + timeout=timeout, + headers=headers, + params=rest_helpers.flatten_query_params(query_params, strict=True), + ) + return response + + def __call__( + self, + request: operations_pb2.ListOperationsRequest, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Optional[float] = None, + metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Call the list operations method over HTTP. + + Args: + request (operations_pb2.ListOperationsRequest): + The request object for ListOperations method. + 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, Union[str, bytes]]]): Key/value pairs which should be + sent along with the request as metadata. Normally, each value must be of type `str`, + but for metadata keys ending with the suffix `-bin`, the corresponding values must + be of type `bytes`. + + Returns: + operations_pb2.ListOperationsResponse: Response from ListOperations method. + """ + + http_options = ( + _BaseVideoStitcherServiceRestTransport._BaseListOperations._get_http_options() + ) + + request, metadata = self._interceptor.pre_list_operations(request, metadata) + transcoded_request = _BaseVideoStitcherServiceRestTransport._BaseListOperations._get_transcoded_request( + http_options, request + ) + + # Jsonify the query params + query_params = _BaseVideoStitcherServiceRestTransport._BaseListOperations._get_query_params_json( + transcoded_request + ) + + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + request_url = "{host}{uri}".format( + host=self._host, uri=transcoded_request["uri"] + ) + method = transcoded_request["method"] + try: + request_payload = json_format.MessageToJson(request) + except: + request_payload = None + http_request = { + "payload": request_payload, + "requestMethod": method, + "requestUrl": request_url, + "headers": dict(metadata), + } + _LOGGER.debug( + f"Sending request for google.cloud.video.stitcher_v1.VideoStitcherServiceClient.ListOperations", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListOperations", + "httpRequest": http_request, + "metadata": http_request["headers"], + }, + ) + + # Send the request + response = VideoStitcherServiceRestTransport._ListOperations._get_response( + self._host, + metadata, + query_params, + self._session, + timeout, + transcoded_request, + ) + + # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception + # subclass. + if response.status_code >= 400: + raise core_exceptions.from_http_response(response) + + content = response.content.decode("utf-8") + resp = operations_pb2.ListOperationsResponse() + resp = json_format.Parse(content, resp) + resp = self._interceptor.post_list_operations(resp) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( + logging.DEBUG + ): # pragma: NO COVER + try: + response_payload = json_format.MessageToJson(resp) + except: + response_payload = None + http_response = { + "payload": response_payload, + "headers": dict(response.headers), + "status": response.status_code, + } + _LOGGER.debug( + "Received response for google.cloud.video.stitcher_v1.VideoStitcherServiceAsyncClient.ListOperations", + extra={ + "serviceName": "google.cloud.video.stitcher.v1.VideoStitcherService", + "rpcName": "ListOperations", + "httpResponse": http_response, + "metadata": http_response["headers"], + }, + ) + return resp + @property def kind(self) -> str: return "rest" diff --git a/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest_base.py b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest_base.py new file mode 100644 index 000000000000..07f32682b8a0 --- /dev/null +++ b/packages/google-cloud-video-stitcher/google/cloud/video/stitcher_v1/services/video_stitcher_service/transports/rest_base.py @@ -0,0 +1,1733 @@ +# -*- coding: utf-8 -*- +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import json # type: ignore +import re +from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1, path_template +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import json_format + +from google.cloud.video.stitcher_v1.types import ( + ad_tag_details, + cdn_keys, + live_configs, + sessions, + slates, + stitch_details, + video_stitcher_service, + vod_configs, +) + +from .base import DEFAULT_CLIENT_INFO, VideoStitcherServiceTransport + + +class _BaseVideoStitcherServiceRestTransport(VideoStitcherServiceTransport): + """Base REST backend transport for VideoStitcherService. + + Note: This class is not meant to be used directly. Use its sync and + async sub-classes instead. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends JSON representations of protocol buffers over HTTP/1.1 + """ + + def __init__( + self, + *, + host: str = "videostitcher.googleapis.com", + credentials: Optional[Any] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + url_scheme: str = "https", + api_audience: Optional[str] = None, + ) -> None: + """Instantiate the transport. + Args: + host (Optional[str]): + The hostname to connect to (default: 'videostitcher.googleapis.com'). + credentials (Optional[Any]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you are developing + your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + url_scheme: the protocol scheme for the API endpoint. Normally + "https", but for testing or local servers, + "http" can be specified. + """ + # Run the base constructor + maybe_url_match = re.match("^(?Phttp(?:s)?://)?(?P.*)$", host) + if maybe_url_match is None: + raise ValueError( + f"Unexpected hostname structure: {host}" + ) # pragma: NO COVER + + url_match_items = maybe_url_match.groupdict() + + host = f"{url_scheme}://{host}" if not url_match_items["scheme"] else host + + super().__init__( + host=host, + credentials=credentials, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + api_audience=api_audience, + ) + + class _BaseCreateCdnKey: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "cdnKeyId": "", + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/cdnKeys", + "body": "cdn_key", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.CreateCdnKeyRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseCreateCdnKey._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseCreateLiveConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "liveConfigId": "", + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/liveConfigs", + "body": "live_config", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.CreateLiveConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseCreateLiveConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseCreateLiveSession: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/liveSessions", + "body": "live_session", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.CreateLiveSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseCreateLiveSession._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseCreateSlate: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "slateId": "", + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/slates", + "body": "slate", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.CreateSlateRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseCreateSlate._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseCreateVodConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "vodConfigId": "", + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/vodConfigs", + "body": "vod_config", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.CreateVodConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseCreateVodConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseCreateVodSession: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{parent=projects/*/locations/*}/vodSessions", + "body": "vod_session", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.CreateVodSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseCreateVodSession._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseDeleteCdnKey: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/cdnKeys/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.DeleteCdnKeyRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseDeleteCdnKey._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseDeleteLiveConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/liveConfigs/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.DeleteLiveConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseDeleteLiveConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseDeleteSlate: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/slates/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.DeleteSlateRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseDeleteSlate._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseDeleteVodConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/vodConfigs/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.DeleteVodConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseDeleteVodConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetCdnKey: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/cdnKeys/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetCdnKeyRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetCdnKey._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetLiveAdTagDetail: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/liveSessions/*/liveAdTagDetails/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetLiveAdTagDetailRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveAdTagDetail._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetLiveConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/liveConfigs/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetLiveConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetLiveSession: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/liveSessions/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetLiveSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetLiveSession._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetSlate: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/slates/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetSlateRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetSlate._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetVodAdTagDetail: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/vodSessions/*/vodAdTagDetails/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetVodAdTagDetailRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetVodAdTagDetail._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetVodConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/vodConfigs/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetVodConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetVodConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetVodSession: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/vodSessions/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetVodSessionRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetVodSession._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseGetVodStitchDetail: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/vodSessions/*/vodStitchDetails/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.GetVodStitchDetailRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseGetVodStitchDetail._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListCdnKeys: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*}/cdnKeys", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListCdnKeysRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListCdnKeys._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListLiveAdTagDetails: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*/liveSessions/*}/liveAdTagDetails", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListLiveAdTagDetailsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListLiveAdTagDetails._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListLiveConfigs: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*}/liveConfigs", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListLiveConfigsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListLiveConfigs._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListSlates: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*}/slates", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListSlatesRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListSlates._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListVodAdTagDetails: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*/vodSessions/*}/vodAdTagDetails", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListVodAdTagDetailsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListVodAdTagDetails._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListVodConfigs: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*}/vodConfigs", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListVodConfigsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListVodConfigs._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseListVodStitchDetails: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = {} + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{parent=projects/*/locations/*/vodSessions/*}/vodStitchDetails", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.ListVodStitchDetailsRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseListVodStitchDetails._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseUpdateCdnKey: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{cdn_key.name=projects/*/locations/*/cdnKeys/*}", + "body": "cdn_key", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.UpdateCdnKeyRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseUpdateCdnKey._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseUpdateLiveConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{live_config.name=projects/*/locations/*/liveConfigs/*}", + "body": "live_config", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.UpdateLiveConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseUpdateLiveConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseUpdateSlate: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{slate.name=projects/*/locations/*/slates/*}", + "body": "slate", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.UpdateSlateRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseUpdateSlate._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseUpdateVodConfig: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + __REQUIRED_FIELDS_DEFAULT_VALUES: Dict[str, Any] = { + "updateMask": {}, + } + + @classmethod + def _get_unset_required_fields(cls, message_dict): + return { + k: v + for k, v in cls.__REQUIRED_FIELDS_DEFAULT_VALUES.items() + if k not in message_dict + } + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "patch", + "uri": "/v1/{vod_config.name=projects/*/locations/*/vodConfigs/*}", + "body": "vod_config", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + pb_request = video_stitcher_service.UpdateVodConfigRequest.pb(request) + transcoded_request = path_template.transcode(http_options, pb_request) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + # Jsonify the request body + + body = json_format.MessageToJson( + transcoded_request["body"], use_integers_for_enums=True + ) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=True, + ) + ) + query_params.update( + _BaseVideoStitcherServiceRestTransport._BaseUpdateVodConfig._get_unset_required_fields( + query_params + ) + ) + + query_params["$alt"] = "json;enum-encoding=int" + return query_params + + class _BaseCancelOperation: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "post", + "uri": "/v1/{name=projects/*/locations/*/operations/*}:cancel", + "body": "*", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + return transcoded_request + + @staticmethod + def _get_request_body_json(transcoded_request): + body = json.dumps(transcoded_request["body"]) + return body + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + return query_params + + class _BaseDeleteOperation: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "delete", + "uri": "/v1/{name=projects/*/locations/*/operations/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + return query_params + + class _BaseGetOperation: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*/operations/*}", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + return query_params + + class _BaseListOperations: + def __hash__(self): # pragma: NO COVER + return NotImplementedError("__hash__ must be implemented.") + + @staticmethod + def _get_http_options(): + http_options: List[Dict[str, str]] = [ + { + "method": "get", + "uri": "/v1/{name=projects/*/locations/*}/operations", + }, + ] + return http_options + + @staticmethod + def _get_transcoded_request(http_options, request): + request_kwargs = json_format.MessageToDict(request) + transcoded_request = path_template.transcode(http_options, **request_kwargs) + return transcoded_request + + @staticmethod + def _get_query_params_json(transcoded_request): + query_params = json.loads(json.dumps(transcoded_request["query_params"])) + return query_params + + +__all__ = ("_BaseVideoStitcherServiceRestTransport",) diff --git a/packages/google-cloud-video-stitcher/tests/unit/gapic/stitcher_v1/test_video_stitcher_service.py b/packages/google-cloud-video-stitcher/tests/unit/gapic/stitcher_v1/test_video_stitcher_service.py index 4fb50afc18a3..7d4d501b4aa2 100644 --- a/packages/google-cloud-video-stitcher/tests/unit/gapic/stitcher_v1/test_video_stitcher_service.py +++ b/packages/google-cloud-video-stitcher/tests/unit/gapic/stitcher_v1/test_video_stitcher_service.py @@ -22,15 +22,19 @@ except ImportError: # pragma: NO COVER import mock +from collections.abc import AsyncIterable, Iterable import json import math from google.api_core import api_core_version +from google.protobuf import json_format import grpc from grpc.experimental import aio from proto.marshal.rules import wrappers from proto.marshal.rules.dates import DurationRule, TimestampRule import pytest +from requests import PreparedRequest, Request, Response +from requests.sessions import Session try: from google.auth.aio import credentials as ga_credentials_async @@ -409,6 +413,7 @@ def test__add_cred_info_for_auth_errors_no_get_cred_info(error_code): [ (VideoStitcherServiceClient, "grpc"), (VideoStitcherServiceAsyncClient, "grpc_asyncio"), + (VideoStitcherServiceClient, "rest"), ], ) def test_video_stitcher_service_client_from_service_account_info( @@ -424,7 +429,11 @@ def test_video_stitcher_service_client_from_service_account_info( assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == ("videostitcher.googleapis.com:443") + assert client.transport._host == ( + "videostitcher.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://videostitcher.googleapis.com" + ) @pytest.mark.parametrize( @@ -432,6 +441,7 @@ def test_video_stitcher_service_client_from_service_account_info( [ (transports.VideoStitcherServiceGrpcTransport, "grpc"), (transports.VideoStitcherServiceGrpcAsyncIOTransport, "grpc_asyncio"), + (transports.VideoStitcherServiceRestTransport, "rest"), ], ) def test_video_stitcher_service_client_service_account_always_use_jwt( @@ -457,6 +467,7 @@ def test_video_stitcher_service_client_service_account_always_use_jwt( [ (VideoStitcherServiceClient, "grpc"), (VideoStitcherServiceAsyncClient, "grpc_asyncio"), + (VideoStitcherServiceClient, "rest"), ], ) def test_video_stitcher_service_client_from_service_account_file( @@ -479,13 +490,18 @@ def test_video_stitcher_service_client_from_service_account_file( assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == ("videostitcher.googleapis.com:443") + assert client.transport._host == ( + "videostitcher.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://videostitcher.googleapis.com" + ) def test_video_stitcher_service_client_get_transport_class(): transport = VideoStitcherServiceClient.get_transport_class() available_transports = [ transports.VideoStitcherServiceGrpcTransport, + transports.VideoStitcherServiceRestTransport, ] assert transport in available_transports @@ -506,6 +522,11 @@ def test_video_stitcher_service_client_get_transport_class(): transports.VideoStitcherServiceGrpcAsyncIOTransport, "grpc_asyncio", ), + ( + VideoStitcherServiceClient, + transports.VideoStitcherServiceRestTransport, + "rest", + ), ], ) @mock.patch.object( @@ -675,6 +696,18 @@ def test_video_stitcher_service_client_client_options( "grpc_asyncio", "false", ), + ( + VideoStitcherServiceClient, + transports.VideoStitcherServiceRestTransport, + "rest", + "true", + ), + ( + VideoStitcherServiceClient, + transports.VideoStitcherServiceRestTransport, + "rest", + "false", + ), ], ) @mock.patch.object( @@ -993,6 +1026,11 @@ def test_video_stitcher_service_client_client_api_endpoint(client_class): transports.VideoStitcherServiceGrpcAsyncIOTransport, "grpc_asyncio", ), + ( + VideoStitcherServiceClient, + transports.VideoStitcherServiceRestTransport, + "rest", + ), ], ) def test_video_stitcher_service_client_client_options_scopes( @@ -1035,6 +1073,12 @@ def test_video_stitcher_service_client_client_options_scopes( "grpc_asyncio", grpc_helpers_async, ), + ( + VideoStitcherServiceClient, + transports.VideoStitcherServiceRestTransport, + "rest", + None, + ), ], ) def test_video_stitcher_service_client_client_options_credentials_file( @@ -12892,801 +12936,12905 @@ async def test_update_vod_config_flattened_error_async(): ) -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.VideoStitcherServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): +def test_create_cdn_key_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport=transport, + transport="rest", ) - # It is an error to provide a credentials file and a transport instance. - transport = transports.VideoStitcherServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = VideoStitcherServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() - # It is an error to provide an api_key and a transport instance. - transport = transports.VideoStitcherServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = VideoStitcherServiceClient( - client_options=options, - transport=transport, - ) + # Ensure method has been cached + assert client._transport.create_cdn_key in client._transport._wrapped_methods - # It is an error to provide an api_key and a credential. - options = client_options.ClientOptions() - options.api_key = "api_key" - with pytest.raises(ValueError): - client = VideoStitcherServiceClient( - client_options=options, credentials=ga_credentials.AnonymousCredentials() + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. ) + client._transport._wrapped_methods[client._transport.create_cdn_key] = mock_rpc - # It is an error to provide scopes and a transport instance. - transport = transports.VideoStitcherServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = VideoStitcherServiceClient( - client_options={"scopes": ["1", "2"]}, - transport=transport, - ) + request = {} + client.create_cdn_key(request) + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.VideoStitcherServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = VideoStitcherServiceClient(transport=transport) - assert client.transport is transport + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + client.create_cdn_key(request) -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.VideoStitcherServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 - transport = transports.VideoStitcherServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel +def test_create_cdn_key_rest_required_fields( + request_type=video_stitcher_service.CreateCdnKeyRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport -@pytest.mark.parametrize( - "transport_class", - [ - transports.VideoStitcherServiceGrpcTransport, - transports.VideoStitcherServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + request_init = {} + request_init["parent"] = "" + request_init["cdn_key_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + # verify fields with default values are dropped + assert "cdnKeyId" not in jsonified_request -def test_transport_kind_grpc(): - transport = VideoStitcherServiceClient.get_transport_class("grpc")( + unset_fields = transport_class( credentials=ga_credentials.AnonymousCredentials() - ) - assert transport.kind == "grpc" + ).create_cdn_key._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + # verify required fields with default values are now present + assert "cdnKeyId" in jsonified_request + assert jsonified_request["cdnKeyId"] == request_init["cdn_key_id"] -def test_initialize_client_w_grpc(): - client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc" - ) - assert client is not None + jsonified_request["parent"] = "parent_value" + jsonified_request["cdnKeyId"] = "cdn_key_id_value" + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_cdn_key._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("cdn_key_id",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "cdnKeyId" in jsonified_request + assert jsonified_request["cdnKeyId"] == "cdn_key_id_value" -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_cdn_key_empty_call_grpc(): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_cdn_key), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_cdn_key(request=None) + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.CreateCdnKeyRequest() + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) - assert args[0] == request_msg + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_cdn_key(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_cdn_keys_empty_call_grpc(): - client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + expected_params = [ + ( + "cdnKeyId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_cdn_keys), "__call__") as call: - call.return_value = video_stitcher_service.ListCdnKeysResponse() - client.list_cdn_keys(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListCdnKeysRequest() +def test_create_cdn_key_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) - assert args[0] == request_msg + unset_fields = transport.create_cdn_key._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("cdnKeyId",)) + & set( + ( + "parent", + "cdnKey", + "cdnKeyId", + ) + ) + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_cdn_key_empty_call_grpc(): +def test_create_cdn_key_rest_flattened(): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_cdn_key), "__call__") as call: - call.return_value = cdn_keys.CdnKey() - client.get_cdn_key(request=None) + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetCdnKeyRequest() + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} - assert args[0] == request_msg + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + cdn_key=cdn_keys.CdnKey( + google_cdn_key=cdn_keys.GoogleCdnKey(private_key=b"private_key_blob") + ), + cdn_key_id="cdn_key_id_value", + ) + mock_args.update(sample_request) + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_cdn_key_empty_call_grpc(): + client.create_cdn_key(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/cdnKeys" % client.transport._host, + args[1], + ) + + +def test_create_cdn_key_rest_flattened_error(transport: str = "rest"): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport=transport, ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_cdn_key), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_cdn_key(request=None) + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_cdn_key( + video_stitcher_service.CreateCdnKeyRequest(), + parent="parent_value", + cdn_key=cdn_keys.CdnKey( + google_cdn_key=cdn_keys.GoogleCdnKey(private_key=b"private_key_blob") + ), + cdn_key_id="cdn_key_id_value", + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.DeleteCdnKeyRequest() - assert args[0] == request_msg +def test_list_cdn_keys_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_cdn_key_empty_call_grpc(): - client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + # Ensure method has been cached + assert client._transport.list_cdn_keys in client._transport._wrapped_methods - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_cdn_key), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_cdn_key(request=None) + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.list_cdn_keys] = mock_rpc - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.UpdateCdnKeyRequest() + request = {} + client.list_cdn_keys(request) - assert args[0] == request_msg + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_cdn_keys(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_cdn_keys_rest_required_fields( + request_type=video_stitcher_service.ListCdnKeysRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_cdn_keys._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_cdn_keys._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListCdnKeysResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListCdnKeysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_cdn_keys(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_cdn_keys_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_cdn_keys._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_cdn_keys_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListCdnKeysResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListCdnKeysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_cdn_keys(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/cdnKeys" % client.transport._host, + args[1], + ) + + +def test_list_cdn_keys_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_cdn_keys( + video_stitcher_service.ListCdnKeysRequest(), + parent="parent_value", + ) + + +def test_list_cdn_keys_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListCdnKeysResponse( + cdn_keys=[ + cdn_keys.CdnKey(), + cdn_keys.CdnKey(), + cdn_keys.CdnKey(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListCdnKeysResponse( + cdn_keys=[], + next_page_token="def", + ), + video_stitcher_service.ListCdnKeysResponse( + cdn_keys=[ + cdn_keys.CdnKey(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListCdnKeysResponse( + cdn_keys=[ + cdn_keys.CdnKey(), + cdn_keys.CdnKey(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListCdnKeysResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_cdn_keys(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, cdn_keys.CdnKey) for i in results) + + pages = list(client.list_cdn_keys(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_cdn_key_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_cdn_key in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_cdn_key] = mock_rpc + + request = {} + client.get_cdn_key(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_cdn_key(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_cdn_key_rest_required_fields( + request_type=video_stitcher_service.GetCdnKeyRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_cdn_key._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_cdn_key._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = cdn_keys.CdnKey() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = cdn_keys.CdnKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_cdn_key(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_cdn_key_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_cdn_key._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_cdn_key_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = cdn_keys.CdnKey() + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = cdn_keys.CdnKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_cdn_key(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/cdnKeys/*}" % client.transport._host, + args[1], + ) + + +def test_get_cdn_key_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_cdn_key( + video_stitcher_service.GetCdnKeyRequest(), + name="name_value", + ) + + +def test_delete_cdn_key_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_cdn_key in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.delete_cdn_key] = mock_rpc + + request = {} + client.delete_cdn_key(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_cdn_key(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_cdn_key_rest_required_fields( + request_type=video_stitcher_service.DeleteCdnKeyRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_cdn_key._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_cdn_key._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_cdn_key(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_cdn_key_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_cdn_key._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_delete_cdn_key_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_cdn_key(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/cdnKeys/*}" % client.transport._host, + args[1], + ) + + +def test_delete_cdn_key_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_cdn_key( + video_stitcher_service.DeleteCdnKeyRequest(), + name="name_value", + ) + + +def test_update_cdn_key_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_cdn_key in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.update_cdn_key] = mock_rpc + + request = {} + client.update_cdn_key(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_cdn_key(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_update_cdn_key_rest_required_fields( + request_type=video_stitcher_service.UpdateCdnKeyRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_cdn_key._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_cdn_key._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_cdn_key(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_update_cdn_key_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.update_cdn_key._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("updateMask",)) + & set( + ( + "cdnKey", + "updateMask", + ) + ) + ) + + +def test_update_cdn_key_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "cdn_key": {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + } + + # get truthy value for each flattened field + mock_args = dict( + cdn_key=cdn_keys.CdnKey( + google_cdn_key=cdn_keys.GoogleCdnKey(private_key=b"private_key_blob") + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_cdn_key(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{cdn_key.name=projects/*/locations/*/cdnKeys/*}" + % client.transport._host, + args[1], + ) + + +def test_update_cdn_key_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_cdn_key( + video_stitcher_service.UpdateCdnKeyRequest(), + cdn_key=cdn_keys.CdnKey( + google_cdn_key=cdn_keys.GoogleCdnKey(private_key=b"private_key_blob") + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_create_vod_session_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_vod_session in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_vod_session + ] = mock_rpc + + request = {} + client.create_vod_session(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.create_vod_session(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_create_vod_session_rest_required_fields( + request_type=video_stitcher_service.CreateVodSessionRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_vod_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_vod_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = sessions.VodSession() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.VodSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.create_vod_session(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_vod_session_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_vod_session._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "vodSession", + ) + ) + ) + + +def test_create_vod_session_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.VodSession() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + vod_session=sessions.VodSession(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = sessions.VodSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_vod_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/vodSessions" + % client.transport._host, + args[1], + ) + + +def test_create_vod_session_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_vod_session( + video_stitcher_service.CreateVodSessionRequest(), + parent="parent_value", + vod_session=sessions.VodSession(name="name_value"), + ) + + +def test_get_vod_session_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_vod_session in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_vod_session] = mock_rpc + + request = {} + client.get_vod_session(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_vod_session(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_vod_session_rest_required_fields( + request_type=video_stitcher_service.GetVodSessionRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = sessions.VodSession() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.VodSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_vod_session(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_vod_session_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_vod_session._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_vod_session_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.VodSession() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = sessions.VodSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_vod_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/vodSessions/*}" + % client.transport._host, + args[1], + ) + + +def test_get_vod_session_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_vod_session( + video_stitcher_service.GetVodSessionRequest(), + name="name_value", + ) + + +def test_list_vod_stitch_details_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_vod_stitch_details + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_vod_stitch_details + ] = mock_rpc + + request = {} + client.list_vod_stitch_details(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_vod_stitch_details(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_vod_stitch_details_rest_required_fields( + request_type=video_stitcher_service.ListVodStitchDetailsRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_vod_stitch_details._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_vod_stitch_details._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodStitchDetailsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodStitchDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_vod_stitch_details(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_vod_stitch_details_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_vod_stitch_details._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_vod_stitch_details_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodStitchDetailsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "projects/sample1/locations/sample2/vodSessions/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodStitchDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_vod_stitch_details(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*/vodSessions/*}/vodStitchDetails" + % client.transport._host, + args[1], + ) + + +def test_list_vod_stitch_details_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_vod_stitch_details( + video_stitcher_service.ListVodStitchDetailsRequest(), + parent="parent_value", + ) + + +def test_list_vod_stitch_details_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListVodStitchDetailsResponse( + vod_stitch_details=[ + stitch_details.VodStitchDetail(), + stitch_details.VodStitchDetail(), + stitch_details.VodStitchDetail(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListVodStitchDetailsResponse( + vod_stitch_details=[], + next_page_token="def", + ), + video_stitcher_service.ListVodStitchDetailsResponse( + vod_stitch_details=[ + stitch_details.VodStitchDetail(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListVodStitchDetailsResponse( + vod_stitch_details=[ + stitch_details.VodStitchDetail(), + stitch_details.VodStitchDetail(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListVodStitchDetailsResponse.to_json(x) + for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = { + "parent": "projects/sample1/locations/sample2/vodSessions/sample3" + } + + pager = client.list_vod_stitch_details(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, stitch_details.VodStitchDetail) for i in results) + + pages = list(client.list_vod_stitch_details(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_vod_stitch_detail_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_vod_stitch_detail + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_vod_stitch_detail + ] = mock_rpc + + request = {} + client.get_vod_stitch_detail(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_vod_stitch_detail(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_vod_stitch_detail_rest_required_fields( + request_type=video_stitcher_service.GetVodStitchDetailRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_stitch_detail._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_stitch_detail._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = stitch_details.VodStitchDetail() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = stitch_details.VodStitchDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_vod_stitch_detail(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_vod_stitch_detail_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_vod_stitch_detail._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_vod_stitch_detail_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = stitch_details.VodStitchDetail() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3/vodStitchDetails/sample4" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = stitch_details.VodStitchDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_vod_stitch_detail(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/vodSessions/*/vodStitchDetails/*}" + % client.transport._host, + args[1], + ) + + +def test_get_vod_stitch_detail_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_vod_stitch_detail( + video_stitcher_service.GetVodStitchDetailRequest(), + name="name_value", + ) + + +def test_list_vod_ad_tag_details_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_vod_ad_tag_details + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_vod_ad_tag_details + ] = mock_rpc + + request = {} + client.list_vod_ad_tag_details(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_vod_ad_tag_details(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_vod_ad_tag_details_rest_required_fields( + request_type=video_stitcher_service.ListVodAdTagDetailsRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_vod_ad_tag_details._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_vod_ad_tag_details._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodAdTagDetailsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodAdTagDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_vod_ad_tag_details(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_vod_ad_tag_details_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_vod_ad_tag_details._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_vod_ad_tag_details_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodAdTagDetailsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "projects/sample1/locations/sample2/vodSessions/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodAdTagDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_vod_ad_tag_details(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*/vodSessions/*}/vodAdTagDetails" + % client.transport._host, + args[1], + ) + + +def test_list_vod_ad_tag_details_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_vod_ad_tag_details( + video_stitcher_service.ListVodAdTagDetailsRequest(), + parent="parent_value", + ) + + +def test_list_vod_ad_tag_details_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListVodAdTagDetailsResponse( + vod_ad_tag_details=[ + ad_tag_details.VodAdTagDetail(), + ad_tag_details.VodAdTagDetail(), + ad_tag_details.VodAdTagDetail(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListVodAdTagDetailsResponse( + vod_ad_tag_details=[], + next_page_token="def", + ), + video_stitcher_service.ListVodAdTagDetailsResponse( + vod_ad_tag_details=[ + ad_tag_details.VodAdTagDetail(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListVodAdTagDetailsResponse( + vod_ad_tag_details=[ + ad_tag_details.VodAdTagDetail(), + ad_tag_details.VodAdTagDetail(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListVodAdTagDetailsResponse.to_json(x) + for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = { + "parent": "projects/sample1/locations/sample2/vodSessions/sample3" + } + + pager = client.list_vod_ad_tag_details(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, ad_tag_details.VodAdTagDetail) for i in results) + + pages = list(client.list_vod_ad_tag_details(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_vod_ad_tag_detail_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_vod_ad_tag_detail + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_vod_ad_tag_detail + ] = mock_rpc + + request = {} + client.get_vod_ad_tag_detail(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_vod_ad_tag_detail(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_vod_ad_tag_detail_rest_required_fields( + request_type=video_stitcher_service.GetVodAdTagDetailRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_ad_tag_detail._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_ad_tag_detail._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = ad_tag_details.VodAdTagDetail() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = ad_tag_details.VodAdTagDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_vod_ad_tag_detail(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_vod_ad_tag_detail_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_vod_ad_tag_detail._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_vod_ad_tag_detail_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = ad_tag_details.VodAdTagDetail() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3/vodAdTagDetails/sample4" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = ad_tag_details.VodAdTagDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_vod_ad_tag_detail(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/vodSessions/*/vodAdTagDetails/*}" + % client.transport._host, + args[1], + ) + + +def test_get_vod_ad_tag_detail_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_vod_ad_tag_detail( + video_stitcher_service.GetVodAdTagDetailRequest(), + name="name_value", + ) + + +def test_list_live_ad_tag_details_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.list_live_ad_tag_details + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_live_ad_tag_details + ] = mock_rpc + + request = {} + client.list_live_ad_tag_details(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_live_ad_tag_details(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_live_ad_tag_details_rest_required_fields( + request_type=video_stitcher_service.ListLiveAdTagDetailsRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_live_ad_tag_details._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_live_ad_tag_details._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_live_ad_tag_details(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_live_ad_tag_details_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_live_ad_tag_details._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_live_ad_tag_details_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = { + "parent": "projects/sample1/locations/sample2/liveSessions/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_live_ad_tag_details(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*/liveSessions/*}/liveAdTagDetails" + % client.transport._host, + args[1], + ) + + +def test_list_live_ad_tag_details_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_live_ad_tag_details( + video_stitcher_service.ListLiveAdTagDetailsRequest(), + parent="parent_value", + ) + + +def test_list_live_ad_tag_details_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListLiveAdTagDetailsResponse( + live_ad_tag_details=[ + ad_tag_details.LiveAdTagDetail(), + ad_tag_details.LiveAdTagDetail(), + ad_tag_details.LiveAdTagDetail(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListLiveAdTagDetailsResponse( + live_ad_tag_details=[], + next_page_token="def", + ), + video_stitcher_service.ListLiveAdTagDetailsResponse( + live_ad_tag_details=[ + ad_tag_details.LiveAdTagDetail(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListLiveAdTagDetailsResponse( + live_ad_tag_details=[ + ad_tag_details.LiveAdTagDetail(), + ad_tag_details.LiveAdTagDetail(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListLiveAdTagDetailsResponse.to_json(x) + for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = { + "parent": "projects/sample1/locations/sample2/liveSessions/sample3" + } + + pager = client.list_live_ad_tag_details(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, ad_tag_details.LiveAdTagDetail) for i in results) + + pages = list(client.list_live_ad_tag_details(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_live_ad_tag_detail_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.get_live_ad_tag_detail + in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_live_ad_tag_detail + ] = mock_rpc + + request = {} + client.get_live_ad_tag_detail(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_live_ad_tag_detail(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_live_ad_tag_detail_rest_required_fields( + request_type=video_stitcher_service.GetLiveAdTagDetailRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_live_ad_tag_detail._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_live_ad_tag_detail._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = ad_tag_details.LiveAdTagDetail() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = ad_tag_details.LiveAdTagDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_live_ad_tag_detail(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_live_ad_tag_detail_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_live_ad_tag_detail._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_live_ad_tag_detail_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = ad_tag_details.LiveAdTagDetail() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/liveSessions/sample3/liveAdTagDetails/sample4" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = ad_tag_details.LiveAdTagDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_live_ad_tag_detail(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/liveSessions/*/liveAdTagDetails/*}" + % client.transport._host, + args[1], + ) + + +def test_get_live_ad_tag_detail_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_live_ad_tag_detail( + video_stitcher_service.GetLiveAdTagDetailRequest(), + name="name_value", + ) + + +def test_create_slate_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.create_slate in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.create_slate] = mock_rpc + + request = {} + client.create_slate(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_slate(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_create_slate_rest_required_fields( + request_type=video_stitcher_service.CreateSlateRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["slate_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + assert "slateId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_slate._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "slateId" in jsonified_request + assert jsonified_request["slateId"] == request_init["slate_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["slateId"] = "slate_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_slate._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "request_id", + "slate_id", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "slateId" in jsonified_request + assert jsonified_request["slateId"] == "slate_id_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.create_slate(request) + + expected_params = [ + ( + "slateId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_slate_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_slate._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "requestId", + "slateId", + ) + ) + & set( + ( + "parent", + "slateId", + "slate", + ) + ) + ) + + +def test_create_slate_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + slate=slates.Slate(name="name_value"), + slate_id="slate_id_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_slate(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/slates" % client.transport._host, + args[1], + ) + + +def test_create_slate_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_slate( + video_stitcher_service.CreateSlateRequest(), + parent="parent_value", + slate=slates.Slate(name="name_value"), + slate_id="slate_id_value", + ) + + +def test_list_slates_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_slates in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.list_slates] = mock_rpc + + request = {} + client.list_slates(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_slates(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_slates_rest_required_fields( + request_type=video_stitcher_service.ListSlatesRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_slates._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_slates._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListSlatesResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListSlatesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_slates(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_slates_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_slates._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_slates_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListSlatesResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListSlatesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_slates(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/slates" % client.transport._host, + args[1], + ) + + +def test_list_slates_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_slates( + video_stitcher_service.ListSlatesRequest(), + parent="parent_value", + ) + + +def test_list_slates_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListSlatesResponse( + slates=[ + slates.Slate(), + slates.Slate(), + slates.Slate(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListSlatesResponse( + slates=[], + next_page_token="def", + ), + video_stitcher_service.ListSlatesResponse( + slates=[ + slates.Slate(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListSlatesResponse( + slates=[ + slates.Slate(), + slates.Slate(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListSlatesResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_slates(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, slates.Slate) for i in results) + + pages = list(client.list_slates(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_slate_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_slate in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_slate] = mock_rpc + + request = {} + client.get_slate(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_slate(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_slate_rest_required_fields( + request_type=video_stitcher_service.GetSlateRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_slate._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_slate._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = slates.Slate() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = slates.Slate.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_slate(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_slate_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_slate._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_slate_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = slates.Slate() + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "projects/sample1/locations/sample2/slates/sample3"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = slates.Slate.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_slate(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/slates/*}" % client.transport._host, + args[1], + ) + + +def test_get_slate_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_slate( + video_stitcher_service.GetSlateRequest(), + name="name_value", + ) + + +def test_update_slate_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_slate in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.update_slate] = mock_rpc + + request = {} + client.update_slate(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_slate(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_update_slate_rest_required_fields( + request_type=video_stitcher_service.UpdateSlateRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_slate._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_slate._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_slate(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_update_slate_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.update_slate._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("updateMask",)) + & set( + ( + "slate", + "updateMask", + ) + ) + ) + + +def test_update_slate_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "slate": {"name": "projects/sample1/locations/sample2/slates/sample3"} + } + + # get truthy value for each flattened field + mock_args = dict( + slate=slates.Slate(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_slate(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{slate.name=projects/*/locations/*/slates/*}" + % client.transport._host, + args[1], + ) + + +def test_update_slate_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_slate( + video_stitcher_service.UpdateSlateRequest(), + slate=slates.Slate(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_delete_slate_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_slate in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.delete_slate] = mock_rpc + + request = {} + client.delete_slate(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_slate(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_slate_rest_required_fields( + request_type=video_stitcher_service.DeleteSlateRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_slate._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_slate._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_slate(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_slate_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_slate._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_delete_slate_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"name": "projects/sample1/locations/sample2/slates/sample3"} + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_slate(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/slates/*}" % client.transport._host, + args[1], + ) + + +def test_delete_slate_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_slate( + video_stitcher_service.DeleteSlateRequest(), + name="name_value", + ) + + +def test_create_live_session_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_live_session in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_live_session + ] = mock_rpc + + request = {} + client.create_live_session(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.create_live_session(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_create_live_session_rest_required_fields( + request_type=video_stitcher_service.CreateLiveSessionRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_live_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_live_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = sessions.LiveSession() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.LiveSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.create_live_session(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_live_session_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_live_session._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(()) + & set( + ( + "parent", + "liveSession", + ) + ) + ) + + +def test_create_live_session_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.LiveSession() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + live_session=sessions.LiveSession(name="name_value"), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = sessions.LiveSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_live_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/liveSessions" + % client.transport._host, + args[1], + ) + + +def test_create_live_session_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_live_session( + video_stitcher_service.CreateLiveSessionRequest(), + parent="parent_value", + live_session=sessions.LiveSession(name="name_value"), + ) + + +def test_get_live_session_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_live_session in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.get_live_session + ] = mock_rpc + + request = {} + client.get_live_session(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_live_session(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_live_session_rest_required_fields( + request_type=video_stitcher_service.GetLiveSessionRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_live_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_live_session._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = sessions.LiveSession() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.LiveSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_live_session(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_live_session_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_live_session._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_live_session_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.LiveSession() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/liveSessions/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = sessions.LiveSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_live_session(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/liveSessions/*}" + % client.transport._host, + args[1], + ) + + +def test_get_live_session_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_live_session( + video_stitcher_service.GetLiveSessionRequest(), + name="name_value", + ) + + +def test_create_live_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.create_live_config in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_live_config + ] = mock_rpc + + request = {} + client.create_live_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_live_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_create_live_config_rest_required_fields( + request_type=video_stitcher_service.CreateLiveConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["live_config_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + assert "liveConfigId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_live_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "liveConfigId" in jsonified_request + assert jsonified_request["liveConfigId"] == request_init["live_config_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["liveConfigId"] = "live_config_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_live_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "live_config_id", + "request_id", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "liveConfigId" in jsonified_request + assert jsonified_request["liveConfigId"] == "live_config_id_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.create_live_config(request) + + expected_params = [ + ( + "liveConfigId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_live_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_live_config._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "liveConfigId", + "requestId", + ) + ) + & set( + ( + "parent", + "liveConfigId", + "liveConfig", + ) + ) + ) + + +def test_create_live_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + live_config=live_configs.LiveConfig(name="name_value"), + live_config_id="live_config_id_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_live_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/liveConfigs" + % client.transport._host, + args[1], + ) + + +def test_create_live_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_live_config( + video_stitcher_service.CreateLiveConfigRequest(), + parent="parent_value", + live_config=live_configs.LiveConfig(name="name_value"), + live_config_id="live_config_id_value", + ) + + +def test_list_live_configs_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_live_configs in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_live_configs + ] = mock_rpc + + request = {} + client.list_live_configs(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_live_configs(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_live_configs_rest_required_fields( + request_type=video_stitcher_service.ListLiveConfigsRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_live_configs._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_live_configs._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListLiveConfigsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListLiveConfigsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_live_configs(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_live_configs_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_live_configs._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_live_configs_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListLiveConfigsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListLiveConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_live_configs(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/liveConfigs" + % client.transport._host, + args[1], + ) + + +def test_list_live_configs_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_live_configs( + video_stitcher_service.ListLiveConfigsRequest(), + parent="parent_value", + ) + + +def test_list_live_configs_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListLiveConfigsResponse( + live_configs=[ + live_configs.LiveConfig(), + live_configs.LiveConfig(), + live_configs.LiveConfig(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListLiveConfigsResponse( + live_configs=[], + next_page_token="def", + ), + video_stitcher_service.ListLiveConfigsResponse( + live_configs=[ + live_configs.LiveConfig(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListLiveConfigsResponse( + live_configs=[ + live_configs.LiveConfig(), + live_configs.LiveConfig(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListLiveConfigsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_live_configs(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, live_configs.LiveConfig) for i in results) + + pages = list(client.list_live_configs(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_live_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_live_config in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_live_config] = mock_rpc + + request = {} + client.get_live_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_live_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_live_config_rest_required_fields( + request_type=video_stitcher_service.GetLiveConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_live_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_live_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = live_configs.LiveConfig() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = live_configs.LiveConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_live_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_live_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_live_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_live_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = live_configs.LiveConfig() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/liveConfigs/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = live_configs.LiveConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_live_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/liveConfigs/*}" + % client.transport._host, + args[1], + ) + + +def test_get_live_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_live_config( + video_stitcher_service.GetLiveConfigRequest(), + name="name_value", + ) + + +def test_delete_live_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.delete_live_config in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_live_config + ] = mock_rpc + + request = {} + client.delete_live_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_live_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_live_config_rest_required_fields( + request_type=video_stitcher_service.DeleteLiveConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_live_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_live_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_live_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_live_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_live_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_delete_live_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/liveConfigs/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_live_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/liveConfigs/*}" + % client.transport._host, + args[1], + ) + + +def test_delete_live_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_live_config( + video_stitcher_service.DeleteLiveConfigRequest(), + name="name_value", + ) + + +def test_update_live_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.update_live_config in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_live_config + ] = mock_rpc + + request = {} + client.update_live_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_live_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_update_live_config_rest_required_fields( + request_type=video_stitcher_service.UpdateLiveConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_live_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_live_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_live_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_update_live_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.update_live_config._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("updateMask",)) + & set( + ( + "liveConfig", + "updateMask", + ) + ) + ) + + +def test_update_live_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "live_config": { + "name": "projects/sample1/locations/sample2/liveConfigs/sample3" + } + } + + # get truthy value for each flattened field + mock_args = dict( + live_config=live_configs.LiveConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_live_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{live_config.name=projects/*/locations/*/liveConfigs/*}" + % client.transport._host, + args[1], + ) + + +def test_update_live_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_live_config( + video_stitcher_service.UpdateLiveConfigRequest(), + live_config=live_configs.LiveConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_create_vod_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.create_vod_config in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.create_vod_config + ] = mock_rpc + + request = {} + client.create_vod_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.create_vod_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_create_vod_config_rest_required_fields( + request_type=video_stitcher_service.CreateVodConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request_init["vod_config_id"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + assert "vodConfigId" not in jsonified_request + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_vod_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + assert "vodConfigId" in jsonified_request + assert jsonified_request["vodConfigId"] == request_init["vod_config_id"] + + jsonified_request["parent"] = "parent_value" + jsonified_request["vodConfigId"] = "vod_config_id_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).create_vod_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "request_id", + "vod_config_id", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + assert "vodConfigId" in jsonified_request + assert jsonified_request["vodConfigId"] == "vod_config_id_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "post", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.create_vod_config(request) + + expected_params = [ + ( + "vodConfigId", + "", + ), + ("$alt", "json;enum-encoding=int"), + ] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_create_vod_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.create_vod_config._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "requestId", + "vodConfigId", + ) + ) + & set( + ( + "parent", + "vodConfigId", + "vodConfig", + ) + ) + ) + + +def test_create_vod_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + vod_config=vod_configs.VodConfig(name="name_value"), + vod_config_id="vod_config_id_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.create_vod_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/vodConfigs" % client.transport._host, + args[1], + ) + + +def test_create_vod_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_vod_config( + video_stitcher_service.CreateVodConfigRequest(), + parent="parent_value", + vod_config=vod_configs.VodConfig(name="name_value"), + vod_config_id="vod_config_id_value", + ) + + +def test_list_vod_configs_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_vod_configs in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_vod_configs + ] = mock_rpc + + request = {} + client.list_vod_configs(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_vod_configs(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_list_vod_configs_rest_required_fields( + request_type=video_stitcher_service.ListVodConfigsRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["parent"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_vod_configs._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["parent"] = "parent_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).list_vod_configs._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set( + ( + "filter", + "order_by", + "page_size", + "page_token", + ) + ) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "parent" in jsonified_request + assert jsonified_request["parent"] == "parent_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodConfigsResponse() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodConfigsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.list_vod_configs(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_list_vod_configs_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.list_vod_configs._get_unset_required_fields({}) + assert set(unset_fields) == ( + set( + ( + "filter", + "orderBy", + "pageSize", + "pageToken", + ) + ) + & set(("parent",)) + ) + + +def test_list_vod_configs_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodConfigsResponse() + + # get arguments that satisfy an http rule for this method + sample_request = {"parent": "projects/sample1/locations/sample2"} + + # get truthy value for each flattened field + mock_args = dict( + parent="parent_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.list_vod_configs(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{parent=projects/*/locations/*}/vodConfigs" % client.transport._host, + args[1], + ) + + +def test_list_vod_configs_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_vod_configs( + video_stitcher_service.ListVodConfigsRequest(), + parent="parent_value", + ) + + +def test_list_vod_configs_rest_pager(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # TODO(kbandes): remove this mock unless there's a good reason for it. + # with mock.patch.object(path_template, 'transcode') as transcode: + # Set the response as a series of pages + response = ( + video_stitcher_service.ListVodConfigsResponse( + vod_configs=[ + vod_configs.VodConfig(), + vod_configs.VodConfig(), + vod_configs.VodConfig(), + ], + next_page_token="abc", + ), + video_stitcher_service.ListVodConfigsResponse( + vod_configs=[], + next_page_token="def", + ), + video_stitcher_service.ListVodConfigsResponse( + vod_configs=[ + vod_configs.VodConfig(), + ], + next_page_token="ghi", + ), + video_stitcher_service.ListVodConfigsResponse( + vod_configs=[ + vod_configs.VodConfig(), + vod_configs.VodConfig(), + ], + ), + ) + # Two responses for two calls + response = response + response + + # Wrap the values into proper Response objs + response = tuple( + video_stitcher_service.ListVodConfigsResponse.to_json(x) for x in response + ) + return_values = tuple(Response() for i in response) + for return_val, response_val in zip(return_values, response): + return_val._content = response_val.encode("UTF-8") + return_val.status_code = 200 + req.side_effect = return_values + + sample_request = {"parent": "projects/sample1/locations/sample2"} + + pager = client.list_vod_configs(request=sample_request) + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, vod_configs.VodConfig) for i in results) + + pages = list(client.list_vod_configs(request=sample_request).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_get_vod_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.get_vod_config in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[client._transport.get_vod_config] = mock_rpc + + request = {} + client.get_vod_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.get_vod_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_get_vod_config_rest_required_fields( + request_type=video_stitcher_service.GetVodConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).get_vod_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = vod_configs.VodConfig() + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "get", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = vod_configs.VodConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.get_vod_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_get_vod_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.get_vod_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_get_vod_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = vod_configs.VodConfig() + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/vodConfigs/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = vod_configs.VodConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.get_vod_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/vodConfigs/*}" % client.transport._host, + args[1], + ) + + +def test_get_vod_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_vod_config( + video_stitcher_service.GetVodConfigRequest(), + name="name_value", + ) + + +def test_delete_vod_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.delete_vod_config in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.delete_vod_config + ] = mock_rpc + + request = {} + client.delete_vod_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.delete_vod_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_delete_vod_config_rest_required_fields( + request_type=video_stitcher_service.DeleteVodConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request_init["name"] = "" + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_vod_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + jsonified_request["name"] = "name_value" + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).delete_vod_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + assert "name" in jsonified_request + assert jsonified_request["name"] == "name_value" + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "delete", + "query_params": pb_request, + } + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.delete_vod_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_delete_vod_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.delete_vod_config._get_unset_required_fields({}) + assert set(unset_fields) == (set(()) & set(("name",))) + + +def test_delete_vod_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "name": "projects/sample1/locations/sample2/vodConfigs/sample3" + } + + # get truthy value for each flattened field + mock_args = dict( + name="name_value", + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.delete_vod_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{name=projects/*/locations/*/vodConfigs/*}" % client.transport._host, + args[1], + ) + + +def test_delete_vod_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_vod_config( + video_stitcher_service.DeleteVodConfigRequest(), + name="name_value", + ) + + +def test_update_vod_config_rest_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.update_vod_config in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.update_vod_config + ] = mock_rpc + + request = {} + client.update_vod_config(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + # Operation methods build a cached wrapper on first rpc call + # subsequent calls should use the cached wrapper + wrapper_fn.reset_mock() + + client.update_vod_config(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +def test_update_vod_config_rest_required_fields( + request_type=video_stitcher_service.UpdateVodConfigRequest, +): + transport_class = transports.VideoStitcherServiceRestTransport + + request_init = {} + request = request_type(**request_init) + pb_request = request_type.pb(request) + jsonified_request = json.loads( + json_format.MessageToJson(pb_request, use_integers_for_enums=False) + ) + + # verify fields with default values are dropped + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_vod_config._get_unset_required_fields(jsonified_request) + jsonified_request.update(unset_fields) + + # verify required fields with default values are now present + + unset_fields = transport_class( + credentials=ga_credentials.AnonymousCredentials() + ).update_vod_config._get_unset_required_fields(jsonified_request) + # Check that path parameters and body parameters are not mixing in. + assert not set(unset_fields) - set(("update_mask",)) + jsonified_request.update(unset_fields) + + # verify required fields with non-default values are left alone + + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + request = request_type(**request_init) + + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # We need to mock transcode() because providing default values + # for required fields will fail the real version if the http_options + # expect actual values for those fields. + with mock.patch.object(path_template, "transcode") as transcode: + # A uri without fields and an empty body will force all the + # request fields to show up in the query_params. + pb_request = request_type.pb(request) + transcode_result = { + "uri": "v1/sample_method", + "method": "patch", + "query_params": pb_request, + } + transcode_result["body"] = pb_request + transcode.return_value = transcode_result + + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + response = client.update_vod_config(request) + + expected_params = [("$alt", "json;enum-encoding=int")] + actual_params = req.call_args.kwargs["params"] + assert expected_params == actual_params + + +def test_update_vod_config_rest_unset_required_fields(): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials + ) + + unset_fields = transport.update_vod_config._get_unset_required_fields({}) + assert set(unset_fields) == ( + set(("updateMask",)) + & set( + ( + "vodConfig", + "updateMask", + ) + ) + ) + + +def test_update_vod_config_rest_flattened(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # get arguments that satisfy an http rule for this method + sample_request = { + "vod_config": { + "name": "projects/sample1/locations/sample2/vodConfigs/sample3" + } + } + + # get truthy value for each flattened field + mock_args = dict( + vod_config=vod_configs.VodConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + mock_args.update(sample_request) + + # Wrap the value into a proper Response obj + response_value = Response() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value._content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + + client.update_vod_config(**mock_args) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(req.mock_calls) == 1 + _, args, _ = req.mock_calls[0] + assert path_template.validate( + "%s/v1/{vod_config.name=projects/*/locations/*/vodConfigs/*}" + % client.transport._host, + args[1], + ) + + +def test_update_vod_config_rest_flattened_error(transport: str = "rest"): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_vod_config( + video_stitcher_service.UpdateVodConfigRequest(), + vod_config=vod_configs.VodConfig(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.VideoStitcherServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.VideoStitcherServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = VideoStitcherServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.VideoStitcherServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = VideoStitcherServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = VideoStitcherServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.VideoStitcherServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = VideoStitcherServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.VideoStitcherServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = VideoStitcherServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.VideoStitcherServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.VideoStitcherServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.VideoStitcherServiceGrpcTransport, + transports.VideoStitcherServiceGrpcAsyncIOTransport, + transports.VideoStitcherServiceRestTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +def test_transport_kind_grpc(): + transport = VideoStitcherServiceClient.get_transport_class("grpc")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "grpc" + + +def test_initialize_client_w_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_cdn_key_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_cdn_key), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_cdn_keys_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_cdn_keys), "__call__") as call: + call.return_value = video_stitcher_service.ListCdnKeysResponse() + client.list_cdn_keys(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListCdnKeysRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_cdn_key_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_cdn_key), "__call__") as call: + call.return_value = cdn_keys.CdnKey() + client.get_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_cdn_key_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_cdn_key), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_cdn_key_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_cdn_key), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_vod_session_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_vod_session), "__call__" + ) as call: + call.return_value = sessions.VodSession() + client.create_vod_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateVodSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_vod_session_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_vod_session), "__call__") as call: + call.return_value = sessions.VodSession() + client.get_vod_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_vod_stitch_details_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_vod_stitch_details), "__call__" + ) as call: + call.return_value = video_stitcher_service.ListVodStitchDetailsResponse() + client.list_vod_stitch_details(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListVodStitchDetailsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_vod_stitch_detail_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_vod_stitch_detail), "__call__" + ) as call: + call.return_value = stitch_details.VodStitchDetail() + client.get_vod_stitch_detail(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodStitchDetailRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_vod_ad_tag_details_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_vod_ad_tag_details), "__call__" + ) as call: + call.return_value = video_stitcher_service.ListVodAdTagDetailsResponse() + client.list_vod_ad_tag_details(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListVodAdTagDetailsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_vod_ad_tag_detail_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_vod_ad_tag_detail), "__call__" + ) as call: + call.return_value = ad_tag_details.VodAdTagDetail() + client.get_vod_ad_tag_detail(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodAdTagDetailRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_live_ad_tag_details_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_live_ad_tag_details), "__call__" + ) as call: + call.return_value = video_stitcher_service.ListLiveAdTagDetailsResponse() + client.list_live_ad_tag_details(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListLiveAdTagDetailsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_live_ad_tag_detail_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_live_ad_tag_detail), "__call__" + ) as call: + call.return_value = ad_tag_details.LiveAdTagDetail() + client.get_live_ad_tag_detail(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetLiveAdTagDetailRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_slate_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_slate), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_slates_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_slates), "__call__") as call: + call.return_value = video_stitcher_service.ListSlatesResponse() + client.list_slates(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListSlatesRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_slate_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_slate), "__call__") as call: + call.return_value = slates.Slate() + client.get_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_slate_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_slate), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_slate_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_slate), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_live_session_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_live_session), "__call__" + ) as call: + call.return_value = sessions.LiveSession() + client.create_live_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateLiveSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_live_session_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_live_session), "__call__") as call: + call.return_value = sessions.LiveSession() + client.get_live_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetLiveSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_live_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_live_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_live_configs_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_live_configs), "__call__" + ) as call: + call.return_value = video_stitcher_service.ListLiveConfigsResponse() + client.list_live_configs(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListLiveConfigsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_live_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_live_config), "__call__") as call: + call.return_value = live_configs.LiveConfig() + client.get_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_live_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_live_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_live_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_live_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_create_vod_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_vod_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateVodConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_vod_configs_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_vod_configs), "__call__") as call: + call.return_value = video_stitcher_service.ListVodConfigsResponse() + client.list_vod_configs(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListVodConfigsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_get_vod_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_vod_config), "__call__") as call: + call.return_value = vod_configs.VodConfig() + client.get_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_delete_vod_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_vod_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteVodConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_update_vod_config_empty_call_grpc(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_vod_config), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateVodConfigRequest() + + assert args[0] == request_msg + + +def test_transport_kind_grpc_asyncio(): + transport = VideoStitcherServiceAsyncClient.get_transport_class("grpc_asyncio")( + credentials=async_anonymous_credentials() + ) + assert transport.kind == "grpc_asyncio" + + +def test_initialize_client_w_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), transport="grpc_asyncio" + ) + assert client is not None + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_cdn_key_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_cdn_key), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_cdn_keys_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_cdn_keys), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListCdnKeysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_cdn_keys(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListCdnKeysRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_cdn_key_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_cdn_key), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + cdn_keys.CdnKey( + name="name_value", + hostname="hostname_value", + ) + ) + await client.get_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_cdn_key_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_cdn_key), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_cdn_key_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_cdn_key), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_cdn_key(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateCdnKeyRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_vod_session_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_vod_session), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + sessions.VodSession( + name="name_value", + play_uri="play_uri_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + asset_id="asset_id_value", + ad_tracking=live_configs.AdTracking.CLIENT, + vod_config="vod_config_value", + ) + ) + await client.create_vod_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateVodSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_vod_session_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_vod_session), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + sessions.VodSession( + name="name_value", + play_uri="play_uri_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + asset_id="asset_id_value", + ad_tracking=live_configs.AdTracking.CLIENT, + vod_config="vod_config_value", + ) + ) + await client.get_vod_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_vod_stitch_details_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_vod_stitch_details), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListVodStitchDetailsResponse( + next_page_token="next_page_token_value", + ) + ) + await client.list_vod_stitch_details(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListVodStitchDetailsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_vod_stitch_detail_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_vod_stitch_detail), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + stitch_details.VodStitchDetail( + name="name_value", + ) + ) + await client.get_vod_stitch_detail(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodStitchDetailRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_vod_ad_tag_details_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_vod_ad_tag_details), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListVodAdTagDetailsResponse( + next_page_token="next_page_token_value", + ) + ) + await client.list_vod_ad_tag_details(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListVodAdTagDetailsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_vod_ad_tag_detail_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_vod_ad_tag_detail), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + ad_tag_details.VodAdTagDetail( + name="name_value", + ) + ) + await client.get_vod_ad_tag_detail(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodAdTagDetailRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_live_ad_tag_details_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_live_ad_tag_details), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListLiveAdTagDetailsResponse( + next_page_token="next_page_token_value", + ) + ) + await client.list_live_ad_tag_details(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListLiveAdTagDetailsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_live_ad_tag_detail_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.get_live_ad_tag_detail), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + ad_tag_details.LiveAdTagDetail( + name="name_value", + ) + ) + await client.get_live_ad_tag_detail(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetLiveAdTagDetailRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_slate_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.create_slate), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_slates_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_slates), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListSlatesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_slates(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListSlatesRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_slate_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_slate), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + slates.Slate( + name="name_value", + uri="uri_value", + ) + ) + await client.get_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_slate_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.update_slate), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_slate_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.delete_slate), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_slate(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteSlateRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_live_session_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_live_session), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + sessions.LiveSession( + name="name_value", + play_uri="play_uri_value", + live_config="live_config_value", + ad_tracking=live_configs.AdTracking.CLIENT, + ) + ) + await client.create_live_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateLiveSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_live_session_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_live_session), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + sessions.LiveSession( + name="name_value", + play_uri="play_uri_value", + live_config="live_config_value", + ad_tracking=live_configs.AdTracking.CLIENT, + ) + ) + await client.get_live_session(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetLiveSessionRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_live_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_live_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateLiveConfigRequest() + + assert args[0] == request_msg # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -def test_create_vod_session_empty_call_grpc(): +@pytest.mark.asyncio +async def test_list_live_configs_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_live_configs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListLiveConfigsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_live_configs(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListLiveConfigsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_live_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_live_config), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + live_configs.LiveConfig( + name="name_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + state=live_configs.LiveConfig.State.CREATING, + ad_tracking=live_configs.AdTracking.CLIENT, + default_slate="default_slate_value", + stitching_policy=live_configs.LiveConfig.StitchingPolicy.CUT_CURRENT, + ) + ) + await client.get_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_live_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_live_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_live_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_live_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_live_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateLiveConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_create_vod_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.create_vod_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.create_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.CreateVodConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_vod_configs_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.list_vod_configs), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + video_stitcher_service.ListVodConfigsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + ) + await client.list_vod_configs(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.ListVodConfigsRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_get_vod_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_vod_config), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vod_configs.VodConfig( + name="name_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + state=vod_configs.VodConfig.State.CREATING, + ) + ) + await client.get_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.GetVodConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_delete_vod_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.delete_vod_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.delete_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.DeleteVodConfigRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_update_vod_config_empty_call_grpc_asyncio(): + client = VideoStitcherServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.update_vod_config), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + await client.update_vod_config(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = video_stitcher_service.UpdateVodConfigRequest() + + assert args[0] == request_msg + + +def test_transport_kind_rest(): + transport = VideoStitcherServiceClient.get_transport_class("rest")( + credentials=ga_credentials.AnonymousCredentials() + ) + assert transport.kind == "rest" + + +def test_create_cdn_key_rest_bad_request( + request_type=video_stitcher_service.CreateCdnKeyRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_cdn_key(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.CreateCdnKeyRequest, + dict, + ], +) +def test_create_cdn_key_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["cdn_key"] = { + "google_cdn_key": { + "private_key": b"private_key_blob", + "key_name": "key_name_value", + }, + "akamai_cdn_key": {"token_key": b"token_key_blob"}, + "media_cdn_key": { + "private_key": b"private_key_blob", + "key_name": "key_name_value", + "token_config": {"query_parameter": "query_parameter_value"}, + }, + "name": "name_value", + "hostname": "hostname_value", + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.CreateCdnKeyRequest.meta.fields["cdn_key"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["cdn_key"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["cdn_key"][field])): + del request_init["cdn_key"][field][i][subfield] + else: + del request_init["cdn_key"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_cdn_key(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_cdn_key_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_create_cdn_key" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_create_cdn_key_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_create_cdn_key" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.CreateCdnKeyRequest.pb( + video_stitcher_service.CreateCdnKeyRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.CreateCdnKeyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.create_cdn_key( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_cdn_keys_rest_bad_request( + request_type=video_stitcher_service.ListCdnKeysRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_cdn_keys(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListCdnKeysRequest, + dict, + ], +) +def test_list_cdn_keys_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListCdnKeysResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListCdnKeysResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_cdn_keys(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListCdnKeysPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_cdn_keys_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_cdn_keys" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_list_cdn_keys_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_cdn_keys" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListCdnKeysRequest.pb( + video_stitcher_service.ListCdnKeysRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListCdnKeysResponse.to_json( + video_stitcher_service.ListCdnKeysResponse() + ) + req.return_value.content = return_value + + request = video_stitcher_service.ListCdnKeysRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListCdnKeysResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListCdnKeysResponse(), + metadata, + ) + + client.list_cdn_keys( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_cdn_key_rest_bad_request( + request_type=video_stitcher_service.GetCdnKeyRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_cdn_key(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetCdnKeyRequest, + dict, + ], +) +def test_get_cdn_key_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = cdn_keys.CdnKey( + name="name_value", + hostname="hostname_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = cdn_keys.CdnKey.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_cdn_key(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, cdn_keys.CdnKey) + assert response.name == "name_value" + assert response.hostname == "hostname_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_cdn_key_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_cdn_key" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_cdn_key_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_cdn_key" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetCdnKeyRequest.pb( + video_stitcher_service.GetCdnKeyRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = cdn_keys.CdnKey.to_json(cdn_keys.CdnKey()) + req.return_value.content = return_value + + request = video_stitcher_service.GetCdnKeyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = cdn_keys.CdnKey() + post_with_metadata.return_value = cdn_keys.CdnKey(), metadata + + client.get_cdn_key( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_delete_cdn_key_rest_bad_request( + request_type=video_stitcher_service.DeleteCdnKeyRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_cdn_key(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.DeleteCdnKeyRequest, + dict, + ], +) +def test_delete_cdn_key_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_cdn_key(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_cdn_key_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_delete_cdn_key" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_delete_cdn_key_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_delete_cdn_key" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.DeleteCdnKeyRequest.pb( + video_stitcher_service.DeleteCdnKeyRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.DeleteCdnKeyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.delete_cdn_key( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_update_cdn_key_rest_bad_request( + request_type=video_stitcher_service.UpdateCdnKeyRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "cdn_key": {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_cdn_key(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.UpdateCdnKeyRequest, + dict, + ], +) +def test_update_cdn_key_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "cdn_key": {"name": "projects/sample1/locations/sample2/cdnKeys/sample3"} + } + request_init["cdn_key"] = { + "google_cdn_key": { + "private_key": b"private_key_blob", + "key_name": "key_name_value", + }, + "akamai_cdn_key": {"token_key": b"token_key_blob"}, + "media_cdn_key": { + "private_key": b"private_key_blob", + "key_name": "key_name_value", + "token_config": {"query_parameter": "query_parameter_value"}, + }, + "name": "projects/sample1/locations/sample2/cdnKeys/sample3", + "hostname": "hostname_value", + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.UpdateCdnKeyRequest.meta.fields["cdn_key"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["cdn_key"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["cdn_key"][field])): + del request_init["cdn_key"][field][i][subfield] + else: + del request_init["cdn_key"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_cdn_key(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_cdn_key_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_update_cdn_key" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_update_cdn_key_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_update_cdn_key" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.UpdateCdnKeyRequest.pb( + video_stitcher_service.UpdateCdnKeyRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.UpdateCdnKeyRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.update_cdn_key( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_create_vod_session_rest_bad_request( + request_type=video_stitcher_service.CreateVodSessionRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_vod_session(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.CreateVodSessionRequest, + dict, + ], +) +def test_create_vod_session_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["vod_session"] = { + "name": "name_value", + "interstitials": { + "ad_breaks": [ + { + "progress_events": [ + { + "time_offset": {"seconds": 751, "nanos": 543}, + "events": [ + { + "type_": 1, + "uri": "uri_value", + "id": "id_value", + "offset": {}, + } + ], + } + ], + "ads": [ + { + "duration": {}, + "companion_ads": { + "display_requirement": 1, + "companions": [ + { + "iframe_ad_resource": {"uri": "uri_value"}, + "static_ad_resource": { + "uri": "uri_value", + "creative_type": "creative_type_value", + }, + "html_ad_resource": { + "html_source": "html_source_value" + }, + "api_framework": "api_framework_value", + "height_px": 960, + "width_px": 871, + "asset_height_px": 1599, + "expanded_height_px": 1896, + "asset_width_px": 1510, + "expanded_width_px": 1807, + "ad_slot_id": "ad_slot_id_value", + "events": {}, + } + ], + }, + "activity_events": {}, + } + ], + "end_time_offset": {}, + "start_time_offset": {}, + } + ], + "session_content": {"duration": {}}, + }, + "play_uri": "play_uri_value", + "source_uri": "source_uri_value", + "ad_tag_uri": "ad_tag_uri_value", + "ad_tag_macro_map": {}, + "manifest_options": { + "include_renditions": [{"bitrate_bps": 1167, "codecs": "codecs_value"}], + "bitrate_order": 1, + }, + "asset_id": "asset_id_value", + "ad_tracking": 1, + "gam_settings": { + "network_code": "network_code_value", + "stream_id": "stream_id_value", + }, + "vod_config": "vod_config_value", + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.CreateVodSessionRequest.meta.fields[ + "vod_session" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["vod_session"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["vod_session"][field])): + del request_init["vod_session"][field][i][subfield] + else: + del request_init["vod_session"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.VodSession( + name="name_value", + play_uri="play_uri_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + asset_id="asset_id_value", + ad_tracking=live_configs.AdTracking.CLIENT, + vod_config="vod_config_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.VodSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_vod_session(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, sessions.VodSession) + assert response.name == "name_value" + assert response.play_uri == "play_uri_value" + assert response.source_uri == "source_uri_value" + assert response.ad_tag_uri == "ad_tag_uri_value" + assert response.asset_id == "asset_id_value" + assert response.ad_tracking == live_configs.AdTracking.CLIENT + assert response.vod_config == "vod_config_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_vod_session_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_create_vod_session" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_create_vod_session_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_create_vod_session" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.CreateVodSessionRequest.pb( + video_stitcher_service.CreateVodSessionRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = sessions.VodSession.to_json(sessions.VodSession()) + req.return_value.content = return_value + + request = video_stitcher_service.CreateVodSessionRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = sessions.VodSession() + post_with_metadata.return_value = sessions.VodSession(), metadata + + client.create_vod_session( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_vod_session_rest_bad_request( + request_type=video_stitcher_service.GetVodSessionRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/vodSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_vod_session(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetVodSessionRequest, + dict, + ], +) +def test_get_vod_session_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/vodSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.VodSession( + name="name_value", + play_uri="play_uri_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + asset_id="asset_id_value", + ad_tracking=live_configs.AdTracking.CLIENT, + vod_config="vod_config_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.VodSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_vod_session(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, sessions.VodSession) + assert response.name == "name_value" + assert response.play_uri == "play_uri_value" + assert response.source_uri == "source_uri_value" + assert response.ad_tag_uri == "ad_tag_uri_value" + assert response.asset_id == "asset_id_value" + assert response.ad_tracking == live_configs.AdTracking.CLIENT + assert response.vod_config == "vod_config_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_vod_session_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_vod_session" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_vod_session_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_vod_session" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetVodSessionRequest.pb( + video_stitcher_service.GetVodSessionRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = sessions.VodSession.to_json(sessions.VodSession()) + req.return_value.content = return_value + + request = video_stitcher_service.GetVodSessionRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = sessions.VodSession() + post_with_metadata.return_value = sessions.VodSession(), metadata + + client.get_vod_session( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_vod_stitch_details_rest_bad_request( + request_type=video_stitcher_service.ListVodStitchDetailsRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/vodSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_vod_stitch_details(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListVodStitchDetailsRequest, + dict, + ], +) +def test_list_vod_stitch_details_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/vodSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodStitchDetailsResponse( + next_page_token="next_page_token_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodStitchDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_vod_stitch_details(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListVodStitchDetailsPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_vod_stitch_details_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_vod_stitch_details" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_list_vod_stitch_details_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_vod_stitch_details" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListVodStitchDetailsRequest.pb( + video_stitcher_service.ListVodStitchDetailsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListVodStitchDetailsResponse.to_json( + video_stitcher_service.ListVodStitchDetailsResponse() + ) + req.return_value.content = return_value + + request = video_stitcher_service.ListVodStitchDetailsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListVodStitchDetailsResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListVodStitchDetailsResponse(), + metadata, + ) + + client.list_vod_stitch_details( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_vod_stitch_detail_rest_bad_request( + request_type=video_stitcher_service.GetVodStitchDetailRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3/vodStitchDetails/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_vod_stitch_detail(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetVodStitchDetailRequest, + dict, + ], +) +def test_get_vod_stitch_detail_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3/vodStitchDetails/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = stitch_details.VodStitchDetail( + name="name_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = stitch_details.VodStitchDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_vod_stitch_detail(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, stitch_details.VodStitchDetail) + assert response.name == "name_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_vod_stitch_detail_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_vod_stitch_detail" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_vod_stitch_detail_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_vod_stitch_detail" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetVodStitchDetailRequest.pb( + video_stitcher_service.GetVodStitchDetailRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = stitch_details.VodStitchDetail.to_json( + stitch_details.VodStitchDetail() + ) + req.return_value.content = return_value + + request = video_stitcher_service.GetVodStitchDetailRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = stitch_details.VodStitchDetail() + post_with_metadata.return_value = stitch_details.VodStitchDetail(), metadata + + client.get_vod_stitch_detail( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_vod_ad_tag_details_rest_bad_request( + request_type=video_stitcher_service.ListVodAdTagDetailsRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/vodSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_vod_ad_tag_details(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListVodAdTagDetailsRequest, + dict, + ], +) +def test_list_vod_ad_tag_details_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/vodSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodAdTagDetailsResponse( + next_page_token="next_page_token_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodAdTagDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_vod_ad_tag_details(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListVodAdTagDetailsPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_vod_ad_tag_details_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_vod_ad_tag_details" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_list_vod_ad_tag_details_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_vod_ad_tag_details" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListVodAdTagDetailsRequest.pb( + video_stitcher_service.ListVodAdTagDetailsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListVodAdTagDetailsResponse.to_json( + video_stitcher_service.ListVodAdTagDetailsResponse() + ) + req.return_value.content = return_value + + request = video_stitcher_service.ListVodAdTagDetailsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListVodAdTagDetailsResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListVodAdTagDetailsResponse(), + metadata, + ) + + client.list_vod_ad_tag_details( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_vod_ad_tag_detail_rest_bad_request( + request_type=video_stitcher_service.GetVodAdTagDetailRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3/vodAdTagDetails/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_vod_ad_tag_detail(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetVodAdTagDetailRequest, + dict, + ], +) +def test_get_vod_ad_tag_detail_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/vodSessions/sample3/vodAdTagDetails/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = ad_tag_details.VodAdTagDetail( + name="name_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = ad_tag_details.VodAdTagDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_vod_ad_tag_detail(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, ad_tag_details.VodAdTagDetail) + assert response.name == "name_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_vod_ad_tag_detail_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_vod_ad_tag_detail" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_vod_ad_tag_detail_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_vod_ad_tag_detail" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetVodAdTagDetailRequest.pb( + video_stitcher_service.GetVodAdTagDetailRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = ad_tag_details.VodAdTagDetail.to_json( + ad_tag_details.VodAdTagDetail() + ) + req.return_value.content = return_value + + request = video_stitcher_service.GetVodAdTagDetailRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = ad_tag_details.VodAdTagDetail() + post_with_metadata.return_value = ad_tag_details.VodAdTagDetail(), metadata + + client.get_vod_ad_tag_detail( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_live_ad_tag_details_rest_bad_request( + request_type=video_stitcher_service.ListLiveAdTagDetailsRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/liveSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_live_ad_tag_details(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListLiveAdTagDetailsRequest, + dict, + ], +) +def test_list_live_ad_tag_details_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2/liveSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse( + next_page_token="next_page_token_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse.pb( + return_value + ) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_live_ad_tag_details(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListLiveAdTagDetailsPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_live_ad_tag_details_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_live_ad_tag_details" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_list_live_ad_tag_details_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_live_ad_tag_details" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListLiveAdTagDetailsRequest.pb( + video_stitcher_service.ListLiveAdTagDetailsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListLiveAdTagDetailsResponse.to_json( + video_stitcher_service.ListLiveAdTagDetailsResponse() + ) + req.return_value.content = return_value + + request = video_stitcher_service.ListLiveAdTagDetailsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListLiveAdTagDetailsResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListLiveAdTagDetailsResponse(), + metadata, + ) + + client.list_live_ad_tag_details( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_live_ad_tag_detail_rest_bad_request( + request_type=video_stitcher_service.GetLiveAdTagDetailRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/liveSessions/sample3/liveAdTagDetails/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_live_ad_tag_detail(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetLiveAdTagDetailRequest, + dict, + ], +) +def test_get_live_ad_tag_detail_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "name": "projects/sample1/locations/sample2/liveSessions/sample3/liveAdTagDetails/sample4" + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = ad_tag_details.LiveAdTagDetail( + name="name_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = ad_tag_details.LiveAdTagDetail.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_live_ad_tag_detail(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, ad_tag_details.LiveAdTagDetail) + assert response.name == "name_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_live_ad_tag_detail_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_live_ad_tag_detail" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_live_ad_tag_detail_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_live_ad_tag_detail" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetLiveAdTagDetailRequest.pb( + video_stitcher_service.GetLiveAdTagDetailRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = ad_tag_details.LiveAdTagDetail.to_json( + ad_tag_details.LiveAdTagDetail() + ) + req.return_value.content = return_value + + request = video_stitcher_service.GetLiveAdTagDetailRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = ad_tag_details.LiveAdTagDetail() + post_with_metadata.return_value = ad_tag_details.LiveAdTagDetail(), metadata + + client.get_live_ad_tag_detail( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_create_slate_rest_bad_request( + request_type=video_stitcher_service.CreateSlateRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_slate(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.CreateSlateRequest, + dict, + ], +) +def test_create_slate_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["slate"] = { + "name": "name_value", + "uri": "uri_value", + "gam_slate": {"network_code": "network_code_value", "gam_slate_id": 1241}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.CreateSlateRequest.meta.fields["slate"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["slate"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["slate"][field])): + del request_init["slate"][field][i][subfield] + else: + del request_init["slate"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_slate(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_slate_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_create_slate" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_create_slate_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_create_slate" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.CreateSlateRequest.pb( + video_stitcher_service.CreateSlateRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.CreateSlateRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.create_slate( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_slates_rest_bad_request( + request_type=video_stitcher_service.ListSlatesRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_slates(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListSlatesRequest, + dict, + ], +) +def test_list_slates_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListSlatesResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListSlatesResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_slates(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListSlatesPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_slates_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_slates" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_slates_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_slates" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListSlatesRequest.pb( + video_stitcher_service.ListSlatesRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListSlatesResponse.to_json( + video_stitcher_service.ListSlatesResponse() + ) + req.return_value.content = return_value + + request = video_stitcher_service.ListSlatesRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListSlatesResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListSlatesResponse(), + metadata, + ) + + client.list_slates( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_slate_rest_bad_request( + request_type=video_stitcher_service.GetSlateRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/slates/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_slate(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetSlateRequest, + dict, + ], +) +def test_get_slate_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/slates/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = slates.Slate( + name="name_value", + uri="uri_value", + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = slates.Slate.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_slate(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, slates.Slate) + assert response.name == "name_value" + assert response.uri == "uri_value" + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_slate_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_slate" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_slate_with_metadata" + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_slate" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetSlateRequest.pb( + video_stitcher_service.GetSlateRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = slates.Slate.to_json(slates.Slate()) + req.return_value.content = return_value + + request = video_stitcher_service.GetSlateRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = slates.Slate() + post_with_metadata.return_value = slates.Slate(), metadata + + client.get_slate( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_update_slate_rest_bad_request( + request_type=video_stitcher_service.UpdateSlateRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "slate": {"name": "projects/sample1/locations/sample2/slates/sample3"} + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_slate(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.UpdateSlateRequest, + dict, + ], +) +def test_update_slate_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "slate": {"name": "projects/sample1/locations/sample2/slates/sample3"} + } + request_init["slate"] = { + "name": "projects/sample1/locations/sample2/slates/sample3", + "uri": "uri_value", + "gam_slate": {"network_code": "network_code_value", "gam_slate_id": 1241}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.UpdateSlateRequest.meta.fields["slate"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["slate"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["slate"][field])): + del request_init["slate"][field][i][subfield] + else: + del request_init["slate"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_slate(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_slate_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_update_slate" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_update_slate_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_update_slate" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.UpdateSlateRequest.pb( + video_stitcher_service.UpdateSlateRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.UpdateSlateRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.update_slate( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_delete_slate_rest_bad_request( + request_type=video_stitcher_service.DeleteSlateRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/slates/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_slate(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.DeleteSlateRequest, + dict, + ], +) +def test_delete_slate_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/slates/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_slate(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_slate_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_delete_slate" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_delete_slate_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_delete_slate" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.DeleteSlateRequest.pb( + video_stitcher_service.DeleteSlateRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.DeleteSlateRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.delete_slate( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_create_live_session_rest_bad_request( + request_type=video_stitcher_service.CreateLiveSessionRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_live_session(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.CreateLiveSessionRequest, + dict, + ], +) +def test_create_live_session_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["live_session"] = { + "name": "name_value", + "play_uri": "play_uri_value", + "ad_tag_macros": {}, + "manifest_options": { + "include_renditions": [{"bitrate_bps": 1167, "codecs": "codecs_value"}], + "bitrate_order": 1, + }, + "gam_settings": {"stream_id": "stream_id_value", "targeting_parameters": {}}, + "live_config": "live_config_value", + "ad_tracking": 1, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.CreateLiveSessionRequest.meta.fields[ + "live_session" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["live_session"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["live_session"][field])): + del request_init["live_session"][field][i][subfield] + else: + del request_init["live_session"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.LiveSession( + name="name_value", + play_uri="play_uri_value", + live_config="live_config_value", + ad_tracking=live_configs.AdTracking.CLIENT, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.LiveSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_live_session(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, sessions.LiveSession) + assert response.name == "name_value" + assert response.play_uri == "play_uri_value" + assert response.live_config == "live_config_value" + assert response.ad_tracking == live_configs.AdTracking.CLIENT + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_live_session_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_create_live_session" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_create_live_session_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_create_live_session" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.CreateLiveSessionRequest.pb( + video_stitcher_service.CreateLiveSessionRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = sessions.LiveSession.to_json(sessions.LiveSession()) + req.return_value.content = return_value + + request = video_stitcher_service.CreateLiveSessionRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = sessions.LiveSession() + post_with_metadata.return_value = sessions.LiveSession(), metadata + + client.create_live_session( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_get_live_session_rest_bad_request( + request_type=video_stitcher_service.GetLiveSessionRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/liveSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_live_session(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetLiveSessionRequest, + dict, + ], +) +def test_get_live_session_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/liveSessions/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = sessions.LiveSession( + name="name_value", + play_uri="play_uri_value", + live_config="live_config_value", + ad_tracking=live_configs.AdTracking.CLIENT, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = sessions.LiveSession.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_live_session(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, sessions.LiveSession) + assert response.name == "name_value" + assert response.play_uri == "play_uri_value" + assert response.live_config == "live_config_value" + assert response.ad_tracking == live_configs.AdTracking.CLIENT + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_live_session_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_live_session" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_live_session_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_live_session" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetLiveSessionRequest.pb( + video_stitcher_service.GetLiveSessionRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = sessions.LiveSession.to_json(sessions.LiveSession()) + req.return_value.content = return_value + + request = video_stitcher_service.GetLiveSessionRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = sessions.LiveSession() + post_with_metadata.return_value = sessions.LiveSession(), metadata + + client.get_live_session( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_create_live_config_rest_bad_request( + request_type=video_stitcher_service.CreateLiveConfigRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_live_config(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.CreateLiveConfigRequest, + dict, + ], +) +def test_create_live_config_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["live_config"] = { + "name": "name_value", + "source_uri": "source_uri_value", + "ad_tag_uri": "ad_tag_uri_value", + "gam_live_config": { + "network_code": "network_code_value", + "asset_key": "asset_key_value", + "custom_asset_key": "custom_asset_key_value", + }, + "state": 1, + "ad_tracking": 1, + "default_slate": "default_slate_value", + "stitching_policy": 1, + "prefetch_config": { + "enabled": True, + "initial_ad_request_duration": {"seconds": 751, "nanos": 543}, + }, + "source_fetch_options": {"headers": {}}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.CreateLiveConfigRequest.meta.fields[ + "live_config" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["live_config"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["live_config"][field])): + del request_init["live_config"][field][i][subfield] + else: + del request_init["live_config"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_live_config(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_live_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( + credentials=ga_credentials.AnonymousCredentials(), + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), + ) + client = VideoStitcherServiceClient(transport=transport) + + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_create_live_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_create_live_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_create_live_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.CreateLiveConfigRequest.pb( + video_stitcher_service.CreateLiveConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.CreateLiveConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.create_live_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_list_live_configs_rest_bad_request( + request_type=video_stitcher_service.ListLiveConfigsRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_live_configs(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListLiveConfigsRequest, + dict, + ], +) +def test_list_live_configs_rest_call_success(request_type): client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListLiveConfigsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = video_stitcher_service.ListLiveConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_live_configs(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListLiveConfigsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_live_configs_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.create_vod_session), "__call__" - ) as call: - call.return_value = sessions.VodSession() - client.create_vod_session(request=None) + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_live_configs" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_list_live_configs_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_live_configs" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListLiveConfigsRequest.pb( + video_stitcher_service.ListLiveConfigsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListLiveConfigsResponse.to_json( + video_stitcher_service.ListLiveConfigsResponse() + ) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.CreateVodSessionRequest() + request = video_stitcher_service.ListLiveConfigsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListLiveConfigsResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListLiveConfigsResponse(), + metadata, + ) - assert args[0] == request_msg + client.list_live_configs( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_vod_session_empty_call_grpc(): + +def test_get_live_config_rest_bad_request( + request_type=video_stitcher_service.GetLiveConfigRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/liveConfigs/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_live_config(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetLiveConfigRequest, + dict, + ], +) +def test_get_live_config_rest_call_success(request_type): client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/liveConfigs/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = live_configs.LiveConfig( + name="name_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + state=live_configs.LiveConfig.State.CREATING, + ad_tracking=live_configs.AdTracking.CLIENT, + default_slate="default_slate_value", + stitching_policy=live_configs.LiveConfig.StitchingPolicy.CUT_CURRENT, + ) + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + + # Convert return value to protobuf type + return_value = live_configs.LiveConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_live_config(request) + + # Establish that the response is the type that we expect. + assert isinstance(response, live_configs.LiveConfig) + assert response.name == "name_value" + assert response.source_uri == "source_uri_value" + assert response.ad_tag_uri == "ad_tag_uri_value" + assert response.state == live_configs.LiveConfig.State.CREATING + assert response.ad_tracking == live_configs.AdTracking.CLIENT + assert response.default_slate == "default_slate_value" + assert ( + response.stitching_policy == live_configs.LiveConfig.StitchingPolicy.CUT_CURRENT + ) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_live_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_vod_session), "__call__") as call: - call.return_value = sessions.VodSession() - client.get_vod_session(request=None) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_live_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_live_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_live_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetLiveConfigRequest.pb( + video_stitcher_service.GetLiveConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = live_configs.LiveConfig.to_json(live_configs.LiveConfig()) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetVodSessionRequest() + request = video_stitcher_service.GetLiveConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = live_configs.LiveConfig() + post_with_metadata.return_value = live_configs.LiveConfig(), metadata - assert args[0] == request_msg + client.get_live_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_vod_stitch_details_empty_call_grpc(): + +def test_delete_live_config_rest_bad_request( + request_type=video_stitcher_service.DeleteLiveConfigRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/liveConfigs/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_live_config(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.DeleteLiveConfigRequest, + dict, + ], +) +def test_delete_live_config_rest_call_success(request_type): client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/liveConfigs/sample3"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_live_config(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_live_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.list_vod_stitch_details), "__call__" - ) as call: - call.return_value = video_stitcher_service.ListVodStitchDetailsResponse() - client.list_vod_stitch_details(request=None) + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_delete_live_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_delete_live_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_delete_live_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.DeleteLiveConfigRequest.pb( + video_stitcher_service.DeleteLiveConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListVodStitchDetailsRequest() + request = video_stitcher_service.DeleteLiveConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - assert args[0] == request_msg + client.delete_live_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_vod_stitch_detail_empty_call_grpc(): + +def test_update_live_config_rest_bad_request( + request_type=video_stitcher_service.UpdateLiveConfigRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "live_config": { + "name": "projects/sample1/locations/sample2/liveConfigs/sample3" + } + } + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_live_config(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.UpdateLiveConfigRequest, + dict, + ], +) +def test_update_live_config_rest_call_success(request_type): client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = { + "live_config": { + "name": "projects/sample1/locations/sample2/liveConfigs/sample3" + } + } + request_init["live_config"] = { + "name": "projects/sample1/locations/sample2/liveConfigs/sample3", + "source_uri": "source_uri_value", + "ad_tag_uri": "ad_tag_uri_value", + "gam_live_config": { + "network_code": "network_code_value", + "asset_key": "asset_key_value", + "custom_asset_key": "custom_asset_key_value", + }, + "state": 1, + "ad_tracking": 1, + "default_slate": "default_slate_value", + "stitching_policy": 1, + "prefetch_config": { + "enabled": True, + "initial_ad_request_duration": {"seconds": 751, "nanos": 543}, + }, + "source_fetch_options": {"headers": {}}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.UpdateLiveConfigRequest.meta.fields[ + "live_config" + ] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["live_config"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) + + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["live_config"][field])): + del request_init["live_config"][field][i][subfield] + else: + del request_init["live_config"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_live_config(request) + + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_live_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.get_vod_stitch_detail), "__call__" - ) as call: - call.return_value = stitch_details.VodStitchDetail() - client.get_vod_stitch_detail(request=None) + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_update_live_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_update_live_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_update_live_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.UpdateLiveConfigRequest.pb( + video_stitcher_service.UpdateLiveConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value + + request = video_stitcher_service.UpdateLiveConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + + client.update_live_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() + + +def test_create_vod_config_rest_bad_request( + request_type=video_stitcher_service.CreateVodConfigRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.create_vod_config(request) + + +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.CreateVodConfigRequest, + dict, + ], +) +def test_create_vod_config_rest_call_success(request_type): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request_init["vod_config"] = { + "name": "name_value", + "source_uri": "source_uri_value", + "ad_tag_uri": "ad_tag_uri_value", + "gam_vod_config": {"network_code": "network_code_value"}, + "state": 1, + "source_fetch_options": {"headers": {}}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.CreateVodConfigRequest.meta.fields["vod_config"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] + + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["vod_config"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetVodStitchDetailRequest() + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["vod_config"][field])): + del request_init["vod_config"][field][i][subfield] + else: + del request_init["vod_config"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.create_vod_config(request) - assert args[0] == request_msg + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_vod_ad_tag_details_empty_call_grpc(): - client = VideoStitcherServiceClient( +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_create_vod_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.list_vod_ad_tag_details), "__call__" - ) as call: - call.return_value = video_stitcher_service.ListVodAdTagDetailsResponse() - client.list_vod_ad_tag_details(request=None) + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_create_vod_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_create_vod_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_create_vod_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.CreateVodConfigRequest.pb( + video_stitcher_service.CreateVodConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListVodAdTagDetailsRequest() + request = video_stitcher_service.CreateVodConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - assert args[0] == request_msg + client.create_vod_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_vod_ad_tag_detail_empty_call_grpc(): + +def test_list_vod_configs_rest_bad_request( + request_type=video_stitcher_service.ListVodConfigsRequest, +): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.get_vod_ad_tag_detail), "__call__" - ) as call: - call.return_value = ad_tag_details.VodAdTagDetail() - client.get_vod_ad_tag_detail(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetVodAdTagDetailRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_vod_configs(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_live_ad_tag_details_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.ListVodConfigsRequest, + dict, + ], +) +def test_list_vod_configs_rest_call_success(request_type): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.list_live_ad_tag_details), "__call__" - ) as call: - call.return_value = video_stitcher_service.ListLiveAdTagDetailsResponse() - client.list_live_ad_tag_details(request=None) + # send a request that will satisfy transcoding + request_init = {"parent": "projects/sample1/locations/sample2"} + request = request_type(**request_init) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListLiveAdTagDetailsRequest() + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = video_stitcher_service.ListVodConfigsResponse( + next_page_token="next_page_token_value", + unreachable=["unreachable_value"], + ) - assert args[0] == request_msg + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = video_stitcher_service.ListVodConfigsResponse.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_vod_configs(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_live_ad_tag_detail_empty_call_grpc(): - client = VideoStitcherServiceClient( + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListVodConfigsPager) + assert response.next_page_token == "next_page_token_value" + assert response.unreachable == ["unreachable_value"] + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_list_vod_configs_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.get_live_ad_tag_detail), "__call__" - ) as call: - call.return_value = ad_tag_details.LiveAdTagDetail() - client.get_live_ad_tag_detail(request=None) + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_list_vod_configs" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_list_vod_configs_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_list_vod_configs" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.ListVodConfigsRequest.pb( + video_stitcher_service.ListVodConfigsRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = video_stitcher_service.ListVodConfigsResponse.to_json( + video_stitcher_service.ListVodConfigsResponse() + ) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetLiveAdTagDetailRequest() + request = video_stitcher_service.ListVodConfigsRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = video_stitcher_service.ListVodConfigsResponse() + post_with_metadata.return_value = ( + video_stitcher_service.ListVodConfigsResponse(), + metadata, + ) - assert args[0] == request_msg + client.list_vod_configs( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_slate_empty_call_grpc(): + +def test_get_vod_config_rest_bad_request( + request_type=video_stitcher_service.GetVodConfigRequest, +): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/vodConfigs/sample3"} + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.create_slate), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_slate(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.CreateSlateRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_vod_config(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_slates_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.GetVodConfigRequest, + dict, + ], +) +def test_get_vod_config_rest_call_success(request_type): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_slates), "__call__") as call: - call.return_value = video_stitcher_service.ListSlatesResponse() - client.list_slates(request=None) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/vodConfigs/sample3"} + request = request_type(**request_init) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListSlatesRequest() + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = vod_configs.VodConfig( + name="name_value", + source_uri="source_uri_value", + ad_tag_uri="ad_tag_uri_value", + state=vod_configs.VodConfig.State.CREATING, + ) - assert args[0] == request_msg + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + # Convert return value to protobuf type + return_value = vod_configs.VodConfig.pb(return_value) + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_vod_config(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_slate_empty_call_grpc(): - client = VideoStitcherServiceClient( + # Establish that the response is the type that we expect. + assert isinstance(response, vod_configs.VodConfig) + assert response.name == "name_value" + assert response.source_uri == "source_uri_value" + assert response.ad_tag_uri == "ad_tag_uri_value" + assert response.state == vod_configs.VodConfig.State.CREATING + + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_get_vod_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_slate), "__call__") as call: - call.return_value = slates.Slate() - client.get_slate(request=None) + with mock.patch.object( + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_get_vod_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_get_vod_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_get_vod_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.GetVodConfigRequest.pb( + video_stitcher_service.GetVodConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = vod_configs.VodConfig.to_json(vod_configs.VodConfig()) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetSlateRequest() + request = video_stitcher_service.GetVodConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = vod_configs.VodConfig() + post_with_metadata.return_value = vod_configs.VodConfig(), metadata - assert args[0] == request_msg + client.get_vod_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_slate_empty_call_grpc(): + +def test_delete_vod_config_rest_bad_request( + request_type=video_stitcher_service.DeleteVodConfigRequest, +): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/vodConfigs/sample3"} + request = request_type(**request_init) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.update_slate), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_slate(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.UpdateSlateRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_vod_config(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_slate_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.DeleteVodConfigRequest, + dict, + ], +) +def test_delete_vod_config_rest_call_success(request_type): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.delete_slate), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_slate(request=None) + # send a request that will satisfy transcoding + request_init = {"name": "projects/sample1/locations/sample2/vodConfigs/sample3"} + request = request_type(**request_init) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.DeleteSlateRequest() + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") - assert args[0] == request_msg + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_vod_config(request) + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_live_session_empty_call_grpc(): - client = VideoStitcherServiceClient( + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_delete_vod_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.create_live_session), "__call__" - ) as call: - call.return_value = sessions.LiveSession() - client.create_live_session(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.CreateLiveSessionRequest() + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_delete_vod_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_delete_vod_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_delete_vod_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.DeleteVodConfigRequest.pb( + video_stitcher_service.DeleteVodConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value - assert args[0] == request_msg + request = video_stitcher_service.DeleteVodConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata + client.delete_vod_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_live_session_empty_call_grpc(): - client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", - ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_live_session), "__call__") as call: - call.return_value = sessions.LiveSession() - client.get_live_session(request=None) - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetLiveSessionRequest() +def test_update_vod_config_rest_bad_request( + request_type=video_stitcher_service.UpdateVodConfigRequest, +): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + # send a request that will satisfy transcoding + request_init = { + "vod_config": {"name": "projects/sample1/locations/sample2/vodConfigs/sample3"} + } + request = request_type(**request_init) - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = mock.Mock() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = mock.Mock() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.update_vod_config(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_live_config_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + video_stitcher_service.UpdateVodConfigRequest, + dict, + ], +) +def test_update_vod_config_rest_call_success(request_type): client = VideoStitcherServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_live_config), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_live_config(request=None) + # send a request that will satisfy transcoding + request_init = { + "vod_config": {"name": "projects/sample1/locations/sample2/vodConfigs/sample3"} + } + request_init["vod_config"] = { + "name": "projects/sample1/locations/sample2/vodConfigs/sample3", + "source_uri": "source_uri_value", + "ad_tag_uri": "ad_tag_uri_value", + "gam_vod_config": {"network_code": "network_code_value"}, + "state": 1, + "source_fetch_options": {"headers": {}}, + } + # The version of a generated dependency at test runtime may differ from the version used during generation. + # Delete any fields which are not present in the current runtime dependency + # See https://github.com/googleapis/gapic-generator-python/issues/1748 + + # Determine if the message type is proto-plus or protobuf + test_field = video_stitcher_service.UpdateVodConfigRequest.meta.fields["vod_config"] + + def get_message_fields(field): + # Given a field which is a message (composite type), return a list with + # all the fields of the message. + # If the field is not a composite type, return an empty list. + message_fields = [] + + if hasattr(field, "message") and field.message: + is_field_type_proto_plus_type = not hasattr(field.message, "DESCRIPTOR") + + if is_field_type_proto_plus_type: + message_fields = field.message.meta.fields.values() + # Add `# pragma: NO COVER` because there may not be any `*_pb2` field types + else: # pragma: NO COVER + message_fields = field.message.DESCRIPTOR.fields + return message_fields + + runtime_nested_fields = [ + (field.name, nested_field.name) + for field in get_message_fields(test_field) + for nested_field in get_message_fields(field) + ] - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.CreateLiveConfigRequest() + subfields_not_in_runtime = [] + + # For each item in the sample request, create a list of sub fields which are not present at runtime + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for field, value in request_init["vod_config"].items(): # pragma: NO COVER + result = None + is_repeated = False + # For repeated fields + if isinstance(value, list) and len(value): + is_repeated = True + result = value[0] + # For fields where the type is another message + if isinstance(value, dict): + result = value + + if result and hasattr(result, "keys"): + for subfield in result.keys(): + if (field, subfield) not in runtime_nested_fields: + subfields_not_in_runtime.append( + { + "field": field, + "subfield": subfield, + "is_repeated": is_repeated, + } + ) - assert args[0] == request_msg + # Remove fields from the sample request which are not present in the runtime version of the dependency + # Add `# pragma: NO COVER` because this test code will not run if all subfields are present at runtime + for subfield_to_delete in subfields_not_in_runtime: # pragma: NO COVER + field = subfield_to_delete.get("field") + field_repeated = subfield_to_delete.get("is_repeated") + subfield = subfield_to_delete.get("subfield") + if subfield: + if field_repeated: + for i in range(0, len(request_init["vod_config"][field])): + del request_init["vod_config"][field][i][subfield] + else: + del request_init["vod_config"][field][subfield] + request = request_type(**request_init) + + # Mock the http request call within the method and fake a response. + with mock.patch.object(type(client.transport._session), "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation(name="operations/spam") + + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.update_vod_config(request) + # Establish that the response is the type that we expect. + json_return_value = json_format.MessageToJson(return_value) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_live_configs_empty_call_grpc(): - client = VideoStitcherServiceClient( + +@pytest.mark.parametrize("null_interceptor", [True, False]) +def test_update_vod_config_rest_interceptors(null_interceptor): + transport = transports.VideoStitcherServiceRestTransport( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + interceptor=None + if null_interceptor + else transports.VideoStitcherServiceRestInterceptor(), ) + client = VideoStitcherServiceClient(transport=transport) - # Mock the actual call, and fake the request. with mock.patch.object( - type(client.transport.list_live_configs), "__call__" - ) as call: - call.return_value = video_stitcher_service.ListLiveConfigsResponse() - client.list_live_configs(request=None) + type(client.transport._session), "request" + ) as req, mock.patch.object( + path_template, "transcode" + ) as transcode, mock.patch.object( + operation.Operation, "_set_result_from_operation" + ), mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "post_update_vod_config" + ) as post, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, + "post_update_vod_config_with_metadata", + ) as post_with_metadata, mock.patch.object( + transports.VideoStitcherServiceRestInterceptor, "pre_update_vod_config" + ) as pre: + pre.assert_not_called() + post.assert_not_called() + post_with_metadata.assert_not_called() + pb_message = video_stitcher_service.UpdateVodConfigRequest.pb( + video_stitcher_service.UpdateVodConfigRequest() + ) + transcode.return_value = { + "method": "post", + "uri": "my_uri", + "body": pb_message, + "query_params": pb_message, + } + + req.return_value = mock.Mock() + req.return_value.status_code = 200 + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + return_value = json_format.MessageToJson(operations_pb2.Operation()) + req.return_value.content = return_value - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListLiveConfigsRequest() + request = video_stitcher_service.UpdateVodConfigRequest() + metadata = [ + ("key", "val"), + ("cephalopod", "squid"), + ] + pre.return_value = request, metadata + post.return_value = operations_pb2.Operation() + post_with_metadata.return_value = operations_pb2.Operation(), metadata - assert args[0] == request_msg + client.update_vod_config( + request, + metadata=[ + ("key", "val"), + ("cephalopod", "squid"), + ], + ) + pre.assert_called_once() + post.assert_called_once() + post_with_metadata.assert_called_once() -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_live_config_empty_call_grpc(): + +def test_cancel_operation_rest_bad_request( + request_type=operations_pb2.CancelOperationRequest, +): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", + ) + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_live_config), "__call__") as call: - call.return_value = live_configs.LiveConfig() - client.get_live_config(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetLiveConfigRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.cancel_operation(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_live_config_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.CancelOperationRequest, + dict, + ], +) +def test_cancel_operation_rest(request_type): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_live_config), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_live_config(request=None) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # Designate an appropriate value for the returned response. + return_value = None - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.DeleteLiveConfigRequest() + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = "{}" + response_value.content = json_return_value.encode("UTF-8") - assert args[0] == request_msg + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.cancel_operation(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_live_config_empty_call_grpc(): + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_rest_bad_request( + request_type=operations_pb2.DeleteOperationRequest, +): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", + ) + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_live_config), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_live_config(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.UpdateLiveConfigRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.delete_operation(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_create_vod_config_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.DeleteOperationRequest, + dict, + ], +) +def test_delete_operation_rest(request_type): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.create_vod_config), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.create_vod_config(request=None) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # Designate an appropriate value for the returned response. + return_value = None - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.CreateVodConfigRequest() + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = "{}" + response_value.content = json_return_value.encode("UTF-8") - assert args[0] == request_msg + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.delete_operation(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_list_vod_configs_empty_call_grpc(): + # Establish that the response is the type that we expect. + assert response is None + + +def test_get_operation_rest_bad_request( + request_type=operations_pb2.GetOperationRequest, +): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", + ) + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2/operations/sample3"}, request ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.list_vod_configs), "__call__") as call: - call.return_value = video_stitcher_service.ListVodConfigsResponse() - client.list_vod_configs(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.ListVodConfigsRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.get_operation(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_get_vod_config_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.GetOperationRequest, + dict, + ], +) +def test_get_operation_rest(request_type): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_vod_config), "__call__") as call: - call.return_value = vod_configs.VodConfig() - client.get_vod_config(request=None) + request_init = {"name": "projects/sample1/locations/sample2/operations/sample3"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.Operation() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.GetVodConfigRequest() + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") - assert args[0] == request_msg + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.get_operation(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_delete_vod_config_empty_call_grpc(): + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_list_operations_rest_bad_request( + request_type=operations_pb2.ListOperationsRequest, +): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", + ) + request = request_type() + request = json_format.ParseDict( + {"name": "projects/sample1/locations/sample2"}, request ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.delete_vod_config), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_vod_config(request=None) - - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.DeleteVodConfigRequest() - - assert args[0] == request_msg + # Mock the http request call within the method and fake a BadRequest error. + with mock.patch.object(Session, "request") as req, pytest.raises( + core_exceptions.BadRequest + ): + # Wrap the value into a proper Response obj + response_value = Response() + json_return_value = "" + response_value.json = mock.Mock(return_value={}) + response_value.status_code = 400 + response_value.request = Request() + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + client.list_operations(request) -# This test is a coverage failsafe to make sure that totally empty calls, -# i.e. request == None and no flattened fields passed, work. -def test_update_vod_config_empty_call_grpc(): +@pytest.mark.parametrize( + "request_type", + [ + operations_pb2.ListOperationsRequest, + dict, + ], +) +def test_list_operations_rest(request_type): client = VideoStitcherServiceClient( credentials=ga_credentials.AnonymousCredentials(), - transport="grpc", + transport="rest", ) - # Mock the actual call, and fake the request. - with mock.patch.object( - type(client.transport.update_vod_config), "__call__" - ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.update_vod_config(request=None) + request_init = {"name": "projects/sample1/locations/sample2"} + request = request_type(**request_init) + # Mock the http request call within the method and fake a response. + with mock.patch.object(Session, "request") as req: + # Designate an appropriate value for the returned response. + return_value = operations_pb2.ListOperationsResponse() - # Establish that the underlying stub method was called. - call.assert_called() - _, args, _ = call.mock_calls[0] - request_msg = video_stitcher_service.UpdateVodConfigRequest() + # Wrap the value into a proper Response obj + response_value = mock.Mock() + response_value.status_code = 200 + json_return_value = json_format.MessageToJson(return_value) + response_value.content = json_return_value.encode("UTF-8") - assert args[0] == request_msg + req.return_value = response_value + req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"} + response = client.list_operations(request) -def test_transport_kind_grpc_asyncio(): - transport = VideoStitcherServiceAsyncClient.get_transport_class("grpc_asyncio")( - credentials=async_anonymous_credentials() - ) - assert transport.kind == "grpc_asyncio" + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) -def test_initialize_client_w_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), transport="grpc_asyncio" +def test_initialize_client_w_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" ) assert client is not None # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_cdn_key_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_cdn_key_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.create_cdn_key), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_cdn_key(request=None) + client.create_cdn_key(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13698,23 +25846,15 @@ async def test_create_cdn_key_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_cdn_keys_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_cdn_keys_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.list_cdn_keys), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListCdnKeysResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_cdn_keys(request=None) + client.list_cdn_keys(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13726,23 +25866,15 @@ async def test_list_cdn_keys_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_cdn_key_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_cdn_key_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.get_cdn_key), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - cdn_keys.CdnKey( - name="name_value", - hostname="hostname_value", - ) - ) - await client.get_cdn_key(request=None) + client.get_cdn_key(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13754,20 +25886,15 @@ async def test_get_cdn_key_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_cdn_key_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_delete_cdn_key_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.delete_cdn_key), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_cdn_key(request=None) + client.delete_cdn_key(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13779,20 +25906,15 @@ async def test_delete_cdn_key_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_cdn_key_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_update_cdn_key_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.update_cdn_key), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_cdn_key(request=None) + client.update_cdn_key(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13804,30 +25926,17 @@ async def test_update_cdn_key_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_vod_session_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_vod_session_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.create_vod_session), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - sessions.VodSession( - name="name_value", - play_uri="play_uri_value", - source_uri="source_uri_value", - ad_tag_uri="ad_tag_uri_value", - asset_id="asset_id_value", - ad_tracking=live_configs.AdTracking.CLIENT, - vod_config="vod_config_value", - ) - ) - await client.create_vod_session(request=None) + client.create_vod_session(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13839,28 +25948,15 @@ async def test_create_vod_session_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_vod_session_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_vod_session_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.get_vod_session), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - sessions.VodSession( - name="name_value", - play_uri="play_uri_value", - source_uri="source_uri_value", - ad_tag_uri="ad_tag_uri_value", - asset_id="asset_id_value", - ad_tracking=live_configs.AdTracking.CLIENT, - vod_config="vod_config_value", - ) - ) - await client.get_vod_session(request=None) + client.get_vod_session(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13872,24 +25968,17 @@ async def test_get_vod_session_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_vod_stitch_details_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_vod_stitch_details_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.list_vod_stitch_details), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListVodStitchDetailsResponse( - next_page_token="next_page_token_value", - ) - ) - await client.list_vod_stitch_details(request=None) + client.list_vod_stitch_details(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13901,24 +25990,17 @@ async def test_list_vod_stitch_details_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_vod_stitch_detail_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_vod_stitch_detail_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.get_vod_stitch_detail), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - stitch_details.VodStitchDetail( - name="name_value", - ) - ) - await client.get_vod_stitch_detail(request=None) + client.get_vod_stitch_detail(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13930,24 +26012,17 @@ async def test_get_vod_stitch_detail_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_vod_ad_tag_details_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_vod_ad_tag_details_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.list_vod_ad_tag_details), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListVodAdTagDetailsResponse( - next_page_token="next_page_token_value", - ) - ) - await client.list_vod_ad_tag_details(request=None) + client.list_vod_ad_tag_details(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13959,24 +26034,17 @@ async def test_list_vod_ad_tag_details_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_vod_ad_tag_detail_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_vod_ad_tag_detail_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.get_vod_ad_tag_detail), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - ad_tag_details.VodAdTagDetail( - name="name_value", - ) - ) - await client.get_vod_ad_tag_detail(request=None) + client.get_vod_ad_tag_detail(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -13988,24 +26056,17 @@ async def test_get_vod_ad_tag_detail_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_live_ad_tag_details_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_live_ad_tag_details_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.list_live_ad_tag_details), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListLiveAdTagDetailsResponse( - next_page_token="next_page_token_value", - ) - ) - await client.list_live_ad_tag_details(request=None) + client.list_live_ad_tag_details(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14017,24 +26078,17 @@ async def test_list_live_ad_tag_details_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_live_ad_tag_detail_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_live_ad_tag_detail_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.get_live_ad_tag_detail), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - ad_tag_details.LiveAdTagDetail( - name="name_value", - ) - ) - await client.get_live_ad_tag_detail(request=None) + client.get_live_ad_tag_detail(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14046,20 +26100,15 @@ async def test_get_live_ad_tag_detail_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_slate_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_slate_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.create_slate), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_slate(request=None) + client.create_slate(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14071,23 +26120,15 @@ async def test_create_slate_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_slates_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_slates_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.list_slates), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListSlatesResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_slates(request=None) + client.list_slates(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14099,23 +26140,15 @@ async def test_list_slates_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_slate_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", - ) - - # Mock the actual call, and fake the request. - with mock.patch.object(type(client.transport.get_slate), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - slates.Slate( - name="name_value", - uri="uri_value", - ) - ) - await client.get_slate(request=None) +def test_get_slate_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object(type(client.transport.get_slate), "__call__") as call: + client.get_slate(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14127,20 +26160,15 @@ async def test_get_slate_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_slate_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_update_slate_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.update_slate), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_slate(request=None) + client.update_slate(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14152,20 +26180,15 @@ async def test_update_slate_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_slate_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_delete_slate_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.delete_slate), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_slate(request=None) + client.delete_slate(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14177,27 +26200,17 @@ async def test_delete_slate_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_live_session_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_live_session_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.create_live_session), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - sessions.LiveSession( - name="name_value", - play_uri="play_uri_value", - live_config="live_config_value", - ad_tracking=live_configs.AdTracking.CLIENT, - ) - ) - await client.create_live_session(request=None) + client.create_live_session(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14209,25 +26222,15 @@ async def test_create_live_session_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_live_session_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_live_session_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.get_live_session), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - sessions.LiveSession( - name="name_value", - play_uri="play_uri_value", - live_config="live_config_value", - ad_tracking=live_configs.AdTracking.CLIENT, - ) - ) - await client.get_live_session(request=None) + client.get_live_session(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14239,22 +26242,17 @@ async def test_get_live_session_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_live_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_live_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.create_live_config), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_live_config(request=None) + client.create_live_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14266,25 +26264,17 @@ async def test_create_live_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_live_configs_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_live_configs_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.list_live_configs), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListLiveConfigsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_live_configs(request=None) + client.list_live_configs(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14296,28 +26286,15 @@ async def test_list_live_configs_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_live_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_live_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.get_live_config), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - live_configs.LiveConfig( - name="name_value", - source_uri="source_uri_value", - ad_tag_uri="ad_tag_uri_value", - state=live_configs.LiveConfig.State.CREATING, - ad_tracking=live_configs.AdTracking.CLIENT, - default_slate="default_slate_value", - stitching_policy=live_configs.LiveConfig.StitchingPolicy.CUT_CURRENT, - ) - ) - await client.get_live_config(request=None) + client.get_live_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14329,22 +26306,17 @@ async def test_get_live_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_live_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_delete_live_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.delete_live_config), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_live_config(request=None) + client.delete_live_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14356,22 +26328,17 @@ async def test_delete_live_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_live_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_update_live_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.update_live_config), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_live_config(request=None) + client.update_live_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14383,22 +26350,17 @@ async def test_update_live_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_create_vod_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_create_vod_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.create_vod_config), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.create_vod_config(request=None) + client.create_vod_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14410,23 +26372,15 @@ async def test_create_vod_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_list_vod_configs_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_list_vod_configs_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.list_vod_configs), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - video_stitcher_service.ListVodConfigsResponse( - next_page_token="next_page_token_value", - unreachable=["unreachable_value"], - ) - ) - await client.list_vod_configs(request=None) + client.list_vod_configs(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14438,25 +26392,15 @@ async def test_list_vod_configs_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_get_vod_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_get_vod_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object(type(client.transport.get_vod_config), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - vod_configs.VodConfig( - name="name_value", - source_uri="source_uri_value", - ad_tag_uri="ad_tag_uri_value", - state=vod_configs.VodConfig.State.CREATING, - ) - ) - await client.get_vod_config(request=None) + client.get_vod_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14468,22 +26412,17 @@ async def test_get_vod_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_delete_vod_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_delete_vod_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.delete_vod_config), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.delete_vod_config(request=None) + client.delete_vod_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14495,22 +26434,17 @@ async def test_delete_vod_config_empty_call_grpc_asyncio(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. -@pytest.mark.asyncio -async def test_update_vod_config_empty_call_grpc_asyncio(): - client = VideoStitcherServiceAsyncClient( - credentials=async_anonymous_credentials(), - transport="grpc_asyncio", +def test_update_vod_config_empty_call_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", ) # Mock the actual call, and fake the request. with mock.patch.object( type(client.transport.update_vod_config), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - await client.update_vod_config(request=None) + client.update_vod_config(request=None) # Establish that the underlying stub method was called. call.assert_called() @@ -14520,6 +26454,23 @@ async def test_update_vod_config_empty_call_grpc_asyncio(): assert args[0] == request_msg +def test_video_stitcher_service_rest_lro_client(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="rest", + ) + transport = client.transport + + # Ensure that we have an api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.AbstractOperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = VideoStitcherServiceClient( @@ -14678,6 +26629,7 @@ def test_video_stitcher_service_transport_auth_adc(transport_class): [ transports.VideoStitcherServiceGrpcTransport, transports.VideoStitcherServiceGrpcAsyncIOTransport, + transports.VideoStitcherServiceRestTransport, ], ) def test_video_stitcher_service_transport_auth_gdch_credentials(transport_class): @@ -14777,11 +26729,23 @@ def test_video_stitcher_service_grpc_transport_client_cert_source_for_mtls( ) +def test_video_stitcher_service_http_transport_client_cert_source_for_mtls(): + cred = ga_credentials.AnonymousCredentials() + with mock.patch( + "google.auth.transport.requests.AuthorizedSession.configure_mtls_channel" + ) as mock_configure_mtls_channel: + transports.VideoStitcherServiceRestTransport( + credentials=cred, client_cert_source_for_mtls=client_cert_source_callback + ) + mock_configure_mtls_channel.assert_called_once_with(client_cert_source_callback) + + @pytest.mark.parametrize( "transport_name", [ "grpc", "grpc_asyncio", + "rest", ], ) def test_video_stitcher_service_host_no_port(transport_name): @@ -14792,7 +26756,11 @@ def test_video_stitcher_service_host_no_port(transport_name): ), transport=transport_name, ) - assert client.transport._host == ("videostitcher.googleapis.com:443") + assert client.transport._host == ( + "videostitcher.googleapis.com:443" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://videostitcher.googleapis.com" + ) @pytest.mark.parametrize( @@ -14800,6 +26768,7 @@ def test_video_stitcher_service_host_no_port(transport_name): [ "grpc", "grpc_asyncio", + "rest", ], ) def test_video_stitcher_service_host_with_port(transport_name): @@ -14810,7 +26779,120 @@ def test_video_stitcher_service_host_with_port(transport_name): ), transport=transport_name, ) - assert client.transport._host == ("videostitcher.googleapis.com:8000") + assert client.transport._host == ( + "videostitcher.googleapis.com:8000" + if transport_name in ["grpc", "grpc_asyncio"] + else "https://videostitcher.googleapis.com:8000" + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "rest", + ], +) +def test_video_stitcher_service_client_transport_session_collision(transport_name): + creds1 = ga_credentials.AnonymousCredentials() + creds2 = ga_credentials.AnonymousCredentials() + client1 = VideoStitcherServiceClient( + credentials=creds1, + transport=transport_name, + ) + client2 = VideoStitcherServiceClient( + credentials=creds2, + transport=transport_name, + ) + session1 = client1.transport.create_cdn_key._session + session2 = client2.transport.create_cdn_key._session + assert session1 != session2 + session1 = client1.transport.list_cdn_keys._session + session2 = client2.transport.list_cdn_keys._session + assert session1 != session2 + session1 = client1.transport.get_cdn_key._session + session2 = client2.transport.get_cdn_key._session + assert session1 != session2 + session1 = client1.transport.delete_cdn_key._session + session2 = client2.transport.delete_cdn_key._session + assert session1 != session2 + session1 = client1.transport.update_cdn_key._session + session2 = client2.transport.update_cdn_key._session + assert session1 != session2 + session1 = client1.transport.create_vod_session._session + session2 = client2.transport.create_vod_session._session + assert session1 != session2 + session1 = client1.transport.get_vod_session._session + session2 = client2.transport.get_vod_session._session + assert session1 != session2 + session1 = client1.transport.list_vod_stitch_details._session + session2 = client2.transport.list_vod_stitch_details._session + assert session1 != session2 + session1 = client1.transport.get_vod_stitch_detail._session + session2 = client2.transport.get_vod_stitch_detail._session + assert session1 != session2 + session1 = client1.transport.list_vod_ad_tag_details._session + session2 = client2.transport.list_vod_ad_tag_details._session + assert session1 != session2 + session1 = client1.transport.get_vod_ad_tag_detail._session + session2 = client2.transport.get_vod_ad_tag_detail._session + assert session1 != session2 + session1 = client1.transport.list_live_ad_tag_details._session + session2 = client2.transport.list_live_ad_tag_details._session + assert session1 != session2 + session1 = client1.transport.get_live_ad_tag_detail._session + session2 = client2.transport.get_live_ad_tag_detail._session + assert session1 != session2 + session1 = client1.transport.create_slate._session + session2 = client2.transport.create_slate._session + assert session1 != session2 + session1 = client1.transport.list_slates._session + session2 = client2.transport.list_slates._session + assert session1 != session2 + session1 = client1.transport.get_slate._session + session2 = client2.transport.get_slate._session + assert session1 != session2 + session1 = client1.transport.update_slate._session + session2 = client2.transport.update_slate._session + assert session1 != session2 + session1 = client1.transport.delete_slate._session + session2 = client2.transport.delete_slate._session + assert session1 != session2 + session1 = client1.transport.create_live_session._session + session2 = client2.transport.create_live_session._session + assert session1 != session2 + session1 = client1.transport.get_live_session._session + session2 = client2.transport.get_live_session._session + assert session1 != session2 + session1 = client1.transport.create_live_config._session + session2 = client2.transport.create_live_config._session + assert session1 != session2 + session1 = client1.transport.list_live_configs._session + session2 = client2.transport.list_live_configs._session + assert session1 != session2 + session1 = client1.transport.get_live_config._session + session2 = client2.transport.get_live_config._session + assert session1 != session2 + session1 = client1.transport.delete_live_config._session + session2 = client2.transport.delete_live_config._session + assert session1 != session2 + session1 = client1.transport.update_live_config._session + session2 = client2.transport.update_live_config._session + assert session1 != session2 + session1 = client1.transport.create_vod_config._session + session2 = client2.transport.create_vod_config._session + assert session1 != session2 + session1 = client1.transport.list_vod_configs._session + session2 = client2.transport.list_vod_configs._session + assert session1 != session2 + session1 = client1.transport.get_vod_config._session + session2 = client2.transport.get_vod_config._session + assert session1 != session2 + session1 = client1.transport.delete_vod_config._session + session2 = client2.transport.delete_vod_config._session + assert session1 != session2 + session1 = client1.transport.update_vod_config._session + session2 = client2.transport.update_vod_config._session + assert session1 != session2 def test_video_stitcher_service_grpc_transport_channel(): @@ -15949,8 +28031,21 @@ async def test_transport_close_grpc_asyncio(): close.assert_called_once() +def test_transport_close_rest(): + client = VideoStitcherServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport="rest" + ) + with mock.patch.object( + type(getattr(client.transport, "_session")), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + def test_client_ctx(): transports = [ + "rest", "grpc", ] for transport in transports: