1# -*- coding: utf-8 -*-
2# Copyright 2020 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import os
17import mock
18
19import grpc
20from grpc.experimental import aio
21import math
22import pytest
23from proto.marshal.rules.dates import DurationRule, TimestampRule
24
25
26from google.api_core import client_options
27from google.api_core import exceptions as core_exceptions
28from google.api_core import gapic_v1
29from google.api_core import grpc_helpers
30from google.api_core import grpc_helpers_async
31from google.api_core import path_template
32from google.auth import credentials as ga_credentials
33from google.auth.exceptions import MutualTLSChannelError
34from google.cloud.logging_v2.services.config_service_v2 import (
35    ConfigServiceV2AsyncClient,
36)
37from google.cloud.logging_v2.services.config_service_v2 import ConfigServiceV2Client
38from google.cloud.logging_v2.services.config_service_v2 import pagers
39from google.cloud.logging_v2.services.config_service_v2 import transports
40from google.cloud.logging_v2.types import logging_config
41from google.oauth2 import service_account
42from google.protobuf import field_mask_pb2  # type: ignore
43from google.protobuf import timestamp_pb2  # type: ignore
44import google.auth
45
46
47def client_cert_source_callback():
48    return b"cert bytes", b"key bytes"
49
50
51# If default endpoint is localhost, then default mtls endpoint will be the same.
52# This method modifies the default endpoint so the client can produce a different
53# mtls endpoint for endpoint testing purposes.
54def modify_default_endpoint(client):
55    return (
56        "foo.googleapis.com"
57        if ("localhost" in client.DEFAULT_ENDPOINT)
58        else client.DEFAULT_ENDPOINT
59    )
60
61
62def test__get_default_mtls_endpoint():
63    api_endpoint = "example.googleapis.com"
64    api_mtls_endpoint = "example.mtls.googleapis.com"
65    sandbox_endpoint = "example.sandbox.googleapis.com"
66    sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com"
67    non_googleapi = "api.example.com"
68
69    assert ConfigServiceV2Client._get_default_mtls_endpoint(None) is None
70    assert (
71        ConfigServiceV2Client._get_default_mtls_endpoint(api_endpoint)
72        == api_mtls_endpoint
73    )
74    assert (
75        ConfigServiceV2Client._get_default_mtls_endpoint(api_mtls_endpoint)
76        == api_mtls_endpoint
77    )
78    assert (
79        ConfigServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint)
80        == sandbox_mtls_endpoint
81    )
82    assert (
83        ConfigServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint)
84        == sandbox_mtls_endpoint
85    )
86    assert (
87        ConfigServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi
88    )
89
90
91@pytest.mark.parametrize(
92    "client_class", [ConfigServiceV2Client, ConfigServiceV2AsyncClient,]
93)
94def test_config_service_v2_client_from_service_account_info(client_class):
95    creds = ga_credentials.AnonymousCredentials()
96    with mock.patch.object(
97        service_account.Credentials, "from_service_account_info"
98    ) as factory:
99        factory.return_value = creds
100        info = {"valid": True}
101        client = client_class.from_service_account_info(info)
102        assert client.transport._credentials == creds
103        assert isinstance(client, client_class)
104
105        assert client.transport._host == "logging.googleapis.com:443"
106
107
108@pytest.mark.parametrize(
109    "transport_class,transport_name",
110    [
111        (transports.ConfigServiceV2GrpcTransport, "grpc"),
112        (transports.ConfigServiceV2GrpcAsyncIOTransport, "grpc_asyncio"),
113    ],
114)
115def test_config_service_v2_client_service_account_always_use_jwt(
116    transport_class, transport_name
117):
118    with mock.patch.object(
119        service_account.Credentials, "with_always_use_jwt_access", create=True
120    ) as use_jwt:
121        creds = service_account.Credentials(None, None, None)
122        transport = transport_class(credentials=creds, always_use_jwt_access=True)
123        use_jwt.assert_called_once_with(True)
124
125    with mock.patch.object(
126        service_account.Credentials, "with_always_use_jwt_access", create=True
127    ) as use_jwt:
128        creds = service_account.Credentials(None, None, None)
129        transport = transport_class(credentials=creds, always_use_jwt_access=False)
130        use_jwt.assert_not_called()
131
132
133@pytest.mark.parametrize(
134    "client_class", [ConfigServiceV2Client, ConfigServiceV2AsyncClient,]
135)
136def test_config_service_v2_client_from_service_account_file(client_class):
137    creds = ga_credentials.AnonymousCredentials()
138    with mock.patch.object(
139        service_account.Credentials, "from_service_account_file"
140    ) as factory:
141        factory.return_value = creds
142        client = client_class.from_service_account_file("dummy/file/path.json")
143        assert client.transport._credentials == creds
144        assert isinstance(client, client_class)
145
146        client = client_class.from_service_account_json("dummy/file/path.json")
147        assert client.transport._credentials == creds
148        assert isinstance(client, client_class)
149
150        assert client.transport._host == "logging.googleapis.com:443"
151
152
153def test_config_service_v2_client_get_transport_class():
154    transport = ConfigServiceV2Client.get_transport_class()
155    available_transports = [
156        transports.ConfigServiceV2GrpcTransport,
157    ]
158    assert transport in available_transports
159
160    transport = ConfigServiceV2Client.get_transport_class("grpc")
161    assert transport == transports.ConfigServiceV2GrpcTransport
162
163
164@pytest.mark.parametrize(
165    "client_class,transport_class,transport_name",
166    [
167        (ConfigServiceV2Client, transports.ConfigServiceV2GrpcTransport, "grpc"),
168        (
169            ConfigServiceV2AsyncClient,
170            transports.ConfigServiceV2GrpcAsyncIOTransport,
171            "grpc_asyncio",
172        ),
173    ],
174)
175@mock.patch.object(
176    ConfigServiceV2Client,
177    "DEFAULT_ENDPOINT",
178    modify_default_endpoint(ConfigServiceV2Client),
179)
180@mock.patch.object(
181    ConfigServiceV2AsyncClient,
182    "DEFAULT_ENDPOINT",
183    modify_default_endpoint(ConfigServiceV2AsyncClient),
184)
185def test_config_service_v2_client_client_options(
186    client_class, transport_class, transport_name
187):
188    # Check that if channel is provided we won't create a new one.
189    with mock.patch.object(ConfigServiceV2Client, "get_transport_class") as gtc:
190        transport = transport_class(credentials=ga_credentials.AnonymousCredentials())
191        client = client_class(transport=transport)
192        gtc.assert_not_called()
193
194    # Check that if channel is provided via str we will create a new one.
195    with mock.patch.object(ConfigServiceV2Client, "get_transport_class") as gtc:
196        client = client_class(transport=transport_name)
197        gtc.assert_called()
198
199    # Check the case api_endpoint is provided.
200    options = client_options.ClientOptions(api_endpoint="squid.clam.whelk")
201    with mock.patch.object(transport_class, "__init__") as patched:
202        patched.return_value = None
203        client = client_class(transport=transport_name, client_options=options)
204        patched.assert_called_once_with(
205            credentials=None,
206            credentials_file=None,
207            host="squid.clam.whelk",
208            scopes=None,
209            client_cert_source_for_mtls=None,
210            quota_project_id=None,
211            client_info=transports.base.DEFAULT_CLIENT_INFO,
212            always_use_jwt_access=True,
213        )
214
215    # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
216    # "never".
217    with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}):
218        with mock.patch.object(transport_class, "__init__") as patched:
219            patched.return_value = None
220            client = client_class(transport=transport_name)
221            patched.assert_called_once_with(
222                credentials=None,
223                credentials_file=None,
224                host=client.DEFAULT_ENDPOINT,
225                scopes=None,
226                client_cert_source_for_mtls=None,
227                quota_project_id=None,
228                client_info=transports.base.DEFAULT_CLIENT_INFO,
229                always_use_jwt_access=True,
230            )
231
232    # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is
233    # "always".
234    with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}):
235        with mock.patch.object(transport_class, "__init__") as patched:
236            patched.return_value = None
237            client = client_class(transport=transport_name)
238            patched.assert_called_once_with(
239                credentials=None,
240                credentials_file=None,
241                host=client.DEFAULT_MTLS_ENDPOINT,
242                scopes=None,
243                client_cert_source_for_mtls=None,
244                quota_project_id=None,
245                client_info=transports.base.DEFAULT_CLIENT_INFO,
246                always_use_jwt_access=True,
247            )
248
249    # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has
250    # unsupported value.
251    with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}):
252        with pytest.raises(MutualTLSChannelError):
253            client = client_class()
254
255    # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value.
256    with mock.patch.dict(
257        os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"}
258    ):
259        with pytest.raises(ValueError):
260            client = client_class()
261
262    # Check the case quota_project_id is provided
263    options = client_options.ClientOptions(quota_project_id="octopus")
264    with mock.patch.object(transport_class, "__init__") as patched:
265        patched.return_value = None
266        client = client_class(transport=transport_name, client_options=options)
267        patched.assert_called_once_with(
268            credentials=None,
269            credentials_file=None,
270            host=client.DEFAULT_ENDPOINT,
271            scopes=None,
272            client_cert_source_for_mtls=None,
273            quota_project_id="octopus",
274            client_info=transports.base.DEFAULT_CLIENT_INFO,
275            always_use_jwt_access=True,
276        )
277
278
279@pytest.mark.parametrize(
280    "client_class,transport_class,transport_name,use_client_cert_env",
281    [
282        (
283            ConfigServiceV2Client,
284            transports.ConfigServiceV2GrpcTransport,
285            "grpc",
286            "true",
287        ),
288        (
289            ConfigServiceV2AsyncClient,
290            transports.ConfigServiceV2GrpcAsyncIOTransport,
291            "grpc_asyncio",
292            "true",
293        ),
294        (
295            ConfigServiceV2Client,
296            transports.ConfigServiceV2GrpcTransport,
297            "grpc",
298            "false",
299        ),
300        (
301            ConfigServiceV2AsyncClient,
302            transports.ConfigServiceV2GrpcAsyncIOTransport,
303            "grpc_asyncio",
304            "false",
305        ),
306    ],
307)
308@mock.patch.object(
309    ConfigServiceV2Client,
310    "DEFAULT_ENDPOINT",
311    modify_default_endpoint(ConfigServiceV2Client),
312)
313@mock.patch.object(
314    ConfigServiceV2AsyncClient,
315    "DEFAULT_ENDPOINT",
316    modify_default_endpoint(ConfigServiceV2AsyncClient),
317)
318@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"})
319def test_config_service_v2_client_mtls_env_auto(
320    client_class, transport_class, transport_name, use_client_cert_env
321):
322    # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default
323    # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists.
324
325    # Check the case client_cert_source is provided. Whether client cert is used depends on
326    # GOOGLE_API_USE_CLIENT_CERTIFICATE value.
327    with mock.patch.dict(
328        os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}
329    ):
330        options = client_options.ClientOptions(
331            client_cert_source=client_cert_source_callback
332        )
333        with mock.patch.object(transport_class, "__init__") as patched:
334            patched.return_value = None
335            client = client_class(transport=transport_name, client_options=options)
336
337            if use_client_cert_env == "false":
338                expected_client_cert_source = None
339                expected_host = client.DEFAULT_ENDPOINT
340            else:
341                expected_client_cert_source = client_cert_source_callback
342                expected_host = client.DEFAULT_MTLS_ENDPOINT
343
344            patched.assert_called_once_with(
345                credentials=None,
346                credentials_file=None,
347                host=expected_host,
348                scopes=None,
349                client_cert_source_for_mtls=expected_client_cert_source,
350                quota_project_id=None,
351                client_info=transports.base.DEFAULT_CLIENT_INFO,
352                always_use_jwt_access=True,
353            )
354
355    # Check the case ADC client cert is provided. Whether client cert is used depends on
356    # GOOGLE_API_USE_CLIENT_CERTIFICATE value.
357    with mock.patch.dict(
358        os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}
359    ):
360        with mock.patch.object(transport_class, "__init__") as patched:
361            with mock.patch(
362                "google.auth.transport.mtls.has_default_client_cert_source",
363                return_value=True,
364            ):
365                with mock.patch(
366                    "google.auth.transport.mtls.default_client_cert_source",
367                    return_value=client_cert_source_callback,
368                ):
369                    if use_client_cert_env == "false":
370                        expected_host = client.DEFAULT_ENDPOINT
371                        expected_client_cert_source = None
372                    else:
373                        expected_host = client.DEFAULT_MTLS_ENDPOINT
374                        expected_client_cert_source = client_cert_source_callback
375
376                    patched.return_value = None
377                    client = client_class(transport=transport_name)
378                    patched.assert_called_once_with(
379                        credentials=None,
380                        credentials_file=None,
381                        host=expected_host,
382                        scopes=None,
383                        client_cert_source_for_mtls=expected_client_cert_source,
384                        quota_project_id=None,
385                        client_info=transports.base.DEFAULT_CLIENT_INFO,
386                        always_use_jwt_access=True,
387                    )
388
389    # Check the case client_cert_source and ADC client cert are not provided.
390    with mock.patch.dict(
391        os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env}
392    ):
393        with mock.patch.object(transport_class, "__init__") as patched:
394            with mock.patch(
395                "google.auth.transport.mtls.has_default_client_cert_source",
396                return_value=False,
397            ):
398                patched.return_value = None
399                client = client_class(transport=transport_name)
400                patched.assert_called_once_with(
401                    credentials=None,
402                    credentials_file=None,
403                    host=client.DEFAULT_ENDPOINT,
404                    scopes=None,
405                    client_cert_source_for_mtls=None,
406                    quota_project_id=None,
407                    client_info=transports.base.DEFAULT_CLIENT_INFO,
408                    always_use_jwt_access=True,
409                )
410
411
412@pytest.mark.parametrize(
413    "client_class,transport_class,transport_name",
414    [
415        (ConfigServiceV2Client, transports.ConfigServiceV2GrpcTransport, "grpc"),
416        (
417            ConfigServiceV2AsyncClient,
418            transports.ConfigServiceV2GrpcAsyncIOTransport,
419            "grpc_asyncio",
420        ),
421    ],
422)
423def test_config_service_v2_client_client_options_scopes(
424    client_class, transport_class, transport_name
425):
426    # Check the case scopes are provided.
427    options = client_options.ClientOptions(scopes=["1", "2"],)
428    with mock.patch.object(transport_class, "__init__") as patched:
429        patched.return_value = None
430        client = client_class(transport=transport_name, client_options=options)
431        patched.assert_called_once_with(
432            credentials=None,
433            credentials_file=None,
434            host=client.DEFAULT_ENDPOINT,
435            scopes=["1", "2"],
436            client_cert_source_for_mtls=None,
437            quota_project_id=None,
438            client_info=transports.base.DEFAULT_CLIENT_INFO,
439            always_use_jwt_access=True,
440        )
441
442
443@pytest.mark.parametrize(
444    "client_class,transport_class,transport_name",
445    [
446        (ConfigServiceV2Client, transports.ConfigServiceV2GrpcTransport, "grpc"),
447        (
448            ConfigServiceV2AsyncClient,
449            transports.ConfigServiceV2GrpcAsyncIOTransport,
450            "grpc_asyncio",
451        ),
452    ],
453)
454def test_config_service_v2_client_client_options_credentials_file(
455    client_class, transport_class, transport_name
456):
457    # Check the case credentials file is provided.
458    options = client_options.ClientOptions(credentials_file="credentials.json")
459    with mock.patch.object(transport_class, "__init__") as patched:
460        patched.return_value = None
461        client = client_class(transport=transport_name, client_options=options)
462        patched.assert_called_once_with(
463            credentials=None,
464            credentials_file="credentials.json",
465            host=client.DEFAULT_ENDPOINT,
466            scopes=None,
467            client_cert_source_for_mtls=None,
468            quota_project_id=None,
469            client_info=transports.base.DEFAULT_CLIENT_INFO,
470            always_use_jwt_access=True,
471        )
472
473
474def test_config_service_v2_client_client_options_from_dict():
475    with mock.patch(
476        "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2GrpcTransport.__init__"
477    ) as grpc_transport:
478        grpc_transport.return_value = None
479        client = ConfigServiceV2Client(
480            client_options={"api_endpoint": "squid.clam.whelk"}
481        )
482        grpc_transport.assert_called_once_with(
483            credentials=None,
484            credentials_file=None,
485            host="squid.clam.whelk",
486            scopes=None,
487            client_cert_source_for_mtls=None,
488            quota_project_id=None,
489            client_info=transports.base.DEFAULT_CLIENT_INFO,
490            always_use_jwt_access=True,
491        )
492
493
494def test_list_buckets(
495    transport: str = "grpc", request_type=logging_config.ListBucketsRequest
496):
497    client = ConfigServiceV2Client(
498        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
499    )
500
501    # Everything is optional in proto3 as far as the runtime is concerned,
502    # and we are mocking out the actual API, so just send an empty request.
503    request = request_type()
504
505    # Mock the actual call within the gRPC stub, and fake the request.
506    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
507        # Designate an appropriate return value for the call.
508        call.return_value = logging_config.ListBucketsResponse(
509            next_page_token="next_page_token_value",
510        )
511        response = client.list_buckets(request)
512
513        # Establish that the underlying gRPC stub method was called.
514        assert len(call.mock_calls) == 1
515        _, args, _ = call.mock_calls[0]
516        assert args[0] == logging_config.ListBucketsRequest()
517
518    # Establish that the response is the type that we expect.
519    assert isinstance(response, pagers.ListBucketsPager)
520    assert response.next_page_token == "next_page_token_value"
521
522
523def test_list_buckets_from_dict():
524    test_list_buckets(request_type=dict)
525
526
527def test_list_buckets_empty_call():
528    # This test is a coverage failsafe to make sure that totally empty calls,
529    # i.e. request == None and no flattened fields passed, work.
530    client = ConfigServiceV2Client(
531        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
532    )
533
534    # Mock the actual call within the gRPC stub, and fake the request.
535    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
536        client.list_buckets()
537        call.assert_called()
538        _, args, _ = call.mock_calls[0]
539        assert args[0] == logging_config.ListBucketsRequest()
540
541
542@pytest.mark.asyncio
543async def test_list_buckets_async(
544    transport: str = "grpc_asyncio", request_type=logging_config.ListBucketsRequest
545):
546    client = ConfigServiceV2AsyncClient(
547        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
548    )
549
550    # Everything is optional in proto3 as far as the runtime is concerned,
551    # and we are mocking out the actual API, so just send an empty request.
552    request = request_type()
553
554    # Mock the actual call within the gRPC stub, and fake the request.
555    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
556        # Designate an appropriate return value for the call.
557        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
558            logging_config.ListBucketsResponse(next_page_token="next_page_token_value",)
559        )
560        response = await client.list_buckets(request)
561
562        # Establish that the underlying gRPC stub method was called.
563        assert len(call.mock_calls)
564        _, args, _ = call.mock_calls[0]
565        assert args[0] == logging_config.ListBucketsRequest()
566
567    # Establish that the response is the type that we expect.
568    assert isinstance(response, pagers.ListBucketsAsyncPager)
569    assert response.next_page_token == "next_page_token_value"
570
571
572@pytest.mark.asyncio
573async def test_list_buckets_async_from_dict():
574    await test_list_buckets_async(request_type=dict)
575
576
577def test_list_buckets_field_headers():
578    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
579
580    # Any value that is part of the HTTP/1.1 URI should be sent as
581    # a field header. Set these to a non-empty value.
582    request = logging_config.ListBucketsRequest()
583
584    request.parent = "parent/value"
585
586    # Mock the actual call within the gRPC stub, and fake the request.
587    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
588        call.return_value = logging_config.ListBucketsResponse()
589        client.list_buckets(request)
590
591        # Establish that the underlying gRPC stub method was called.
592        assert len(call.mock_calls) == 1
593        _, args, _ = call.mock_calls[0]
594        assert args[0] == request
595
596    # Establish that the field header was sent.
597    _, _, kw = call.mock_calls[0]
598    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
599
600
601@pytest.mark.asyncio
602async def test_list_buckets_field_headers_async():
603    client = ConfigServiceV2AsyncClient(
604        credentials=ga_credentials.AnonymousCredentials(),
605    )
606
607    # Any value that is part of the HTTP/1.1 URI should be sent as
608    # a field header. Set these to a non-empty value.
609    request = logging_config.ListBucketsRequest()
610
611    request.parent = "parent/value"
612
613    # Mock the actual call within the gRPC stub, and fake the request.
614    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
615        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
616            logging_config.ListBucketsResponse()
617        )
618        await client.list_buckets(request)
619
620        # Establish that the underlying gRPC stub method was called.
621        assert len(call.mock_calls)
622        _, args, _ = call.mock_calls[0]
623        assert args[0] == request
624
625    # Establish that the field header was sent.
626    _, _, kw = call.mock_calls[0]
627    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
628
629
630def test_list_buckets_flattened():
631    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
632
633    # Mock the actual call within the gRPC stub, and fake the request.
634    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
635        # Designate an appropriate return value for the call.
636        call.return_value = logging_config.ListBucketsResponse()
637        # Call the method with a truthy value for each flattened field,
638        # using the keyword arguments to the method.
639        client.list_buckets(parent="parent_value",)
640
641        # Establish that the underlying call was made with the expected
642        # request object values.
643        assert len(call.mock_calls) == 1
644        _, args, _ = call.mock_calls[0]
645        assert args[0].parent == "parent_value"
646
647
648def test_list_buckets_flattened_error():
649    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
650
651    # Attempting to call a method with both a request object and flattened
652    # fields is an error.
653    with pytest.raises(ValueError):
654        client.list_buckets(
655            logging_config.ListBucketsRequest(), parent="parent_value",
656        )
657
658
659@pytest.mark.asyncio
660async def test_list_buckets_flattened_async():
661    client = ConfigServiceV2AsyncClient(
662        credentials=ga_credentials.AnonymousCredentials(),
663    )
664
665    # Mock the actual call within the gRPC stub, and fake the request.
666    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
667        # Designate an appropriate return value for the call.
668        call.return_value = logging_config.ListBucketsResponse()
669
670        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
671            logging_config.ListBucketsResponse()
672        )
673        # Call the method with a truthy value for each flattened field,
674        # using the keyword arguments to the method.
675        response = await client.list_buckets(parent="parent_value",)
676
677        # Establish that the underlying call was made with the expected
678        # request object values.
679        assert len(call.mock_calls)
680        _, args, _ = call.mock_calls[0]
681        assert args[0].parent == "parent_value"
682
683
684@pytest.mark.asyncio
685async def test_list_buckets_flattened_error_async():
686    client = ConfigServiceV2AsyncClient(
687        credentials=ga_credentials.AnonymousCredentials(),
688    )
689
690    # Attempting to call a method with both a request object and flattened
691    # fields is an error.
692    with pytest.raises(ValueError):
693        await client.list_buckets(
694            logging_config.ListBucketsRequest(), parent="parent_value",
695        )
696
697
698def test_list_buckets_pager():
699    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
700
701    # Mock the actual call within the gRPC stub, and fake the request.
702    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
703        # Set the response to a series of pages.
704        call.side_effect = (
705            logging_config.ListBucketsResponse(
706                buckets=[
707                    logging_config.LogBucket(),
708                    logging_config.LogBucket(),
709                    logging_config.LogBucket(),
710                ],
711                next_page_token="abc",
712            ),
713            logging_config.ListBucketsResponse(buckets=[], next_page_token="def",),
714            logging_config.ListBucketsResponse(
715                buckets=[logging_config.LogBucket(),], next_page_token="ghi",
716            ),
717            logging_config.ListBucketsResponse(
718                buckets=[logging_config.LogBucket(), logging_config.LogBucket(),],
719            ),
720            RuntimeError,
721        )
722
723        metadata = ()
724        metadata = tuple(metadata) + (
725            gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)),
726        )
727        pager = client.list_buckets(request={})
728
729        assert pager._metadata == metadata
730
731        results = [i for i in pager]
732        assert len(results) == 6
733        assert all(isinstance(i, logging_config.LogBucket) for i in results)
734
735
736def test_list_buckets_pages():
737    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
738
739    # Mock the actual call within the gRPC stub, and fake the request.
740    with mock.patch.object(type(client.transport.list_buckets), "__call__") as call:
741        # Set the response to a series of pages.
742        call.side_effect = (
743            logging_config.ListBucketsResponse(
744                buckets=[
745                    logging_config.LogBucket(),
746                    logging_config.LogBucket(),
747                    logging_config.LogBucket(),
748                ],
749                next_page_token="abc",
750            ),
751            logging_config.ListBucketsResponse(buckets=[], next_page_token="def",),
752            logging_config.ListBucketsResponse(
753                buckets=[logging_config.LogBucket(),], next_page_token="ghi",
754            ),
755            logging_config.ListBucketsResponse(
756                buckets=[logging_config.LogBucket(), logging_config.LogBucket(),],
757            ),
758            RuntimeError,
759        )
760        pages = list(client.list_buckets(request={}).pages)
761        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
762            assert page_.raw_page.next_page_token == token
763
764
765@pytest.mark.asyncio
766async def test_list_buckets_async_pager():
767    client = ConfigServiceV2AsyncClient(
768        credentials=ga_credentials.AnonymousCredentials,
769    )
770
771    # Mock the actual call within the gRPC stub, and fake the request.
772    with mock.patch.object(
773        type(client.transport.list_buckets), "__call__", new_callable=mock.AsyncMock
774    ) as call:
775        # Set the response to a series of pages.
776        call.side_effect = (
777            logging_config.ListBucketsResponse(
778                buckets=[
779                    logging_config.LogBucket(),
780                    logging_config.LogBucket(),
781                    logging_config.LogBucket(),
782                ],
783                next_page_token="abc",
784            ),
785            logging_config.ListBucketsResponse(buckets=[], next_page_token="def",),
786            logging_config.ListBucketsResponse(
787                buckets=[logging_config.LogBucket(),], next_page_token="ghi",
788            ),
789            logging_config.ListBucketsResponse(
790                buckets=[logging_config.LogBucket(), logging_config.LogBucket(),],
791            ),
792            RuntimeError,
793        )
794        async_pager = await client.list_buckets(request={},)
795        assert async_pager.next_page_token == "abc"
796        responses = []
797        async for response in async_pager:
798            responses.append(response)
799
800        assert len(responses) == 6
801        assert all(isinstance(i, logging_config.LogBucket) for i in responses)
802
803
804@pytest.mark.asyncio
805async def test_list_buckets_async_pages():
806    client = ConfigServiceV2AsyncClient(
807        credentials=ga_credentials.AnonymousCredentials,
808    )
809
810    # Mock the actual call within the gRPC stub, and fake the request.
811    with mock.patch.object(
812        type(client.transport.list_buckets), "__call__", new_callable=mock.AsyncMock
813    ) as call:
814        # Set the response to a series of pages.
815        call.side_effect = (
816            logging_config.ListBucketsResponse(
817                buckets=[
818                    logging_config.LogBucket(),
819                    logging_config.LogBucket(),
820                    logging_config.LogBucket(),
821                ],
822                next_page_token="abc",
823            ),
824            logging_config.ListBucketsResponse(buckets=[], next_page_token="def",),
825            logging_config.ListBucketsResponse(
826                buckets=[logging_config.LogBucket(),], next_page_token="ghi",
827            ),
828            logging_config.ListBucketsResponse(
829                buckets=[logging_config.LogBucket(), logging_config.LogBucket(),],
830            ),
831            RuntimeError,
832        )
833        pages = []
834        async for page_ in (await client.list_buckets(request={})).pages:
835            pages.append(page_)
836        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
837            assert page_.raw_page.next_page_token == token
838
839
840def test_get_bucket(
841    transport: str = "grpc", request_type=logging_config.GetBucketRequest
842):
843    client = ConfigServiceV2Client(
844        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
845    )
846
847    # Everything is optional in proto3 as far as the runtime is concerned,
848    # and we are mocking out the actual API, so just send an empty request.
849    request = request_type()
850
851    # Mock the actual call within the gRPC stub, and fake the request.
852    with mock.patch.object(type(client.transport.get_bucket), "__call__") as call:
853        # Designate an appropriate return value for the call.
854        call.return_value = logging_config.LogBucket(
855            name="name_value",
856            description="description_value",
857            retention_days=1512,
858            locked=True,
859            lifecycle_state=logging_config.LifecycleState.ACTIVE,
860        )
861        response = client.get_bucket(request)
862
863        # Establish that the underlying gRPC stub method was called.
864        assert len(call.mock_calls) == 1
865        _, args, _ = call.mock_calls[0]
866        assert args[0] == logging_config.GetBucketRequest()
867
868    # Establish that the response is the type that we expect.
869    assert isinstance(response, logging_config.LogBucket)
870    assert response.name == "name_value"
871    assert response.description == "description_value"
872    assert response.retention_days == 1512
873    assert response.locked is True
874    assert response.lifecycle_state == logging_config.LifecycleState.ACTIVE
875
876
877def test_get_bucket_from_dict():
878    test_get_bucket(request_type=dict)
879
880
881def test_get_bucket_empty_call():
882    # This test is a coverage failsafe to make sure that totally empty calls,
883    # i.e. request == None and no flattened fields passed, work.
884    client = ConfigServiceV2Client(
885        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
886    )
887
888    # Mock the actual call within the gRPC stub, and fake the request.
889    with mock.patch.object(type(client.transport.get_bucket), "__call__") as call:
890        client.get_bucket()
891        call.assert_called()
892        _, args, _ = call.mock_calls[0]
893        assert args[0] == logging_config.GetBucketRequest()
894
895
896@pytest.mark.asyncio
897async def test_get_bucket_async(
898    transport: str = "grpc_asyncio", request_type=logging_config.GetBucketRequest
899):
900    client = ConfigServiceV2AsyncClient(
901        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
902    )
903
904    # Everything is optional in proto3 as far as the runtime is concerned,
905    # and we are mocking out the actual API, so just send an empty request.
906    request = request_type()
907
908    # Mock the actual call within the gRPC stub, and fake the request.
909    with mock.patch.object(type(client.transport.get_bucket), "__call__") as call:
910        # Designate an appropriate return value for the call.
911        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
912            logging_config.LogBucket(
913                name="name_value",
914                description="description_value",
915                retention_days=1512,
916                locked=True,
917                lifecycle_state=logging_config.LifecycleState.ACTIVE,
918            )
919        )
920        response = await client.get_bucket(request)
921
922        # Establish that the underlying gRPC stub method was called.
923        assert len(call.mock_calls)
924        _, args, _ = call.mock_calls[0]
925        assert args[0] == logging_config.GetBucketRequest()
926
927    # Establish that the response is the type that we expect.
928    assert isinstance(response, logging_config.LogBucket)
929    assert response.name == "name_value"
930    assert response.description == "description_value"
931    assert response.retention_days == 1512
932    assert response.locked is True
933    assert response.lifecycle_state == logging_config.LifecycleState.ACTIVE
934
935
936@pytest.mark.asyncio
937async def test_get_bucket_async_from_dict():
938    await test_get_bucket_async(request_type=dict)
939
940
941def test_get_bucket_field_headers():
942    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
943
944    # Any value that is part of the HTTP/1.1 URI should be sent as
945    # a field header. Set these to a non-empty value.
946    request = logging_config.GetBucketRequest()
947
948    request.name = "name/value"
949
950    # Mock the actual call within the gRPC stub, and fake the request.
951    with mock.patch.object(type(client.transport.get_bucket), "__call__") as call:
952        call.return_value = logging_config.LogBucket()
953        client.get_bucket(request)
954
955        # Establish that the underlying gRPC stub method was called.
956        assert len(call.mock_calls) == 1
957        _, args, _ = call.mock_calls[0]
958        assert args[0] == request
959
960    # Establish that the field header was sent.
961    _, _, kw = call.mock_calls[0]
962    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
963
964
965@pytest.mark.asyncio
966async def test_get_bucket_field_headers_async():
967    client = ConfigServiceV2AsyncClient(
968        credentials=ga_credentials.AnonymousCredentials(),
969    )
970
971    # Any value that is part of the HTTP/1.1 URI should be sent as
972    # a field header. Set these to a non-empty value.
973    request = logging_config.GetBucketRequest()
974
975    request.name = "name/value"
976
977    # Mock the actual call within the gRPC stub, and fake the request.
978    with mock.patch.object(type(client.transport.get_bucket), "__call__") as call:
979        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
980            logging_config.LogBucket()
981        )
982        await client.get_bucket(request)
983
984        # Establish that the underlying gRPC stub method was called.
985        assert len(call.mock_calls)
986        _, args, _ = call.mock_calls[0]
987        assert args[0] == request
988
989    # Establish that the field header was sent.
990    _, _, kw = call.mock_calls[0]
991    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
992
993
994def test_create_bucket(
995    transport: str = "grpc", request_type=logging_config.CreateBucketRequest
996):
997    client = ConfigServiceV2Client(
998        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
999    )
1000
1001    # Everything is optional in proto3 as far as the runtime is concerned,
1002    # and we are mocking out the actual API, so just send an empty request.
1003    request = request_type()
1004
1005    # Mock the actual call within the gRPC stub, and fake the request.
1006    with mock.patch.object(type(client.transport.create_bucket), "__call__") as call:
1007        # Designate an appropriate return value for the call.
1008        call.return_value = logging_config.LogBucket(
1009            name="name_value",
1010            description="description_value",
1011            retention_days=1512,
1012            locked=True,
1013            lifecycle_state=logging_config.LifecycleState.ACTIVE,
1014        )
1015        response = client.create_bucket(request)
1016
1017        # Establish that the underlying gRPC stub method was called.
1018        assert len(call.mock_calls) == 1
1019        _, args, _ = call.mock_calls[0]
1020        assert args[0] == logging_config.CreateBucketRequest()
1021
1022    # Establish that the response is the type that we expect.
1023    assert isinstance(response, logging_config.LogBucket)
1024    assert response.name == "name_value"
1025    assert response.description == "description_value"
1026    assert response.retention_days == 1512
1027    assert response.locked is True
1028    assert response.lifecycle_state == logging_config.LifecycleState.ACTIVE
1029
1030
1031def test_create_bucket_from_dict():
1032    test_create_bucket(request_type=dict)
1033
1034
1035def test_create_bucket_empty_call():
1036    # This test is a coverage failsafe to make sure that totally empty calls,
1037    # i.e. request == None and no flattened fields passed, work.
1038    client = ConfigServiceV2Client(
1039        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
1040    )
1041
1042    # Mock the actual call within the gRPC stub, and fake the request.
1043    with mock.patch.object(type(client.transport.create_bucket), "__call__") as call:
1044        client.create_bucket()
1045        call.assert_called()
1046        _, args, _ = call.mock_calls[0]
1047        assert args[0] == logging_config.CreateBucketRequest()
1048
1049
1050@pytest.mark.asyncio
1051async def test_create_bucket_async(
1052    transport: str = "grpc_asyncio", request_type=logging_config.CreateBucketRequest
1053):
1054    client = ConfigServiceV2AsyncClient(
1055        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1056    )
1057
1058    # Everything is optional in proto3 as far as the runtime is concerned,
1059    # and we are mocking out the actual API, so just send an empty request.
1060    request = request_type()
1061
1062    # Mock the actual call within the gRPC stub, and fake the request.
1063    with mock.patch.object(type(client.transport.create_bucket), "__call__") as call:
1064        # Designate an appropriate return value for the call.
1065        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1066            logging_config.LogBucket(
1067                name="name_value",
1068                description="description_value",
1069                retention_days=1512,
1070                locked=True,
1071                lifecycle_state=logging_config.LifecycleState.ACTIVE,
1072            )
1073        )
1074        response = await client.create_bucket(request)
1075
1076        # Establish that the underlying gRPC stub method was called.
1077        assert len(call.mock_calls)
1078        _, args, _ = call.mock_calls[0]
1079        assert args[0] == logging_config.CreateBucketRequest()
1080
1081    # Establish that the response is the type that we expect.
1082    assert isinstance(response, logging_config.LogBucket)
1083    assert response.name == "name_value"
1084    assert response.description == "description_value"
1085    assert response.retention_days == 1512
1086    assert response.locked is True
1087    assert response.lifecycle_state == logging_config.LifecycleState.ACTIVE
1088
1089
1090@pytest.mark.asyncio
1091async def test_create_bucket_async_from_dict():
1092    await test_create_bucket_async(request_type=dict)
1093
1094
1095def test_create_bucket_field_headers():
1096    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1097
1098    # Any value that is part of the HTTP/1.1 URI should be sent as
1099    # a field header. Set these to a non-empty value.
1100    request = logging_config.CreateBucketRequest()
1101
1102    request.parent = "parent/value"
1103
1104    # Mock the actual call within the gRPC stub, and fake the request.
1105    with mock.patch.object(type(client.transport.create_bucket), "__call__") as call:
1106        call.return_value = logging_config.LogBucket()
1107        client.create_bucket(request)
1108
1109        # Establish that the underlying gRPC stub method was called.
1110        assert len(call.mock_calls) == 1
1111        _, args, _ = call.mock_calls[0]
1112        assert args[0] == request
1113
1114    # Establish that the field header was sent.
1115    _, _, kw = call.mock_calls[0]
1116    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
1117
1118
1119@pytest.mark.asyncio
1120async def test_create_bucket_field_headers_async():
1121    client = ConfigServiceV2AsyncClient(
1122        credentials=ga_credentials.AnonymousCredentials(),
1123    )
1124
1125    # Any value that is part of the HTTP/1.1 URI should be sent as
1126    # a field header. Set these to a non-empty value.
1127    request = logging_config.CreateBucketRequest()
1128
1129    request.parent = "parent/value"
1130
1131    # Mock the actual call within the gRPC stub, and fake the request.
1132    with mock.patch.object(type(client.transport.create_bucket), "__call__") as call:
1133        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1134            logging_config.LogBucket()
1135        )
1136        await client.create_bucket(request)
1137
1138        # Establish that the underlying gRPC stub method was called.
1139        assert len(call.mock_calls)
1140        _, args, _ = call.mock_calls[0]
1141        assert args[0] == request
1142
1143    # Establish that the field header was sent.
1144    _, _, kw = call.mock_calls[0]
1145    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
1146
1147
1148def test_update_bucket(
1149    transport: str = "grpc", request_type=logging_config.UpdateBucketRequest
1150):
1151    client = ConfigServiceV2Client(
1152        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1153    )
1154
1155    # Everything is optional in proto3 as far as the runtime is concerned,
1156    # and we are mocking out the actual API, so just send an empty request.
1157    request = request_type()
1158
1159    # Mock the actual call within the gRPC stub, and fake the request.
1160    with mock.patch.object(type(client.transport.update_bucket), "__call__") as call:
1161        # Designate an appropriate return value for the call.
1162        call.return_value = logging_config.LogBucket(
1163            name="name_value",
1164            description="description_value",
1165            retention_days=1512,
1166            locked=True,
1167            lifecycle_state=logging_config.LifecycleState.ACTIVE,
1168        )
1169        response = client.update_bucket(request)
1170
1171        # Establish that the underlying gRPC stub method was called.
1172        assert len(call.mock_calls) == 1
1173        _, args, _ = call.mock_calls[0]
1174        assert args[0] == logging_config.UpdateBucketRequest()
1175
1176    # Establish that the response is the type that we expect.
1177    assert isinstance(response, logging_config.LogBucket)
1178    assert response.name == "name_value"
1179    assert response.description == "description_value"
1180    assert response.retention_days == 1512
1181    assert response.locked is True
1182    assert response.lifecycle_state == logging_config.LifecycleState.ACTIVE
1183
1184
1185def test_update_bucket_from_dict():
1186    test_update_bucket(request_type=dict)
1187
1188
1189def test_update_bucket_empty_call():
1190    # This test is a coverage failsafe to make sure that totally empty calls,
1191    # i.e. request == None and no flattened fields passed, work.
1192    client = ConfigServiceV2Client(
1193        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
1194    )
1195
1196    # Mock the actual call within the gRPC stub, and fake the request.
1197    with mock.patch.object(type(client.transport.update_bucket), "__call__") as call:
1198        client.update_bucket()
1199        call.assert_called()
1200        _, args, _ = call.mock_calls[0]
1201        assert args[0] == logging_config.UpdateBucketRequest()
1202
1203
1204@pytest.mark.asyncio
1205async def test_update_bucket_async(
1206    transport: str = "grpc_asyncio", request_type=logging_config.UpdateBucketRequest
1207):
1208    client = ConfigServiceV2AsyncClient(
1209        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1210    )
1211
1212    # Everything is optional in proto3 as far as the runtime is concerned,
1213    # and we are mocking out the actual API, so just send an empty request.
1214    request = request_type()
1215
1216    # Mock the actual call within the gRPC stub, and fake the request.
1217    with mock.patch.object(type(client.transport.update_bucket), "__call__") as call:
1218        # Designate an appropriate return value for the call.
1219        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1220            logging_config.LogBucket(
1221                name="name_value",
1222                description="description_value",
1223                retention_days=1512,
1224                locked=True,
1225                lifecycle_state=logging_config.LifecycleState.ACTIVE,
1226            )
1227        )
1228        response = await client.update_bucket(request)
1229
1230        # Establish that the underlying gRPC stub method was called.
1231        assert len(call.mock_calls)
1232        _, args, _ = call.mock_calls[0]
1233        assert args[0] == logging_config.UpdateBucketRequest()
1234
1235    # Establish that the response is the type that we expect.
1236    assert isinstance(response, logging_config.LogBucket)
1237    assert response.name == "name_value"
1238    assert response.description == "description_value"
1239    assert response.retention_days == 1512
1240    assert response.locked is True
1241    assert response.lifecycle_state == logging_config.LifecycleState.ACTIVE
1242
1243
1244@pytest.mark.asyncio
1245async def test_update_bucket_async_from_dict():
1246    await test_update_bucket_async(request_type=dict)
1247
1248
1249def test_update_bucket_field_headers():
1250    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1251
1252    # Any value that is part of the HTTP/1.1 URI should be sent as
1253    # a field header. Set these to a non-empty value.
1254    request = logging_config.UpdateBucketRequest()
1255
1256    request.name = "name/value"
1257
1258    # Mock the actual call within the gRPC stub, and fake the request.
1259    with mock.patch.object(type(client.transport.update_bucket), "__call__") as call:
1260        call.return_value = logging_config.LogBucket()
1261        client.update_bucket(request)
1262
1263        # Establish that the underlying gRPC stub method was called.
1264        assert len(call.mock_calls) == 1
1265        _, args, _ = call.mock_calls[0]
1266        assert args[0] == request
1267
1268    # Establish that the field header was sent.
1269    _, _, kw = call.mock_calls[0]
1270    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
1271
1272
1273@pytest.mark.asyncio
1274async def test_update_bucket_field_headers_async():
1275    client = ConfigServiceV2AsyncClient(
1276        credentials=ga_credentials.AnonymousCredentials(),
1277    )
1278
1279    # Any value that is part of the HTTP/1.1 URI should be sent as
1280    # a field header. Set these to a non-empty value.
1281    request = logging_config.UpdateBucketRequest()
1282
1283    request.name = "name/value"
1284
1285    # Mock the actual call within the gRPC stub, and fake the request.
1286    with mock.patch.object(type(client.transport.update_bucket), "__call__") as call:
1287        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1288            logging_config.LogBucket()
1289        )
1290        await client.update_bucket(request)
1291
1292        # Establish that the underlying gRPC stub method was called.
1293        assert len(call.mock_calls)
1294        _, args, _ = call.mock_calls[0]
1295        assert args[0] == request
1296
1297    # Establish that the field header was sent.
1298    _, _, kw = call.mock_calls[0]
1299    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
1300
1301
1302def test_delete_bucket(
1303    transport: str = "grpc", request_type=logging_config.DeleteBucketRequest
1304):
1305    client = ConfigServiceV2Client(
1306        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1307    )
1308
1309    # Everything is optional in proto3 as far as the runtime is concerned,
1310    # and we are mocking out the actual API, so just send an empty request.
1311    request = request_type()
1312
1313    # Mock the actual call within the gRPC stub, and fake the request.
1314    with mock.patch.object(type(client.transport.delete_bucket), "__call__") as call:
1315        # Designate an appropriate return value for the call.
1316        call.return_value = None
1317        response = client.delete_bucket(request)
1318
1319        # Establish that the underlying gRPC stub method was called.
1320        assert len(call.mock_calls) == 1
1321        _, args, _ = call.mock_calls[0]
1322        assert args[0] == logging_config.DeleteBucketRequest()
1323
1324    # Establish that the response is the type that we expect.
1325    assert response is None
1326
1327
1328def test_delete_bucket_from_dict():
1329    test_delete_bucket(request_type=dict)
1330
1331
1332def test_delete_bucket_empty_call():
1333    # This test is a coverage failsafe to make sure that totally empty calls,
1334    # i.e. request == None and no flattened fields passed, work.
1335    client = ConfigServiceV2Client(
1336        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
1337    )
1338
1339    # Mock the actual call within the gRPC stub, and fake the request.
1340    with mock.patch.object(type(client.transport.delete_bucket), "__call__") as call:
1341        client.delete_bucket()
1342        call.assert_called()
1343        _, args, _ = call.mock_calls[0]
1344        assert args[0] == logging_config.DeleteBucketRequest()
1345
1346
1347@pytest.mark.asyncio
1348async def test_delete_bucket_async(
1349    transport: str = "grpc_asyncio", request_type=logging_config.DeleteBucketRequest
1350):
1351    client = ConfigServiceV2AsyncClient(
1352        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1353    )
1354
1355    # Everything is optional in proto3 as far as the runtime is concerned,
1356    # and we are mocking out the actual API, so just send an empty request.
1357    request = request_type()
1358
1359    # Mock the actual call within the gRPC stub, and fake the request.
1360    with mock.patch.object(type(client.transport.delete_bucket), "__call__") as call:
1361        # Designate an appropriate return value for the call.
1362        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
1363        response = await client.delete_bucket(request)
1364
1365        # Establish that the underlying gRPC stub method was called.
1366        assert len(call.mock_calls)
1367        _, args, _ = call.mock_calls[0]
1368        assert args[0] == logging_config.DeleteBucketRequest()
1369
1370    # Establish that the response is the type that we expect.
1371    assert response is None
1372
1373
1374@pytest.mark.asyncio
1375async def test_delete_bucket_async_from_dict():
1376    await test_delete_bucket_async(request_type=dict)
1377
1378
1379def test_delete_bucket_field_headers():
1380    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1381
1382    # Any value that is part of the HTTP/1.1 URI should be sent as
1383    # a field header. Set these to a non-empty value.
1384    request = logging_config.DeleteBucketRequest()
1385
1386    request.name = "name/value"
1387
1388    # Mock the actual call within the gRPC stub, and fake the request.
1389    with mock.patch.object(type(client.transport.delete_bucket), "__call__") as call:
1390        call.return_value = None
1391        client.delete_bucket(request)
1392
1393        # Establish that the underlying gRPC stub method was called.
1394        assert len(call.mock_calls) == 1
1395        _, args, _ = call.mock_calls[0]
1396        assert args[0] == request
1397
1398    # Establish that the field header was sent.
1399    _, _, kw = call.mock_calls[0]
1400    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
1401
1402
1403@pytest.mark.asyncio
1404async def test_delete_bucket_field_headers_async():
1405    client = ConfigServiceV2AsyncClient(
1406        credentials=ga_credentials.AnonymousCredentials(),
1407    )
1408
1409    # Any value that is part of the HTTP/1.1 URI should be sent as
1410    # a field header. Set these to a non-empty value.
1411    request = logging_config.DeleteBucketRequest()
1412
1413    request.name = "name/value"
1414
1415    # Mock the actual call within the gRPC stub, and fake the request.
1416    with mock.patch.object(type(client.transport.delete_bucket), "__call__") as call:
1417        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
1418        await client.delete_bucket(request)
1419
1420        # Establish that the underlying gRPC stub method was called.
1421        assert len(call.mock_calls)
1422        _, args, _ = call.mock_calls[0]
1423        assert args[0] == request
1424
1425    # Establish that the field header was sent.
1426    _, _, kw = call.mock_calls[0]
1427    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
1428
1429
1430def test_undelete_bucket(
1431    transport: str = "grpc", request_type=logging_config.UndeleteBucketRequest
1432):
1433    client = ConfigServiceV2Client(
1434        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1435    )
1436
1437    # Everything is optional in proto3 as far as the runtime is concerned,
1438    # and we are mocking out the actual API, so just send an empty request.
1439    request = request_type()
1440
1441    # Mock the actual call within the gRPC stub, and fake the request.
1442    with mock.patch.object(type(client.transport.undelete_bucket), "__call__") as call:
1443        # Designate an appropriate return value for the call.
1444        call.return_value = None
1445        response = client.undelete_bucket(request)
1446
1447        # Establish that the underlying gRPC stub method was called.
1448        assert len(call.mock_calls) == 1
1449        _, args, _ = call.mock_calls[0]
1450        assert args[0] == logging_config.UndeleteBucketRequest()
1451
1452    # Establish that the response is the type that we expect.
1453    assert response is None
1454
1455
1456def test_undelete_bucket_from_dict():
1457    test_undelete_bucket(request_type=dict)
1458
1459
1460def test_undelete_bucket_empty_call():
1461    # This test is a coverage failsafe to make sure that totally empty calls,
1462    # i.e. request == None and no flattened fields passed, work.
1463    client = ConfigServiceV2Client(
1464        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
1465    )
1466
1467    # Mock the actual call within the gRPC stub, and fake the request.
1468    with mock.patch.object(type(client.transport.undelete_bucket), "__call__") as call:
1469        client.undelete_bucket()
1470        call.assert_called()
1471        _, args, _ = call.mock_calls[0]
1472        assert args[0] == logging_config.UndeleteBucketRequest()
1473
1474
1475@pytest.mark.asyncio
1476async def test_undelete_bucket_async(
1477    transport: str = "grpc_asyncio", request_type=logging_config.UndeleteBucketRequest
1478):
1479    client = ConfigServiceV2AsyncClient(
1480        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1481    )
1482
1483    # Everything is optional in proto3 as far as the runtime is concerned,
1484    # and we are mocking out the actual API, so just send an empty request.
1485    request = request_type()
1486
1487    # Mock the actual call within the gRPC stub, and fake the request.
1488    with mock.patch.object(type(client.transport.undelete_bucket), "__call__") as call:
1489        # Designate an appropriate return value for the call.
1490        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
1491        response = await client.undelete_bucket(request)
1492
1493        # Establish that the underlying gRPC stub method was called.
1494        assert len(call.mock_calls)
1495        _, args, _ = call.mock_calls[0]
1496        assert args[0] == logging_config.UndeleteBucketRequest()
1497
1498    # Establish that the response is the type that we expect.
1499    assert response is None
1500
1501
1502@pytest.mark.asyncio
1503async def test_undelete_bucket_async_from_dict():
1504    await test_undelete_bucket_async(request_type=dict)
1505
1506
1507def test_undelete_bucket_field_headers():
1508    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1509
1510    # Any value that is part of the HTTP/1.1 URI should be sent as
1511    # a field header. Set these to a non-empty value.
1512    request = logging_config.UndeleteBucketRequest()
1513
1514    request.name = "name/value"
1515
1516    # Mock the actual call within the gRPC stub, and fake the request.
1517    with mock.patch.object(type(client.transport.undelete_bucket), "__call__") as call:
1518        call.return_value = None
1519        client.undelete_bucket(request)
1520
1521        # Establish that the underlying gRPC stub method was called.
1522        assert len(call.mock_calls) == 1
1523        _, args, _ = call.mock_calls[0]
1524        assert args[0] == request
1525
1526    # Establish that the field header was sent.
1527    _, _, kw = call.mock_calls[0]
1528    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
1529
1530
1531@pytest.mark.asyncio
1532async def test_undelete_bucket_field_headers_async():
1533    client = ConfigServiceV2AsyncClient(
1534        credentials=ga_credentials.AnonymousCredentials(),
1535    )
1536
1537    # Any value that is part of the HTTP/1.1 URI should be sent as
1538    # a field header. Set these to a non-empty value.
1539    request = logging_config.UndeleteBucketRequest()
1540
1541    request.name = "name/value"
1542
1543    # Mock the actual call within the gRPC stub, and fake the request.
1544    with mock.patch.object(type(client.transport.undelete_bucket), "__call__") as call:
1545        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
1546        await client.undelete_bucket(request)
1547
1548        # Establish that the underlying gRPC stub method was called.
1549        assert len(call.mock_calls)
1550        _, args, _ = call.mock_calls[0]
1551        assert args[0] == request
1552
1553    # Establish that the field header was sent.
1554    _, _, kw = call.mock_calls[0]
1555    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
1556
1557
1558def test_list_views(
1559    transport: str = "grpc", request_type=logging_config.ListViewsRequest
1560):
1561    client = ConfigServiceV2Client(
1562        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1563    )
1564
1565    # Everything is optional in proto3 as far as the runtime is concerned,
1566    # and we are mocking out the actual API, so just send an empty request.
1567    request = request_type()
1568
1569    # Mock the actual call within the gRPC stub, and fake the request.
1570    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1571        # Designate an appropriate return value for the call.
1572        call.return_value = logging_config.ListViewsResponse(
1573            next_page_token="next_page_token_value",
1574        )
1575        response = client.list_views(request)
1576
1577        # Establish that the underlying gRPC stub method was called.
1578        assert len(call.mock_calls) == 1
1579        _, args, _ = call.mock_calls[0]
1580        assert args[0] == logging_config.ListViewsRequest()
1581
1582    # Establish that the response is the type that we expect.
1583    assert isinstance(response, pagers.ListViewsPager)
1584    assert response.next_page_token == "next_page_token_value"
1585
1586
1587def test_list_views_from_dict():
1588    test_list_views(request_type=dict)
1589
1590
1591def test_list_views_empty_call():
1592    # This test is a coverage failsafe to make sure that totally empty calls,
1593    # i.e. request == None and no flattened fields passed, work.
1594    client = ConfigServiceV2Client(
1595        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
1596    )
1597
1598    # Mock the actual call within the gRPC stub, and fake the request.
1599    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1600        client.list_views()
1601        call.assert_called()
1602        _, args, _ = call.mock_calls[0]
1603        assert args[0] == logging_config.ListViewsRequest()
1604
1605
1606@pytest.mark.asyncio
1607async def test_list_views_async(
1608    transport: str = "grpc_asyncio", request_type=logging_config.ListViewsRequest
1609):
1610    client = ConfigServiceV2AsyncClient(
1611        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1612    )
1613
1614    # Everything is optional in proto3 as far as the runtime is concerned,
1615    # and we are mocking out the actual API, so just send an empty request.
1616    request = request_type()
1617
1618    # Mock the actual call within the gRPC stub, and fake the request.
1619    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1620        # Designate an appropriate return value for the call.
1621        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1622            logging_config.ListViewsResponse(next_page_token="next_page_token_value",)
1623        )
1624        response = await client.list_views(request)
1625
1626        # Establish that the underlying gRPC stub method was called.
1627        assert len(call.mock_calls)
1628        _, args, _ = call.mock_calls[0]
1629        assert args[0] == logging_config.ListViewsRequest()
1630
1631    # Establish that the response is the type that we expect.
1632    assert isinstance(response, pagers.ListViewsAsyncPager)
1633    assert response.next_page_token == "next_page_token_value"
1634
1635
1636@pytest.mark.asyncio
1637async def test_list_views_async_from_dict():
1638    await test_list_views_async(request_type=dict)
1639
1640
1641def test_list_views_field_headers():
1642    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1643
1644    # Any value that is part of the HTTP/1.1 URI should be sent as
1645    # a field header. Set these to a non-empty value.
1646    request = logging_config.ListViewsRequest()
1647
1648    request.parent = "parent/value"
1649
1650    # Mock the actual call within the gRPC stub, and fake the request.
1651    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1652        call.return_value = logging_config.ListViewsResponse()
1653        client.list_views(request)
1654
1655        # Establish that the underlying gRPC stub method was called.
1656        assert len(call.mock_calls) == 1
1657        _, args, _ = call.mock_calls[0]
1658        assert args[0] == request
1659
1660    # Establish that the field header was sent.
1661    _, _, kw = call.mock_calls[0]
1662    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
1663
1664
1665@pytest.mark.asyncio
1666async def test_list_views_field_headers_async():
1667    client = ConfigServiceV2AsyncClient(
1668        credentials=ga_credentials.AnonymousCredentials(),
1669    )
1670
1671    # Any value that is part of the HTTP/1.1 URI should be sent as
1672    # a field header. Set these to a non-empty value.
1673    request = logging_config.ListViewsRequest()
1674
1675    request.parent = "parent/value"
1676
1677    # Mock the actual call within the gRPC stub, and fake the request.
1678    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1679        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1680            logging_config.ListViewsResponse()
1681        )
1682        await client.list_views(request)
1683
1684        # Establish that the underlying gRPC stub method was called.
1685        assert len(call.mock_calls)
1686        _, args, _ = call.mock_calls[0]
1687        assert args[0] == request
1688
1689    # Establish that the field header was sent.
1690    _, _, kw = call.mock_calls[0]
1691    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
1692
1693
1694def test_list_views_flattened():
1695    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1696
1697    # Mock the actual call within the gRPC stub, and fake the request.
1698    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1699        # Designate an appropriate return value for the call.
1700        call.return_value = logging_config.ListViewsResponse()
1701        # Call the method with a truthy value for each flattened field,
1702        # using the keyword arguments to the method.
1703        client.list_views(parent="parent_value",)
1704
1705        # Establish that the underlying call was made with the expected
1706        # request object values.
1707        assert len(call.mock_calls) == 1
1708        _, args, _ = call.mock_calls[0]
1709        assert args[0].parent == "parent_value"
1710
1711
1712def test_list_views_flattened_error():
1713    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1714
1715    # Attempting to call a method with both a request object and flattened
1716    # fields is an error.
1717    with pytest.raises(ValueError):
1718        client.list_views(
1719            logging_config.ListViewsRequest(), parent="parent_value",
1720        )
1721
1722
1723@pytest.mark.asyncio
1724async def test_list_views_flattened_async():
1725    client = ConfigServiceV2AsyncClient(
1726        credentials=ga_credentials.AnonymousCredentials(),
1727    )
1728
1729    # Mock the actual call within the gRPC stub, and fake the request.
1730    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1731        # Designate an appropriate return value for the call.
1732        call.return_value = logging_config.ListViewsResponse()
1733
1734        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1735            logging_config.ListViewsResponse()
1736        )
1737        # Call the method with a truthy value for each flattened field,
1738        # using the keyword arguments to the method.
1739        response = await client.list_views(parent="parent_value",)
1740
1741        # Establish that the underlying call was made with the expected
1742        # request object values.
1743        assert len(call.mock_calls)
1744        _, args, _ = call.mock_calls[0]
1745        assert args[0].parent == "parent_value"
1746
1747
1748@pytest.mark.asyncio
1749async def test_list_views_flattened_error_async():
1750    client = ConfigServiceV2AsyncClient(
1751        credentials=ga_credentials.AnonymousCredentials(),
1752    )
1753
1754    # Attempting to call a method with both a request object and flattened
1755    # fields is an error.
1756    with pytest.raises(ValueError):
1757        await client.list_views(
1758            logging_config.ListViewsRequest(), parent="parent_value",
1759        )
1760
1761
1762def test_list_views_pager():
1763    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
1764
1765    # Mock the actual call within the gRPC stub, and fake the request.
1766    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1767        # Set the response to a series of pages.
1768        call.side_effect = (
1769            logging_config.ListViewsResponse(
1770                views=[
1771                    logging_config.LogView(),
1772                    logging_config.LogView(),
1773                    logging_config.LogView(),
1774                ],
1775                next_page_token="abc",
1776            ),
1777            logging_config.ListViewsResponse(views=[], next_page_token="def",),
1778            logging_config.ListViewsResponse(
1779                views=[logging_config.LogView(),], next_page_token="ghi",
1780            ),
1781            logging_config.ListViewsResponse(
1782                views=[logging_config.LogView(), logging_config.LogView(),],
1783            ),
1784            RuntimeError,
1785        )
1786
1787        metadata = ()
1788        metadata = tuple(metadata) + (
1789            gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)),
1790        )
1791        pager = client.list_views(request={})
1792
1793        assert pager._metadata == metadata
1794
1795        results = [i for i in pager]
1796        assert len(results) == 6
1797        assert all(isinstance(i, logging_config.LogView) for i in results)
1798
1799
1800def test_list_views_pages():
1801    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
1802
1803    # Mock the actual call within the gRPC stub, and fake the request.
1804    with mock.patch.object(type(client.transport.list_views), "__call__") as call:
1805        # Set the response to a series of pages.
1806        call.side_effect = (
1807            logging_config.ListViewsResponse(
1808                views=[
1809                    logging_config.LogView(),
1810                    logging_config.LogView(),
1811                    logging_config.LogView(),
1812                ],
1813                next_page_token="abc",
1814            ),
1815            logging_config.ListViewsResponse(views=[], next_page_token="def",),
1816            logging_config.ListViewsResponse(
1817                views=[logging_config.LogView(),], next_page_token="ghi",
1818            ),
1819            logging_config.ListViewsResponse(
1820                views=[logging_config.LogView(), logging_config.LogView(),],
1821            ),
1822            RuntimeError,
1823        )
1824        pages = list(client.list_views(request={}).pages)
1825        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
1826            assert page_.raw_page.next_page_token == token
1827
1828
1829@pytest.mark.asyncio
1830async def test_list_views_async_pager():
1831    client = ConfigServiceV2AsyncClient(
1832        credentials=ga_credentials.AnonymousCredentials,
1833    )
1834
1835    # Mock the actual call within the gRPC stub, and fake the request.
1836    with mock.patch.object(
1837        type(client.transport.list_views), "__call__", new_callable=mock.AsyncMock
1838    ) as call:
1839        # Set the response to a series of pages.
1840        call.side_effect = (
1841            logging_config.ListViewsResponse(
1842                views=[
1843                    logging_config.LogView(),
1844                    logging_config.LogView(),
1845                    logging_config.LogView(),
1846                ],
1847                next_page_token="abc",
1848            ),
1849            logging_config.ListViewsResponse(views=[], next_page_token="def",),
1850            logging_config.ListViewsResponse(
1851                views=[logging_config.LogView(),], next_page_token="ghi",
1852            ),
1853            logging_config.ListViewsResponse(
1854                views=[logging_config.LogView(), logging_config.LogView(),],
1855            ),
1856            RuntimeError,
1857        )
1858        async_pager = await client.list_views(request={},)
1859        assert async_pager.next_page_token == "abc"
1860        responses = []
1861        async for response in async_pager:
1862            responses.append(response)
1863
1864        assert len(responses) == 6
1865        assert all(isinstance(i, logging_config.LogView) for i in responses)
1866
1867
1868@pytest.mark.asyncio
1869async def test_list_views_async_pages():
1870    client = ConfigServiceV2AsyncClient(
1871        credentials=ga_credentials.AnonymousCredentials,
1872    )
1873
1874    # Mock the actual call within the gRPC stub, and fake the request.
1875    with mock.patch.object(
1876        type(client.transport.list_views), "__call__", new_callable=mock.AsyncMock
1877    ) as call:
1878        # Set the response to a series of pages.
1879        call.side_effect = (
1880            logging_config.ListViewsResponse(
1881                views=[
1882                    logging_config.LogView(),
1883                    logging_config.LogView(),
1884                    logging_config.LogView(),
1885                ],
1886                next_page_token="abc",
1887            ),
1888            logging_config.ListViewsResponse(views=[], next_page_token="def",),
1889            logging_config.ListViewsResponse(
1890                views=[logging_config.LogView(),], next_page_token="ghi",
1891            ),
1892            logging_config.ListViewsResponse(
1893                views=[logging_config.LogView(), logging_config.LogView(),],
1894            ),
1895            RuntimeError,
1896        )
1897        pages = []
1898        async for page_ in (await client.list_views(request={})).pages:
1899            pages.append(page_)
1900        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
1901            assert page_.raw_page.next_page_token == token
1902
1903
1904def test_get_view(transport: str = "grpc", request_type=logging_config.GetViewRequest):
1905    client = ConfigServiceV2Client(
1906        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1907    )
1908
1909    # Everything is optional in proto3 as far as the runtime is concerned,
1910    # and we are mocking out the actual API, so just send an empty request.
1911    request = request_type()
1912
1913    # Mock the actual call within the gRPC stub, and fake the request.
1914    with mock.patch.object(type(client.transport.get_view), "__call__") as call:
1915        # Designate an appropriate return value for the call.
1916        call.return_value = logging_config.LogView(
1917            name="name_value", description="description_value", filter="filter_value",
1918        )
1919        response = client.get_view(request)
1920
1921        # Establish that the underlying gRPC stub method was called.
1922        assert len(call.mock_calls) == 1
1923        _, args, _ = call.mock_calls[0]
1924        assert args[0] == logging_config.GetViewRequest()
1925
1926    # Establish that the response is the type that we expect.
1927    assert isinstance(response, logging_config.LogView)
1928    assert response.name == "name_value"
1929    assert response.description == "description_value"
1930    assert response.filter == "filter_value"
1931
1932
1933def test_get_view_from_dict():
1934    test_get_view(request_type=dict)
1935
1936
1937def test_get_view_empty_call():
1938    # This test is a coverage failsafe to make sure that totally empty calls,
1939    # i.e. request == None and no flattened fields passed, work.
1940    client = ConfigServiceV2Client(
1941        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
1942    )
1943
1944    # Mock the actual call within the gRPC stub, and fake the request.
1945    with mock.patch.object(type(client.transport.get_view), "__call__") as call:
1946        client.get_view()
1947        call.assert_called()
1948        _, args, _ = call.mock_calls[0]
1949        assert args[0] == logging_config.GetViewRequest()
1950
1951
1952@pytest.mark.asyncio
1953async def test_get_view_async(
1954    transport: str = "grpc_asyncio", request_type=logging_config.GetViewRequest
1955):
1956    client = ConfigServiceV2AsyncClient(
1957        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
1958    )
1959
1960    # Everything is optional in proto3 as far as the runtime is concerned,
1961    # and we are mocking out the actual API, so just send an empty request.
1962    request = request_type()
1963
1964    # Mock the actual call within the gRPC stub, and fake the request.
1965    with mock.patch.object(type(client.transport.get_view), "__call__") as call:
1966        # Designate an appropriate return value for the call.
1967        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
1968            logging_config.LogView(
1969                name="name_value",
1970                description="description_value",
1971                filter="filter_value",
1972            )
1973        )
1974        response = await client.get_view(request)
1975
1976        # Establish that the underlying gRPC stub method was called.
1977        assert len(call.mock_calls)
1978        _, args, _ = call.mock_calls[0]
1979        assert args[0] == logging_config.GetViewRequest()
1980
1981    # Establish that the response is the type that we expect.
1982    assert isinstance(response, logging_config.LogView)
1983    assert response.name == "name_value"
1984    assert response.description == "description_value"
1985    assert response.filter == "filter_value"
1986
1987
1988@pytest.mark.asyncio
1989async def test_get_view_async_from_dict():
1990    await test_get_view_async(request_type=dict)
1991
1992
1993def test_get_view_field_headers():
1994    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
1995
1996    # Any value that is part of the HTTP/1.1 URI should be sent as
1997    # a field header. Set these to a non-empty value.
1998    request = logging_config.GetViewRequest()
1999
2000    request.name = "name/value"
2001
2002    # Mock the actual call within the gRPC stub, and fake the request.
2003    with mock.patch.object(type(client.transport.get_view), "__call__") as call:
2004        call.return_value = logging_config.LogView()
2005        client.get_view(request)
2006
2007        # Establish that the underlying gRPC stub method was called.
2008        assert len(call.mock_calls) == 1
2009        _, args, _ = call.mock_calls[0]
2010        assert args[0] == request
2011
2012    # Establish that the field header was sent.
2013    _, _, kw = call.mock_calls[0]
2014    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
2015
2016
2017@pytest.mark.asyncio
2018async def test_get_view_field_headers_async():
2019    client = ConfigServiceV2AsyncClient(
2020        credentials=ga_credentials.AnonymousCredentials(),
2021    )
2022
2023    # Any value that is part of the HTTP/1.1 URI should be sent as
2024    # a field header. Set these to a non-empty value.
2025    request = logging_config.GetViewRequest()
2026
2027    request.name = "name/value"
2028
2029    # Mock the actual call within the gRPC stub, and fake the request.
2030    with mock.patch.object(type(client.transport.get_view), "__call__") as call:
2031        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2032            logging_config.LogView()
2033        )
2034        await client.get_view(request)
2035
2036        # Establish that the underlying gRPC stub method was called.
2037        assert len(call.mock_calls)
2038        _, args, _ = call.mock_calls[0]
2039        assert args[0] == request
2040
2041    # Establish that the field header was sent.
2042    _, _, kw = call.mock_calls[0]
2043    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
2044
2045
2046def test_create_view(
2047    transport: str = "grpc", request_type=logging_config.CreateViewRequest
2048):
2049    client = ConfigServiceV2Client(
2050        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2051    )
2052
2053    # Everything is optional in proto3 as far as the runtime is concerned,
2054    # and we are mocking out the actual API, so just send an empty request.
2055    request = request_type()
2056
2057    # Mock the actual call within the gRPC stub, and fake the request.
2058    with mock.patch.object(type(client.transport.create_view), "__call__") as call:
2059        # Designate an appropriate return value for the call.
2060        call.return_value = logging_config.LogView(
2061            name="name_value", description="description_value", filter="filter_value",
2062        )
2063        response = client.create_view(request)
2064
2065        # Establish that the underlying gRPC stub method was called.
2066        assert len(call.mock_calls) == 1
2067        _, args, _ = call.mock_calls[0]
2068        assert args[0] == logging_config.CreateViewRequest()
2069
2070    # Establish that the response is the type that we expect.
2071    assert isinstance(response, logging_config.LogView)
2072    assert response.name == "name_value"
2073    assert response.description == "description_value"
2074    assert response.filter == "filter_value"
2075
2076
2077def test_create_view_from_dict():
2078    test_create_view(request_type=dict)
2079
2080
2081def test_create_view_empty_call():
2082    # This test is a coverage failsafe to make sure that totally empty calls,
2083    # i.e. request == None and no flattened fields passed, work.
2084    client = ConfigServiceV2Client(
2085        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
2086    )
2087
2088    # Mock the actual call within the gRPC stub, and fake the request.
2089    with mock.patch.object(type(client.transport.create_view), "__call__") as call:
2090        client.create_view()
2091        call.assert_called()
2092        _, args, _ = call.mock_calls[0]
2093        assert args[0] == logging_config.CreateViewRequest()
2094
2095
2096@pytest.mark.asyncio
2097async def test_create_view_async(
2098    transport: str = "grpc_asyncio", request_type=logging_config.CreateViewRequest
2099):
2100    client = ConfigServiceV2AsyncClient(
2101        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2102    )
2103
2104    # Everything is optional in proto3 as far as the runtime is concerned,
2105    # and we are mocking out the actual API, so just send an empty request.
2106    request = request_type()
2107
2108    # Mock the actual call within the gRPC stub, and fake the request.
2109    with mock.patch.object(type(client.transport.create_view), "__call__") as call:
2110        # Designate an appropriate return value for the call.
2111        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2112            logging_config.LogView(
2113                name="name_value",
2114                description="description_value",
2115                filter="filter_value",
2116            )
2117        )
2118        response = await client.create_view(request)
2119
2120        # Establish that the underlying gRPC stub method was called.
2121        assert len(call.mock_calls)
2122        _, args, _ = call.mock_calls[0]
2123        assert args[0] == logging_config.CreateViewRequest()
2124
2125    # Establish that the response is the type that we expect.
2126    assert isinstance(response, logging_config.LogView)
2127    assert response.name == "name_value"
2128    assert response.description == "description_value"
2129    assert response.filter == "filter_value"
2130
2131
2132@pytest.mark.asyncio
2133async def test_create_view_async_from_dict():
2134    await test_create_view_async(request_type=dict)
2135
2136
2137def test_create_view_field_headers():
2138    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2139
2140    # Any value that is part of the HTTP/1.1 URI should be sent as
2141    # a field header. Set these to a non-empty value.
2142    request = logging_config.CreateViewRequest()
2143
2144    request.parent = "parent/value"
2145
2146    # Mock the actual call within the gRPC stub, and fake the request.
2147    with mock.patch.object(type(client.transport.create_view), "__call__") as call:
2148        call.return_value = logging_config.LogView()
2149        client.create_view(request)
2150
2151        # Establish that the underlying gRPC stub method was called.
2152        assert len(call.mock_calls) == 1
2153        _, args, _ = call.mock_calls[0]
2154        assert args[0] == request
2155
2156    # Establish that the field header was sent.
2157    _, _, kw = call.mock_calls[0]
2158    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
2159
2160
2161@pytest.mark.asyncio
2162async def test_create_view_field_headers_async():
2163    client = ConfigServiceV2AsyncClient(
2164        credentials=ga_credentials.AnonymousCredentials(),
2165    )
2166
2167    # Any value that is part of the HTTP/1.1 URI should be sent as
2168    # a field header. Set these to a non-empty value.
2169    request = logging_config.CreateViewRequest()
2170
2171    request.parent = "parent/value"
2172
2173    # Mock the actual call within the gRPC stub, and fake the request.
2174    with mock.patch.object(type(client.transport.create_view), "__call__") as call:
2175        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2176            logging_config.LogView()
2177        )
2178        await client.create_view(request)
2179
2180        # Establish that the underlying gRPC stub method was called.
2181        assert len(call.mock_calls)
2182        _, args, _ = call.mock_calls[0]
2183        assert args[0] == request
2184
2185    # Establish that the field header was sent.
2186    _, _, kw = call.mock_calls[0]
2187    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
2188
2189
2190def test_update_view(
2191    transport: str = "grpc", request_type=logging_config.UpdateViewRequest
2192):
2193    client = ConfigServiceV2Client(
2194        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2195    )
2196
2197    # Everything is optional in proto3 as far as the runtime is concerned,
2198    # and we are mocking out the actual API, so just send an empty request.
2199    request = request_type()
2200
2201    # Mock the actual call within the gRPC stub, and fake the request.
2202    with mock.patch.object(type(client.transport.update_view), "__call__") as call:
2203        # Designate an appropriate return value for the call.
2204        call.return_value = logging_config.LogView(
2205            name="name_value", description="description_value", filter="filter_value",
2206        )
2207        response = client.update_view(request)
2208
2209        # Establish that the underlying gRPC stub method was called.
2210        assert len(call.mock_calls) == 1
2211        _, args, _ = call.mock_calls[0]
2212        assert args[0] == logging_config.UpdateViewRequest()
2213
2214    # Establish that the response is the type that we expect.
2215    assert isinstance(response, logging_config.LogView)
2216    assert response.name == "name_value"
2217    assert response.description == "description_value"
2218    assert response.filter == "filter_value"
2219
2220
2221def test_update_view_from_dict():
2222    test_update_view(request_type=dict)
2223
2224
2225def test_update_view_empty_call():
2226    # This test is a coverage failsafe to make sure that totally empty calls,
2227    # i.e. request == None and no flattened fields passed, work.
2228    client = ConfigServiceV2Client(
2229        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
2230    )
2231
2232    # Mock the actual call within the gRPC stub, and fake the request.
2233    with mock.patch.object(type(client.transport.update_view), "__call__") as call:
2234        client.update_view()
2235        call.assert_called()
2236        _, args, _ = call.mock_calls[0]
2237        assert args[0] == logging_config.UpdateViewRequest()
2238
2239
2240@pytest.mark.asyncio
2241async def test_update_view_async(
2242    transport: str = "grpc_asyncio", request_type=logging_config.UpdateViewRequest
2243):
2244    client = ConfigServiceV2AsyncClient(
2245        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2246    )
2247
2248    # Everything is optional in proto3 as far as the runtime is concerned,
2249    # and we are mocking out the actual API, so just send an empty request.
2250    request = request_type()
2251
2252    # Mock the actual call within the gRPC stub, and fake the request.
2253    with mock.patch.object(type(client.transport.update_view), "__call__") as call:
2254        # Designate an appropriate return value for the call.
2255        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2256            logging_config.LogView(
2257                name="name_value",
2258                description="description_value",
2259                filter="filter_value",
2260            )
2261        )
2262        response = await client.update_view(request)
2263
2264        # Establish that the underlying gRPC stub method was called.
2265        assert len(call.mock_calls)
2266        _, args, _ = call.mock_calls[0]
2267        assert args[0] == logging_config.UpdateViewRequest()
2268
2269    # Establish that the response is the type that we expect.
2270    assert isinstance(response, logging_config.LogView)
2271    assert response.name == "name_value"
2272    assert response.description == "description_value"
2273    assert response.filter == "filter_value"
2274
2275
2276@pytest.mark.asyncio
2277async def test_update_view_async_from_dict():
2278    await test_update_view_async(request_type=dict)
2279
2280
2281def test_update_view_field_headers():
2282    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2283
2284    # Any value that is part of the HTTP/1.1 URI should be sent as
2285    # a field header. Set these to a non-empty value.
2286    request = logging_config.UpdateViewRequest()
2287
2288    request.name = "name/value"
2289
2290    # Mock the actual call within the gRPC stub, and fake the request.
2291    with mock.patch.object(type(client.transport.update_view), "__call__") as call:
2292        call.return_value = logging_config.LogView()
2293        client.update_view(request)
2294
2295        # Establish that the underlying gRPC stub method was called.
2296        assert len(call.mock_calls) == 1
2297        _, args, _ = call.mock_calls[0]
2298        assert args[0] == request
2299
2300    # Establish that the field header was sent.
2301    _, _, kw = call.mock_calls[0]
2302    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
2303
2304
2305@pytest.mark.asyncio
2306async def test_update_view_field_headers_async():
2307    client = ConfigServiceV2AsyncClient(
2308        credentials=ga_credentials.AnonymousCredentials(),
2309    )
2310
2311    # Any value that is part of the HTTP/1.1 URI should be sent as
2312    # a field header. Set these to a non-empty value.
2313    request = logging_config.UpdateViewRequest()
2314
2315    request.name = "name/value"
2316
2317    # Mock the actual call within the gRPC stub, and fake the request.
2318    with mock.patch.object(type(client.transport.update_view), "__call__") as call:
2319        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2320            logging_config.LogView()
2321        )
2322        await client.update_view(request)
2323
2324        # Establish that the underlying gRPC stub method was called.
2325        assert len(call.mock_calls)
2326        _, args, _ = call.mock_calls[0]
2327        assert args[0] == request
2328
2329    # Establish that the field header was sent.
2330    _, _, kw = call.mock_calls[0]
2331    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
2332
2333
2334def test_delete_view(
2335    transport: str = "grpc", request_type=logging_config.DeleteViewRequest
2336):
2337    client = ConfigServiceV2Client(
2338        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2339    )
2340
2341    # Everything is optional in proto3 as far as the runtime is concerned,
2342    # and we are mocking out the actual API, so just send an empty request.
2343    request = request_type()
2344
2345    # Mock the actual call within the gRPC stub, and fake the request.
2346    with mock.patch.object(type(client.transport.delete_view), "__call__") as call:
2347        # Designate an appropriate return value for the call.
2348        call.return_value = None
2349        response = client.delete_view(request)
2350
2351        # Establish that the underlying gRPC stub method was called.
2352        assert len(call.mock_calls) == 1
2353        _, args, _ = call.mock_calls[0]
2354        assert args[0] == logging_config.DeleteViewRequest()
2355
2356    # Establish that the response is the type that we expect.
2357    assert response is None
2358
2359
2360def test_delete_view_from_dict():
2361    test_delete_view(request_type=dict)
2362
2363
2364def test_delete_view_empty_call():
2365    # This test is a coverage failsafe to make sure that totally empty calls,
2366    # i.e. request == None and no flattened fields passed, work.
2367    client = ConfigServiceV2Client(
2368        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
2369    )
2370
2371    # Mock the actual call within the gRPC stub, and fake the request.
2372    with mock.patch.object(type(client.transport.delete_view), "__call__") as call:
2373        client.delete_view()
2374        call.assert_called()
2375        _, args, _ = call.mock_calls[0]
2376        assert args[0] == logging_config.DeleteViewRequest()
2377
2378
2379@pytest.mark.asyncio
2380async def test_delete_view_async(
2381    transport: str = "grpc_asyncio", request_type=logging_config.DeleteViewRequest
2382):
2383    client = ConfigServiceV2AsyncClient(
2384        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2385    )
2386
2387    # Everything is optional in proto3 as far as the runtime is concerned,
2388    # and we are mocking out the actual API, so just send an empty request.
2389    request = request_type()
2390
2391    # Mock the actual call within the gRPC stub, and fake the request.
2392    with mock.patch.object(type(client.transport.delete_view), "__call__") as call:
2393        # Designate an appropriate return value for the call.
2394        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
2395        response = await client.delete_view(request)
2396
2397        # Establish that the underlying gRPC stub method was called.
2398        assert len(call.mock_calls)
2399        _, args, _ = call.mock_calls[0]
2400        assert args[0] == logging_config.DeleteViewRequest()
2401
2402    # Establish that the response is the type that we expect.
2403    assert response is None
2404
2405
2406@pytest.mark.asyncio
2407async def test_delete_view_async_from_dict():
2408    await test_delete_view_async(request_type=dict)
2409
2410
2411def test_delete_view_field_headers():
2412    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2413
2414    # Any value that is part of the HTTP/1.1 URI should be sent as
2415    # a field header. Set these to a non-empty value.
2416    request = logging_config.DeleteViewRequest()
2417
2418    request.name = "name/value"
2419
2420    # Mock the actual call within the gRPC stub, and fake the request.
2421    with mock.patch.object(type(client.transport.delete_view), "__call__") as call:
2422        call.return_value = None
2423        client.delete_view(request)
2424
2425        # Establish that the underlying gRPC stub method was called.
2426        assert len(call.mock_calls) == 1
2427        _, args, _ = call.mock_calls[0]
2428        assert args[0] == request
2429
2430    # Establish that the field header was sent.
2431    _, _, kw = call.mock_calls[0]
2432    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
2433
2434
2435@pytest.mark.asyncio
2436async def test_delete_view_field_headers_async():
2437    client = ConfigServiceV2AsyncClient(
2438        credentials=ga_credentials.AnonymousCredentials(),
2439    )
2440
2441    # Any value that is part of the HTTP/1.1 URI should be sent as
2442    # a field header. Set these to a non-empty value.
2443    request = logging_config.DeleteViewRequest()
2444
2445    request.name = "name/value"
2446
2447    # Mock the actual call within the gRPC stub, and fake the request.
2448    with mock.patch.object(type(client.transport.delete_view), "__call__") as call:
2449        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
2450        await client.delete_view(request)
2451
2452        # Establish that the underlying gRPC stub method was called.
2453        assert len(call.mock_calls)
2454        _, args, _ = call.mock_calls[0]
2455        assert args[0] == request
2456
2457    # Establish that the field header was sent.
2458    _, _, kw = call.mock_calls[0]
2459    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
2460
2461
2462def test_list_sinks(
2463    transport: str = "grpc", request_type=logging_config.ListSinksRequest
2464):
2465    client = ConfigServiceV2Client(
2466        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2467    )
2468
2469    # Everything is optional in proto3 as far as the runtime is concerned,
2470    # and we are mocking out the actual API, so just send an empty request.
2471    request = request_type()
2472
2473    # Mock the actual call within the gRPC stub, and fake the request.
2474    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2475        # Designate an appropriate return value for the call.
2476        call.return_value = logging_config.ListSinksResponse(
2477            next_page_token="next_page_token_value",
2478        )
2479        response = client.list_sinks(request)
2480
2481        # Establish that the underlying gRPC stub method was called.
2482        assert len(call.mock_calls) == 1
2483        _, args, _ = call.mock_calls[0]
2484        assert args[0] == logging_config.ListSinksRequest()
2485
2486    # Establish that the response is the type that we expect.
2487    assert isinstance(response, pagers.ListSinksPager)
2488    assert response.next_page_token == "next_page_token_value"
2489
2490
2491def test_list_sinks_from_dict():
2492    test_list_sinks(request_type=dict)
2493
2494
2495def test_list_sinks_empty_call():
2496    # This test is a coverage failsafe to make sure that totally empty calls,
2497    # i.e. request == None and no flattened fields passed, work.
2498    client = ConfigServiceV2Client(
2499        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
2500    )
2501
2502    # Mock the actual call within the gRPC stub, and fake the request.
2503    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2504        client.list_sinks()
2505        call.assert_called()
2506        _, args, _ = call.mock_calls[0]
2507        assert args[0] == logging_config.ListSinksRequest()
2508
2509
2510@pytest.mark.asyncio
2511async def test_list_sinks_async(
2512    transport: str = "grpc_asyncio", request_type=logging_config.ListSinksRequest
2513):
2514    client = ConfigServiceV2AsyncClient(
2515        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2516    )
2517
2518    # Everything is optional in proto3 as far as the runtime is concerned,
2519    # and we are mocking out the actual API, so just send an empty request.
2520    request = request_type()
2521
2522    # Mock the actual call within the gRPC stub, and fake the request.
2523    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2524        # Designate an appropriate return value for the call.
2525        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2526            logging_config.ListSinksResponse(next_page_token="next_page_token_value",)
2527        )
2528        response = await client.list_sinks(request)
2529
2530        # Establish that the underlying gRPC stub method was called.
2531        assert len(call.mock_calls)
2532        _, args, _ = call.mock_calls[0]
2533        assert args[0] == logging_config.ListSinksRequest()
2534
2535    # Establish that the response is the type that we expect.
2536    assert isinstance(response, pagers.ListSinksAsyncPager)
2537    assert response.next_page_token == "next_page_token_value"
2538
2539
2540@pytest.mark.asyncio
2541async def test_list_sinks_async_from_dict():
2542    await test_list_sinks_async(request_type=dict)
2543
2544
2545def test_list_sinks_field_headers():
2546    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2547
2548    # Any value that is part of the HTTP/1.1 URI should be sent as
2549    # a field header. Set these to a non-empty value.
2550    request = logging_config.ListSinksRequest()
2551
2552    request.parent = "parent/value"
2553
2554    # Mock the actual call within the gRPC stub, and fake the request.
2555    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2556        call.return_value = logging_config.ListSinksResponse()
2557        client.list_sinks(request)
2558
2559        # Establish that the underlying gRPC stub method was called.
2560        assert len(call.mock_calls) == 1
2561        _, args, _ = call.mock_calls[0]
2562        assert args[0] == request
2563
2564    # Establish that the field header was sent.
2565    _, _, kw = call.mock_calls[0]
2566    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
2567
2568
2569@pytest.mark.asyncio
2570async def test_list_sinks_field_headers_async():
2571    client = ConfigServiceV2AsyncClient(
2572        credentials=ga_credentials.AnonymousCredentials(),
2573    )
2574
2575    # Any value that is part of the HTTP/1.1 URI should be sent as
2576    # a field header. Set these to a non-empty value.
2577    request = logging_config.ListSinksRequest()
2578
2579    request.parent = "parent/value"
2580
2581    # Mock the actual call within the gRPC stub, and fake the request.
2582    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2583        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2584            logging_config.ListSinksResponse()
2585        )
2586        await client.list_sinks(request)
2587
2588        # Establish that the underlying gRPC stub method was called.
2589        assert len(call.mock_calls)
2590        _, args, _ = call.mock_calls[0]
2591        assert args[0] == request
2592
2593    # Establish that the field header was sent.
2594    _, _, kw = call.mock_calls[0]
2595    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
2596
2597
2598def test_list_sinks_flattened():
2599    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2600
2601    # Mock the actual call within the gRPC stub, and fake the request.
2602    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2603        # Designate an appropriate return value for the call.
2604        call.return_value = logging_config.ListSinksResponse()
2605        # Call the method with a truthy value for each flattened field,
2606        # using the keyword arguments to the method.
2607        client.list_sinks(parent="parent_value",)
2608
2609        # Establish that the underlying call was made with the expected
2610        # request object values.
2611        assert len(call.mock_calls) == 1
2612        _, args, _ = call.mock_calls[0]
2613        assert args[0].parent == "parent_value"
2614
2615
2616def test_list_sinks_flattened_error():
2617    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2618
2619    # Attempting to call a method with both a request object and flattened
2620    # fields is an error.
2621    with pytest.raises(ValueError):
2622        client.list_sinks(
2623            logging_config.ListSinksRequest(), parent="parent_value",
2624        )
2625
2626
2627@pytest.mark.asyncio
2628async def test_list_sinks_flattened_async():
2629    client = ConfigServiceV2AsyncClient(
2630        credentials=ga_credentials.AnonymousCredentials(),
2631    )
2632
2633    # Mock the actual call within the gRPC stub, and fake the request.
2634    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2635        # Designate an appropriate return value for the call.
2636        call.return_value = logging_config.ListSinksResponse()
2637
2638        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2639            logging_config.ListSinksResponse()
2640        )
2641        # Call the method with a truthy value for each flattened field,
2642        # using the keyword arguments to the method.
2643        response = await client.list_sinks(parent="parent_value",)
2644
2645        # Establish that the underlying call was made with the expected
2646        # request object values.
2647        assert len(call.mock_calls)
2648        _, args, _ = call.mock_calls[0]
2649        assert args[0].parent == "parent_value"
2650
2651
2652@pytest.mark.asyncio
2653async def test_list_sinks_flattened_error_async():
2654    client = ConfigServiceV2AsyncClient(
2655        credentials=ga_credentials.AnonymousCredentials(),
2656    )
2657
2658    # Attempting to call a method with both a request object and flattened
2659    # fields is an error.
2660    with pytest.raises(ValueError):
2661        await client.list_sinks(
2662            logging_config.ListSinksRequest(), parent="parent_value",
2663        )
2664
2665
2666def test_list_sinks_pager():
2667    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
2668
2669    # Mock the actual call within the gRPC stub, and fake the request.
2670    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2671        # Set the response to a series of pages.
2672        call.side_effect = (
2673            logging_config.ListSinksResponse(
2674                sinks=[
2675                    logging_config.LogSink(),
2676                    logging_config.LogSink(),
2677                    logging_config.LogSink(),
2678                ],
2679                next_page_token="abc",
2680            ),
2681            logging_config.ListSinksResponse(sinks=[], next_page_token="def",),
2682            logging_config.ListSinksResponse(
2683                sinks=[logging_config.LogSink(),], next_page_token="ghi",
2684            ),
2685            logging_config.ListSinksResponse(
2686                sinks=[logging_config.LogSink(), logging_config.LogSink(),],
2687            ),
2688            RuntimeError,
2689        )
2690
2691        metadata = ()
2692        metadata = tuple(metadata) + (
2693            gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)),
2694        )
2695        pager = client.list_sinks(request={})
2696
2697        assert pager._metadata == metadata
2698
2699        results = [i for i in pager]
2700        assert len(results) == 6
2701        assert all(isinstance(i, logging_config.LogSink) for i in results)
2702
2703
2704def test_list_sinks_pages():
2705    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
2706
2707    # Mock the actual call within the gRPC stub, and fake the request.
2708    with mock.patch.object(type(client.transport.list_sinks), "__call__") as call:
2709        # Set the response to a series of pages.
2710        call.side_effect = (
2711            logging_config.ListSinksResponse(
2712                sinks=[
2713                    logging_config.LogSink(),
2714                    logging_config.LogSink(),
2715                    logging_config.LogSink(),
2716                ],
2717                next_page_token="abc",
2718            ),
2719            logging_config.ListSinksResponse(sinks=[], next_page_token="def",),
2720            logging_config.ListSinksResponse(
2721                sinks=[logging_config.LogSink(),], next_page_token="ghi",
2722            ),
2723            logging_config.ListSinksResponse(
2724                sinks=[logging_config.LogSink(), logging_config.LogSink(),],
2725            ),
2726            RuntimeError,
2727        )
2728        pages = list(client.list_sinks(request={}).pages)
2729        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
2730            assert page_.raw_page.next_page_token == token
2731
2732
2733@pytest.mark.asyncio
2734async def test_list_sinks_async_pager():
2735    client = ConfigServiceV2AsyncClient(
2736        credentials=ga_credentials.AnonymousCredentials,
2737    )
2738
2739    # Mock the actual call within the gRPC stub, and fake the request.
2740    with mock.patch.object(
2741        type(client.transport.list_sinks), "__call__", new_callable=mock.AsyncMock
2742    ) as call:
2743        # Set the response to a series of pages.
2744        call.side_effect = (
2745            logging_config.ListSinksResponse(
2746                sinks=[
2747                    logging_config.LogSink(),
2748                    logging_config.LogSink(),
2749                    logging_config.LogSink(),
2750                ],
2751                next_page_token="abc",
2752            ),
2753            logging_config.ListSinksResponse(sinks=[], next_page_token="def",),
2754            logging_config.ListSinksResponse(
2755                sinks=[logging_config.LogSink(),], next_page_token="ghi",
2756            ),
2757            logging_config.ListSinksResponse(
2758                sinks=[logging_config.LogSink(), logging_config.LogSink(),],
2759            ),
2760            RuntimeError,
2761        )
2762        async_pager = await client.list_sinks(request={},)
2763        assert async_pager.next_page_token == "abc"
2764        responses = []
2765        async for response in async_pager:
2766            responses.append(response)
2767
2768        assert len(responses) == 6
2769        assert all(isinstance(i, logging_config.LogSink) for i in responses)
2770
2771
2772@pytest.mark.asyncio
2773async def test_list_sinks_async_pages():
2774    client = ConfigServiceV2AsyncClient(
2775        credentials=ga_credentials.AnonymousCredentials,
2776    )
2777
2778    # Mock the actual call within the gRPC stub, and fake the request.
2779    with mock.patch.object(
2780        type(client.transport.list_sinks), "__call__", new_callable=mock.AsyncMock
2781    ) as call:
2782        # Set the response to a series of pages.
2783        call.side_effect = (
2784            logging_config.ListSinksResponse(
2785                sinks=[
2786                    logging_config.LogSink(),
2787                    logging_config.LogSink(),
2788                    logging_config.LogSink(),
2789                ],
2790                next_page_token="abc",
2791            ),
2792            logging_config.ListSinksResponse(sinks=[], next_page_token="def",),
2793            logging_config.ListSinksResponse(
2794                sinks=[logging_config.LogSink(),], next_page_token="ghi",
2795            ),
2796            logging_config.ListSinksResponse(
2797                sinks=[logging_config.LogSink(), logging_config.LogSink(),],
2798            ),
2799            RuntimeError,
2800        )
2801        pages = []
2802        async for page_ in (await client.list_sinks(request={})).pages:
2803            pages.append(page_)
2804        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
2805            assert page_.raw_page.next_page_token == token
2806
2807
2808def test_get_sink(transport: str = "grpc", request_type=logging_config.GetSinkRequest):
2809    client = ConfigServiceV2Client(
2810        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2811    )
2812
2813    # Everything is optional in proto3 as far as the runtime is concerned,
2814    # and we are mocking out the actual API, so just send an empty request.
2815    request = request_type()
2816
2817    # Mock the actual call within the gRPC stub, and fake the request.
2818    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
2819        # Designate an appropriate return value for the call.
2820        call.return_value = logging_config.LogSink(
2821            name="name_value",
2822            destination="destination_value",
2823            filter="filter_value",
2824            description="description_value",
2825            disabled=True,
2826            output_version_format=logging_config.LogSink.VersionFormat.V2,
2827            writer_identity="writer_identity_value",
2828            include_children=True,
2829            bigquery_options=logging_config.BigQueryOptions(
2830                use_partitioned_tables=True
2831            ),
2832        )
2833        response = client.get_sink(request)
2834
2835        # Establish that the underlying gRPC stub method was called.
2836        assert len(call.mock_calls) == 1
2837        _, args, _ = call.mock_calls[0]
2838        assert args[0] == logging_config.GetSinkRequest()
2839
2840    # Establish that the response is the type that we expect.
2841    assert isinstance(response, logging_config.LogSink)
2842    assert response.name == "name_value"
2843    assert response.destination == "destination_value"
2844    assert response.filter == "filter_value"
2845    assert response.description == "description_value"
2846    assert response.disabled is True
2847    assert response.output_version_format == logging_config.LogSink.VersionFormat.V2
2848    assert response.writer_identity == "writer_identity_value"
2849    assert response.include_children is True
2850
2851
2852def test_get_sink_from_dict():
2853    test_get_sink(request_type=dict)
2854
2855
2856def test_get_sink_empty_call():
2857    # This test is a coverage failsafe to make sure that totally empty calls,
2858    # i.e. request == None and no flattened fields passed, work.
2859    client = ConfigServiceV2Client(
2860        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
2861    )
2862
2863    # Mock the actual call within the gRPC stub, and fake the request.
2864    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
2865        client.get_sink()
2866        call.assert_called()
2867        _, args, _ = call.mock_calls[0]
2868        assert args[0] == logging_config.GetSinkRequest()
2869
2870
2871@pytest.mark.asyncio
2872async def test_get_sink_async(
2873    transport: str = "grpc_asyncio", request_type=logging_config.GetSinkRequest
2874):
2875    client = ConfigServiceV2AsyncClient(
2876        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
2877    )
2878
2879    # Everything is optional in proto3 as far as the runtime is concerned,
2880    # and we are mocking out the actual API, so just send an empty request.
2881    request = request_type()
2882
2883    # Mock the actual call within the gRPC stub, and fake the request.
2884    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
2885        # Designate an appropriate return value for the call.
2886        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2887            logging_config.LogSink(
2888                name="name_value",
2889                destination="destination_value",
2890                filter="filter_value",
2891                description="description_value",
2892                disabled=True,
2893                output_version_format=logging_config.LogSink.VersionFormat.V2,
2894                writer_identity="writer_identity_value",
2895                include_children=True,
2896            )
2897        )
2898        response = await client.get_sink(request)
2899
2900        # Establish that the underlying gRPC stub method was called.
2901        assert len(call.mock_calls)
2902        _, args, _ = call.mock_calls[0]
2903        assert args[0] == logging_config.GetSinkRequest()
2904
2905    # Establish that the response is the type that we expect.
2906    assert isinstance(response, logging_config.LogSink)
2907    assert response.name == "name_value"
2908    assert response.destination == "destination_value"
2909    assert response.filter == "filter_value"
2910    assert response.description == "description_value"
2911    assert response.disabled is True
2912    assert response.output_version_format == logging_config.LogSink.VersionFormat.V2
2913    assert response.writer_identity == "writer_identity_value"
2914    assert response.include_children is True
2915
2916
2917@pytest.mark.asyncio
2918async def test_get_sink_async_from_dict():
2919    await test_get_sink_async(request_type=dict)
2920
2921
2922def test_get_sink_field_headers():
2923    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2924
2925    # Any value that is part of the HTTP/1.1 URI should be sent as
2926    # a field header. Set these to a non-empty value.
2927    request = logging_config.GetSinkRequest()
2928
2929    request.sink_name = "sink_name/value"
2930
2931    # Mock the actual call within the gRPC stub, and fake the request.
2932    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
2933        call.return_value = logging_config.LogSink()
2934        client.get_sink(request)
2935
2936        # Establish that the underlying gRPC stub method was called.
2937        assert len(call.mock_calls) == 1
2938        _, args, _ = call.mock_calls[0]
2939        assert args[0] == request
2940
2941    # Establish that the field header was sent.
2942    _, _, kw = call.mock_calls[0]
2943    assert ("x-goog-request-params", "sink_name=sink_name/value",) in kw["metadata"]
2944
2945
2946@pytest.mark.asyncio
2947async def test_get_sink_field_headers_async():
2948    client = ConfigServiceV2AsyncClient(
2949        credentials=ga_credentials.AnonymousCredentials(),
2950    )
2951
2952    # Any value that is part of the HTTP/1.1 URI should be sent as
2953    # a field header. Set these to a non-empty value.
2954    request = logging_config.GetSinkRequest()
2955
2956    request.sink_name = "sink_name/value"
2957
2958    # Mock the actual call within the gRPC stub, and fake the request.
2959    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
2960        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2961            logging_config.LogSink()
2962        )
2963        await client.get_sink(request)
2964
2965        # Establish that the underlying gRPC stub method was called.
2966        assert len(call.mock_calls)
2967        _, args, _ = call.mock_calls[0]
2968        assert args[0] == request
2969
2970    # Establish that the field header was sent.
2971    _, _, kw = call.mock_calls[0]
2972    assert ("x-goog-request-params", "sink_name=sink_name/value",) in kw["metadata"]
2973
2974
2975def test_get_sink_flattened():
2976    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2977
2978    # Mock the actual call within the gRPC stub, and fake the request.
2979    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
2980        # Designate an appropriate return value for the call.
2981        call.return_value = logging_config.LogSink()
2982        # Call the method with a truthy value for each flattened field,
2983        # using the keyword arguments to the method.
2984        client.get_sink(sink_name="sink_name_value",)
2985
2986        # Establish that the underlying call was made with the expected
2987        # request object values.
2988        assert len(call.mock_calls) == 1
2989        _, args, _ = call.mock_calls[0]
2990        assert args[0].sink_name == "sink_name_value"
2991
2992
2993def test_get_sink_flattened_error():
2994    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
2995
2996    # Attempting to call a method with both a request object and flattened
2997    # fields is an error.
2998    with pytest.raises(ValueError):
2999        client.get_sink(
3000            logging_config.GetSinkRequest(), sink_name="sink_name_value",
3001        )
3002
3003
3004@pytest.mark.asyncio
3005async def test_get_sink_flattened_async():
3006    client = ConfigServiceV2AsyncClient(
3007        credentials=ga_credentials.AnonymousCredentials(),
3008    )
3009
3010    # Mock the actual call within the gRPC stub, and fake the request.
3011    with mock.patch.object(type(client.transport.get_sink), "__call__") as call:
3012        # Designate an appropriate return value for the call.
3013        call.return_value = logging_config.LogSink()
3014
3015        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3016            logging_config.LogSink()
3017        )
3018        # Call the method with a truthy value for each flattened field,
3019        # using the keyword arguments to the method.
3020        response = await client.get_sink(sink_name="sink_name_value",)
3021
3022        # Establish that the underlying call was made with the expected
3023        # request object values.
3024        assert len(call.mock_calls)
3025        _, args, _ = call.mock_calls[0]
3026        assert args[0].sink_name == "sink_name_value"
3027
3028
3029@pytest.mark.asyncio
3030async def test_get_sink_flattened_error_async():
3031    client = ConfigServiceV2AsyncClient(
3032        credentials=ga_credentials.AnonymousCredentials(),
3033    )
3034
3035    # Attempting to call a method with both a request object and flattened
3036    # fields is an error.
3037    with pytest.raises(ValueError):
3038        await client.get_sink(
3039            logging_config.GetSinkRequest(), sink_name="sink_name_value",
3040        )
3041
3042
3043def test_create_sink(
3044    transport: str = "grpc", request_type=logging_config.CreateSinkRequest
3045):
3046    client = ConfigServiceV2Client(
3047        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3048    )
3049
3050    # Everything is optional in proto3 as far as the runtime is concerned,
3051    # and we are mocking out the actual API, so just send an empty request.
3052    request = request_type()
3053
3054    # Mock the actual call within the gRPC stub, and fake the request.
3055    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3056        # Designate an appropriate return value for the call.
3057        call.return_value = logging_config.LogSink(
3058            name="name_value",
3059            destination="destination_value",
3060            filter="filter_value",
3061            description="description_value",
3062            disabled=True,
3063            output_version_format=logging_config.LogSink.VersionFormat.V2,
3064            writer_identity="writer_identity_value",
3065            include_children=True,
3066            bigquery_options=logging_config.BigQueryOptions(
3067                use_partitioned_tables=True
3068            ),
3069        )
3070        response = client.create_sink(request)
3071
3072        # Establish that the underlying gRPC stub method was called.
3073        assert len(call.mock_calls) == 1
3074        _, args, _ = call.mock_calls[0]
3075        assert args[0] == logging_config.CreateSinkRequest()
3076
3077    # Establish that the response is the type that we expect.
3078    assert isinstance(response, logging_config.LogSink)
3079    assert response.name == "name_value"
3080    assert response.destination == "destination_value"
3081    assert response.filter == "filter_value"
3082    assert response.description == "description_value"
3083    assert response.disabled is True
3084    assert response.output_version_format == logging_config.LogSink.VersionFormat.V2
3085    assert response.writer_identity == "writer_identity_value"
3086    assert response.include_children is True
3087
3088
3089def test_create_sink_from_dict():
3090    test_create_sink(request_type=dict)
3091
3092
3093def test_create_sink_empty_call():
3094    # This test is a coverage failsafe to make sure that totally empty calls,
3095    # i.e. request == None and no flattened fields passed, work.
3096    client = ConfigServiceV2Client(
3097        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
3098    )
3099
3100    # Mock the actual call within the gRPC stub, and fake the request.
3101    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3102        client.create_sink()
3103        call.assert_called()
3104        _, args, _ = call.mock_calls[0]
3105        assert args[0] == logging_config.CreateSinkRequest()
3106
3107
3108@pytest.mark.asyncio
3109async def test_create_sink_async(
3110    transport: str = "grpc_asyncio", request_type=logging_config.CreateSinkRequest
3111):
3112    client = ConfigServiceV2AsyncClient(
3113        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3114    )
3115
3116    # Everything is optional in proto3 as far as the runtime is concerned,
3117    # and we are mocking out the actual API, so just send an empty request.
3118    request = request_type()
3119
3120    # Mock the actual call within the gRPC stub, and fake the request.
3121    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3122        # Designate an appropriate return value for the call.
3123        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3124            logging_config.LogSink(
3125                name="name_value",
3126                destination="destination_value",
3127                filter="filter_value",
3128                description="description_value",
3129                disabled=True,
3130                output_version_format=logging_config.LogSink.VersionFormat.V2,
3131                writer_identity="writer_identity_value",
3132                include_children=True,
3133            )
3134        )
3135        response = await client.create_sink(request)
3136
3137        # Establish that the underlying gRPC stub method was called.
3138        assert len(call.mock_calls)
3139        _, args, _ = call.mock_calls[0]
3140        assert args[0] == logging_config.CreateSinkRequest()
3141
3142    # Establish that the response is the type that we expect.
3143    assert isinstance(response, logging_config.LogSink)
3144    assert response.name == "name_value"
3145    assert response.destination == "destination_value"
3146    assert response.filter == "filter_value"
3147    assert response.description == "description_value"
3148    assert response.disabled is True
3149    assert response.output_version_format == logging_config.LogSink.VersionFormat.V2
3150    assert response.writer_identity == "writer_identity_value"
3151    assert response.include_children is True
3152
3153
3154@pytest.mark.asyncio
3155async def test_create_sink_async_from_dict():
3156    await test_create_sink_async(request_type=dict)
3157
3158
3159def test_create_sink_field_headers():
3160    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3161
3162    # Any value that is part of the HTTP/1.1 URI should be sent as
3163    # a field header. Set these to a non-empty value.
3164    request = logging_config.CreateSinkRequest()
3165
3166    request.parent = "parent/value"
3167
3168    # Mock the actual call within the gRPC stub, and fake the request.
3169    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3170        call.return_value = logging_config.LogSink()
3171        client.create_sink(request)
3172
3173        # Establish that the underlying gRPC stub method was called.
3174        assert len(call.mock_calls) == 1
3175        _, args, _ = call.mock_calls[0]
3176        assert args[0] == request
3177
3178    # Establish that the field header was sent.
3179    _, _, kw = call.mock_calls[0]
3180    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
3181
3182
3183@pytest.mark.asyncio
3184async def test_create_sink_field_headers_async():
3185    client = ConfigServiceV2AsyncClient(
3186        credentials=ga_credentials.AnonymousCredentials(),
3187    )
3188
3189    # Any value that is part of the HTTP/1.1 URI should be sent as
3190    # a field header. Set these to a non-empty value.
3191    request = logging_config.CreateSinkRequest()
3192
3193    request.parent = "parent/value"
3194
3195    # Mock the actual call within the gRPC stub, and fake the request.
3196    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3197        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3198            logging_config.LogSink()
3199        )
3200        await client.create_sink(request)
3201
3202        # Establish that the underlying gRPC stub method was called.
3203        assert len(call.mock_calls)
3204        _, args, _ = call.mock_calls[0]
3205        assert args[0] == request
3206
3207    # Establish that the field header was sent.
3208    _, _, kw = call.mock_calls[0]
3209    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
3210
3211
3212def test_create_sink_flattened():
3213    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3214
3215    # Mock the actual call within the gRPC stub, and fake the request.
3216    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3217        # Designate an appropriate return value for the call.
3218        call.return_value = logging_config.LogSink()
3219        # Call the method with a truthy value for each flattened field,
3220        # using the keyword arguments to the method.
3221        client.create_sink(
3222            parent="parent_value", sink=logging_config.LogSink(name="name_value"),
3223        )
3224
3225        # Establish that the underlying call was made with the expected
3226        # request object values.
3227        assert len(call.mock_calls) == 1
3228        _, args, _ = call.mock_calls[0]
3229        assert args[0].parent == "parent_value"
3230        assert args[0].sink == logging_config.LogSink(name="name_value")
3231
3232
3233def test_create_sink_flattened_error():
3234    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3235
3236    # Attempting to call a method with both a request object and flattened
3237    # fields is an error.
3238    with pytest.raises(ValueError):
3239        client.create_sink(
3240            logging_config.CreateSinkRequest(),
3241            parent="parent_value",
3242            sink=logging_config.LogSink(name="name_value"),
3243        )
3244
3245
3246@pytest.mark.asyncio
3247async def test_create_sink_flattened_async():
3248    client = ConfigServiceV2AsyncClient(
3249        credentials=ga_credentials.AnonymousCredentials(),
3250    )
3251
3252    # Mock the actual call within the gRPC stub, and fake the request.
3253    with mock.patch.object(type(client.transport.create_sink), "__call__") as call:
3254        # Designate an appropriate return value for the call.
3255        call.return_value = logging_config.LogSink()
3256
3257        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3258            logging_config.LogSink()
3259        )
3260        # Call the method with a truthy value for each flattened field,
3261        # using the keyword arguments to the method.
3262        response = await client.create_sink(
3263            parent="parent_value", sink=logging_config.LogSink(name="name_value"),
3264        )
3265
3266        # Establish that the underlying call was made with the expected
3267        # request object values.
3268        assert len(call.mock_calls)
3269        _, args, _ = call.mock_calls[0]
3270        assert args[0].parent == "parent_value"
3271        assert args[0].sink == logging_config.LogSink(name="name_value")
3272
3273
3274@pytest.mark.asyncio
3275async def test_create_sink_flattened_error_async():
3276    client = ConfigServiceV2AsyncClient(
3277        credentials=ga_credentials.AnonymousCredentials(),
3278    )
3279
3280    # Attempting to call a method with both a request object and flattened
3281    # fields is an error.
3282    with pytest.raises(ValueError):
3283        await client.create_sink(
3284            logging_config.CreateSinkRequest(),
3285            parent="parent_value",
3286            sink=logging_config.LogSink(name="name_value"),
3287        )
3288
3289
3290def test_update_sink(
3291    transport: str = "grpc", request_type=logging_config.UpdateSinkRequest
3292):
3293    client = ConfigServiceV2Client(
3294        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3295    )
3296
3297    # Everything is optional in proto3 as far as the runtime is concerned,
3298    # and we are mocking out the actual API, so just send an empty request.
3299    request = request_type()
3300
3301    # Mock the actual call within the gRPC stub, and fake the request.
3302    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3303        # Designate an appropriate return value for the call.
3304        call.return_value = logging_config.LogSink(
3305            name="name_value",
3306            destination="destination_value",
3307            filter="filter_value",
3308            description="description_value",
3309            disabled=True,
3310            output_version_format=logging_config.LogSink.VersionFormat.V2,
3311            writer_identity="writer_identity_value",
3312            include_children=True,
3313            bigquery_options=logging_config.BigQueryOptions(
3314                use_partitioned_tables=True
3315            ),
3316        )
3317        response = client.update_sink(request)
3318
3319        # Establish that the underlying gRPC stub method was called.
3320        assert len(call.mock_calls) == 1
3321        _, args, _ = call.mock_calls[0]
3322        assert args[0] == logging_config.UpdateSinkRequest()
3323
3324    # Establish that the response is the type that we expect.
3325    assert isinstance(response, logging_config.LogSink)
3326    assert response.name == "name_value"
3327    assert response.destination == "destination_value"
3328    assert response.filter == "filter_value"
3329    assert response.description == "description_value"
3330    assert response.disabled is True
3331    assert response.output_version_format == logging_config.LogSink.VersionFormat.V2
3332    assert response.writer_identity == "writer_identity_value"
3333    assert response.include_children is True
3334
3335
3336def test_update_sink_from_dict():
3337    test_update_sink(request_type=dict)
3338
3339
3340def test_update_sink_empty_call():
3341    # This test is a coverage failsafe to make sure that totally empty calls,
3342    # i.e. request == None and no flattened fields passed, work.
3343    client = ConfigServiceV2Client(
3344        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
3345    )
3346
3347    # Mock the actual call within the gRPC stub, and fake the request.
3348    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3349        client.update_sink()
3350        call.assert_called()
3351        _, args, _ = call.mock_calls[0]
3352        assert args[0] == logging_config.UpdateSinkRequest()
3353
3354
3355@pytest.mark.asyncio
3356async def test_update_sink_async(
3357    transport: str = "grpc_asyncio", request_type=logging_config.UpdateSinkRequest
3358):
3359    client = ConfigServiceV2AsyncClient(
3360        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3361    )
3362
3363    # Everything is optional in proto3 as far as the runtime is concerned,
3364    # and we are mocking out the actual API, so just send an empty request.
3365    request = request_type()
3366
3367    # Mock the actual call within the gRPC stub, and fake the request.
3368    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3369        # Designate an appropriate return value for the call.
3370        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3371            logging_config.LogSink(
3372                name="name_value",
3373                destination="destination_value",
3374                filter="filter_value",
3375                description="description_value",
3376                disabled=True,
3377                output_version_format=logging_config.LogSink.VersionFormat.V2,
3378                writer_identity="writer_identity_value",
3379                include_children=True,
3380            )
3381        )
3382        response = await client.update_sink(request)
3383
3384        # Establish that the underlying gRPC stub method was called.
3385        assert len(call.mock_calls)
3386        _, args, _ = call.mock_calls[0]
3387        assert args[0] == logging_config.UpdateSinkRequest()
3388
3389    # Establish that the response is the type that we expect.
3390    assert isinstance(response, logging_config.LogSink)
3391    assert response.name == "name_value"
3392    assert response.destination == "destination_value"
3393    assert response.filter == "filter_value"
3394    assert response.description == "description_value"
3395    assert response.disabled is True
3396    assert response.output_version_format == logging_config.LogSink.VersionFormat.V2
3397    assert response.writer_identity == "writer_identity_value"
3398    assert response.include_children is True
3399
3400
3401@pytest.mark.asyncio
3402async def test_update_sink_async_from_dict():
3403    await test_update_sink_async(request_type=dict)
3404
3405
3406def test_update_sink_field_headers():
3407    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3408
3409    # Any value that is part of the HTTP/1.1 URI should be sent as
3410    # a field header. Set these to a non-empty value.
3411    request = logging_config.UpdateSinkRequest()
3412
3413    request.sink_name = "sink_name/value"
3414
3415    # Mock the actual call within the gRPC stub, and fake the request.
3416    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3417        call.return_value = logging_config.LogSink()
3418        client.update_sink(request)
3419
3420        # Establish that the underlying gRPC stub method was called.
3421        assert len(call.mock_calls) == 1
3422        _, args, _ = call.mock_calls[0]
3423        assert args[0] == request
3424
3425    # Establish that the field header was sent.
3426    _, _, kw = call.mock_calls[0]
3427    assert ("x-goog-request-params", "sink_name=sink_name/value",) in kw["metadata"]
3428
3429
3430@pytest.mark.asyncio
3431async def test_update_sink_field_headers_async():
3432    client = ConfigServiceV2AsyncClient(
3433        credentials=ga_credentials.AnonymousCredentials(),
3434    )
3435
3436    # Any value that is part of the HTTP/1.1 URI should be sent as
3437    # a field header. Set these to a non-empty value.
3438    request = logging_config.UpdateSinkRequest()
3439
3440    request.sink_name = "sink_name/value"
3441
3442    # Mock the actual call within the gRPC stub, and fake the request.
3443    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3444        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3445            logging_config.LogSink()
3446        )
3447        await client.update_sink(request)
3448
3449        # Establish that the underlying gRPC stub method was called.
3450        assert len(call.mock_calls)
3451        _, args, _ = call.mock_calls[0]
3452        assert args[0] == request
3453
3454    # Establish that the field header was sent.
3455    _, _, kw = call.mock_calls[0]
3456    assert ("x-goog-request-params", "sink_name=sink_name/value",) in kw["metadata"]
3457
3458
3459def test_update_sink_flattened():
3460    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3461
3462    # Mock the actual call within the gRPC stub, and fake the request.
3463    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3464        # Designate an appropriate return value for the call.
3465        call.return_value = logging_config.LogSink()
3466        # Call the method with a truthy value for each flattened field,
3467        # using the keyword arguments to the method.
3468        client.update_sink(
3469            sink_name="sink_name_value",
3470            sink=logging_config.LogSink(name="name_value"),
3471            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
3472        )
3473
3474        # Establish that the underlying call was made with the expected
3475        # request object values.
3476        assert len(call.mock_calls) == 1
3477        _, args, _ = call.mock_calls[0]
3478        assert args[0].sink_name == "sink_name_value"
3479        assert args[0].sink == logging_config.LogSink(name="name_value")
3480        assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"])
3481
3482
3483def test_update_sink_flattened_error():
3484    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3485
3486    # Attempting to call a method with both a request object and flattened
3487    # fields is an error.
3488    with pytest.raises(ValueError):
3489        client.update_sink(
3490            logging_config.UpdateSinkRequest(),
3491            sink_name="sink_name_value",
3492            sink=logging_config.LogSink(name="name_value"),
3493            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
3494        )
3495
3496
3497@pytest.mark.asyncio
3498async def test_update_sink_flattened_async():
3499    client = ConfigServiceV2AsyncClient(
3500        credentials=ga_credentials.AnonymousCredentials(),
3501    )
3502
3503    # Mock the actual call within the gRPC stub, and fake the request.
3504    with mock.patch.object(type(client.transport.update_sink), "__call__") as call:
3505        # Designate an appropriate return value for the call.
3506        call.return_value = logging_config.LogSink()
3507
3508        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3509            logging_config.LogSink()
3510        )
3511        # Call the method with a truthy value for each flattened field,
3512        # using the keyword arguments to the method.
3513        response = await client.update_sink(
3514            sink_name="sink_name_value",
3515            sink=logging_config.LogSink(name="name_value"),
3516            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
3517        )
3518
3519        # Establish that the underlying call was made with the expected
3520        # request object values.
3521        assert len(call.mock_calls)
3522        _, args, _ = call.mock_calls[0]
3523        assert args[0].sink_name == "sink_name_value"
3524        assert args[0].sink == logging_config.LogSink(name="name_value")
3525        assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"])
3526
3527
3528@pytest.mark.asyncio
3529async def test_update_sink_flattened_error_async():
3530    client = ConfigServiceV2AsyncClient(
3531        credentials=ga_credentials.AnonymousCredentials(),
3532    )
3533
3534    # Attempting to call a method with both a request object and flattened
3535    # fields is an error.
3536    with pytest.raises(ValueError):
3537        await client.update_sink(
3538            logging_config.UpdateSinkRequest(),
3539            sink_name="sink_name_value",
3540            sink=logging_config.LogSink(name="name_value"),
3541            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
3542        )
3543
3544
3545def test_delete_sink(
3546    transport: str = "grpc", request_type=logging_config.DeleteSinkRequest
3547):
3548    client = ConfigServiceV2Client(
3549        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3550    )
3551
3552    # Everything is optional in proto3 as far as the runtime is concerned,
3553    # and we are mocking out the actual API, so just send an empty request.
3554    request = request_type()
3555
3556    # Mock the actual call within the gRPC stub, and fake the request.
3557    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3558        # Designate an appropriate return value for the call.
3559        call.return_value = None
3560        response = client.delete_sink(request)
3561
3562        # Establish that the underlying gRPC stub method was called.
3563        assert len(call.mock_calls) == 1
3564        _, args, _ = call.mock_calls[0]
3565        assert args[0] == logging_config.DeleteSinkRequest()
3566
3567    # Establish that the response is the type that we expect.
3568    assert response is None
3569
3570
3571def test_delete_sink_from_dict():
3572    test_delete_sink(request_type=dict)
3573
3574
3575def test_delete_sink_empty_call():
3576    # This test is a coverage failsafe to make sure that totally empty calls,
3577    # i.e. request == None and no flattened fields passed, work.
3578    client = ConfigServiceV2Client(
3579        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
3580    )
3581
3582    # Mock the actual call within the gRPC stub, and fake the request.
3583    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3584        client.delete_sink()
3585        call.assert_called()
3586        _, args, _ = call.mock_calls[0]
3587        assert args[0] == logging_config.DeleteSinkRequest()
3588
3589
3590@pytest.mark.asyncio
3591async def test_delete_sink_async(
3592    transport: str = "grpc_asyncio", request_type=logging_config.DeleteSinkRequest
3593):
3594    client = ConfigServiceV2AsyncClient(
3595        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3596    )
3597
3598    # Everything is optional in proto3 as far as the runtime is concerned,
3599    # and we are mocking out the actual API, so just send an empty request.
3600    request = request_type()
3601
3602    # Mock the actual call within the gRPC stub, and fake the request.
3603    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3604        # Designate an appropriate return value for the call.
3605        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
3606        response = await client.delete_sink(request)
3607
3608        # Establish that the underlying gRPC stub method was called.
3609        assert len(call.mock_calls)
3610        _, args, _ = call.mock_calls[0]
3611        assert args[0] == logging_config.DeleteSinkRequest()
3612
3613    # Establish that the response is the type that we expect.
3614    assert response is None
3615
3616
3617@pytest.mark.asyncio
3618async def test_delete_sink_async_from_dict():
3619    await test_delete_sink_async(request_type=dict)
3620
3621
3622def test_delete_sink_field_headers():
3623    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3624
3625    # Any value that is part of the HTTP/1.1 URI should be sent as
3626    # a field header. Set these to a non-empty value.
3627    request = logging_config.DeleteSinkRequest()
3628
3629    request.sink_name = "sink_name/value"
3630
3631    # Mock the actual call within the gRPC stub, and fake the request.
3632    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3633        call.return_value = None
3634        client.delete_sink(request)
3635
3636        # Establish that the underlying gRPC stub method was called.
3637        assert len(call.mock_calls) == 1
3638        _, args, _ = call.mock_calls[0]
3639        assert args[0] == request
3640
3641    # Establish that the field header was sent.
3642    _, _, kw = call.mock_calls[0]
3643    assert ("x-goog-request-params", "sink_name=sink_name/value",) in kw["metadata"]
3644
3645
3646@pytest.mark.asyncio
3647async def test_delete_sink_field_headers_async():
3648    client = ConfigServiceV2AsyncClient(
3649        credentials=ga_credentials.AnonymousCredentials(),
3650    )
3651
3652    # Any value that is part of the HTTP/1.1 URI should be sent as
3653    # a field header. Set these to a non-empty value.
3654    request = logging_config.DeleteSinkRequest()
3655
3656    request.sink_name = "sink_name/value"
3657
3658    # Mock the actual call within the gRPC stub, and fake the request.
3659    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3660        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
3661        await client.delete_sink(request)
3662
3663        # Establish that the underlying gRPC stub method was called.
3664        assert len(call.mock_calls)
3665        _, args, _ = call.mock_calls[0]
3666        assert args[0] == request
3667
3668    # Establish that the field header was sent.
3669    _, _, kw = call.mock_calls[0]
3670    assert ("x-goog-request-params", "sink_name=sink_name/value",) in kw["metadata"]
3671
3672
3673def test_delete_sink_flattened():
3674    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3675
3676    # Mock the actual call within the gRPC stub, and fake the request.
3677    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3678        # Designate an appropriate return value for the call.
3679        call.return_value = None
3680        # Call the method with a truthy value for each flattened field,
3681        # using the keyword arguments to the method.
3682        client.delete_sink(sink_name="sink_name_value",)
3683
3684        # Establish that the underlying call was made with the expected
3685        # request object values.
3686        assert len(call.mock_calls) == 1
3687        _, args, _ = call.mock_calls[0]
3688        assert args[0].sink_name == "sink_name_value"
3689
3690
3691def test_delete_sink_flattened_error():
3692    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3693
3694    # Attempting to call a method with both a request object and flattened
3695    # fields is an error.
3696    with pytest.raises(ValueError):
3697        client.delete_sink(
3698            logging_config.DeleteSinkRequest(), sink_name="sink_name_value",
3699        )
3700
3701
3702@pytest.mark.asyncio
3703async def test_delete_sink_flattened_async():
3704    client = ConfigServiceV2AsyncClient(
3705        credentials=ga_credentials.AnonymousCredentials(),
3706    )
3707
3708    # Mock the actual call within the gRPC stub, and fake the request.
3709    with mock.patch.object(type(client.transport.delete_sink), "__call__") as call:
3710        # Designate an appropriate return value for the call.
3711        call.return_value = None
3712
3713        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
3714        # Call the method with a truthy value for each flattened field,
3715        # using the keyword arguments to the method.
3716        response = await client.delete_sink(sink_name="sink_name_value",)
3717
3718        # Establish that the underlying call was made with the expected
3719        # request object values.
3720        assert len(call.mock_calls)
3721        _, args, _ = call.mock_calls[0]
3722        assert args[0].sink_name == "sink_name_value"
3723
3724
3725@pytest.mark.asyncio
3726async def test_delete_sink_flattened_error_async():
3727    client = ConfigServiceV2AsyncClient(
3728        credentials=ga_credentials.AnonymousCredentials(),
3729    )
3730
3731    # Attempting to call a method with both a request object and flattened
3732    # fields is an error.
3733    with pytest.raises(ValueError):
3734        await client.delete_sink(
3735            logging_config.DeleteSinkRequest(), sink_name="sink_name_value",
3736        )
3737
3738
3739def test_list_exclusions(
3740    transport: str = "grpc", request_type=logging_config.ListExclusionsRequest
3741):
3742    client = ConfigServiceV2Client(
3743        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3744    )
3745
3746    # Everything is optional in proto3 as far as the runtime is concerned,
3747    # and we are mocking out the actual API, so just send an empty request.
3748    request = request_type()
3749
3750    # Mock the actual call within the gRPC stub, and fake the request.
3751    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3752        # Designate an appropriate return value for the call.
3753        call.return_value = logging_config.ListExclusionsResponse(
3754            next_page_token="next_page_token_value",
3755        )
3756        response = client.list_exclusions(request)
3757
3758        # Establish that the underlying gRPC stub method was called.
3759        assert len(call.mock_calls) == 1
3760        _, args, _ = call.mock_calls[0]
3761        assert args[0] == logging_config.ListExclusionsRequest()
3762
3763    # Establish that the response is the type that we expect.
3764    assert isinstance(response, pagers.ListExclusionsPager)
3765    assert response.next_page_token == "next_page_token_value"
3766
3767
3768def test_list_exclusions_from_dict():
3769    test_list_exclusions(request_type=dict)
3770
3771
3772def test_list_exclusions_empty_call():
3773    # This test is a coverage failsafe to make sure that totally empty calls,
3774    # i.e. request == None and no flattened fields passed, work.
3775    client = ConfigServiceV2Client(
3776        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
3777    )
3778
3779    # Mock the actual call within the gRPC stub, and fake the request.
3780    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3781        client.list_exclusions()
3782        call.assert_called()
3783        _, args, _ = call.mock_calls[0]
3784        assert args[0] == logging_config.ListExclusionsRequest()
3785
3786
3787@pytest.mark.asyncio
3788async def test_list_exclusions_async(
3789    transport: str = "grpc_asyncio", request_type=logging_config.ListExclusionsRequest
3790):
3791    client = ConfigServiceV2AsyncClient(
3792        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
3793    )
3794
3795    # Everything is optional in proto3 as far as the runtime is concerned,
3796    # and we are mocking out the actual API, so just send an empty request.
3797    request = request_type()
3798
3799    # Mock the actual call within the gRPC stub, and fake the request.
3800    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3801        # Designate an appropriate return value for the call.
3802        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3803            logging_config.ListExclusionsResponse(
3804                next_page_token="next_page_token_value",
3805            )
3806        )
3807        response = await client.list_exclusions(request)
3808
3809        # Establish that the underlying gRPC stub method was called.
3810        assert len(call.mock_calls)
3811        _, args, _ = call.mock_calls[0]
3812        assert args[0] == logging_config.ListExclusionsRequest()
3813
3814    # Establish that the response is the type that we expect.
3815    assert isinstance(response, pagers.ListExclusionsAsyncPager)
3816    assert response.next_page_token == "next_page_token_value"
3817
3818
3819@pytest.mark.asyncio
3820async def test_list_exclusions_async_from_dict():
3821    await test_list_exclusions_async(request_type=dict)
3822
3823
3824def test_list_exclusions_field_headers():
3825    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3826
3827    # Any value that is part of the HTTP/1.1 URI should be sent as
3828    # a field header. Set these to a non-empty value.
3829    request = logging_config.ListExclusionsRequest()
3830
3831    request.parent = "parent/value"
3832
3833    # Mock the actual call within the gRPC stub, and fake the request.
3834    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3835        call.return_value = logging_config.ListExclusionsResponse()
3836        client.list_exclusions(request)
3837
3838        # Establish that the underlying gRPC stub method was called.
3839        assert len(call.mock_calls) == 1
3840        _, args, _ = call.mock_calls[0]
3841        assert args[0] == request
3842
3843    # Establish that the field header was sent.
3844    _, _, kw = call.mock_calls[0]
3845    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
3846
3847
3848@pytest.mark.asyncio
3849async def test_list_exclusions_field_headers_async():
3850    client = ConfigServiceV2AsyncClient(
3851        credentials=ga_credentials.AnonymousCredentials(),
3852    )
3853
3854    # Any value that is part of the HTTP/1.1 URI should be sent as
3855    # a field header. Set these to a non-empty value.
3856    request = logging_config.ListExclusionsRequest()
3857
3858    request.parent = "parent/value"
3859
3860    # Mock the actual call within the gRPC stub, and fake the request.
3861    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3862        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3863            logging_config.ListExclusionsResponse()
3864        )
3865        await client.list_exclusions(request)
3866
3867        # Establish that the underlying gRPC stub method was called.
3868        assert len(call.mock_calls)
3869        _, args, _ = call.mock_calls[0]
3870        assert args[0] == request
3871
3872    # Establish that the field header was sent.
3873    _, _, kw = call.mock_calls[0]
3874    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
3875
3876
3877def test_list_exclusions_flattened():
3878    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3879
3880    # Mock the actual call within the gRPC stub, and fake the request.
3881    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3882        # Designate an appropriate return value for the call.
3883        call.return_value = logging_config.ListExclusionsResponse()
3884        # Call the method with a truthy value for each flattened field,
3885        # using the keyword arguments to the method.
3886        client.list_exclusions(parent="parent_value",)
3887
3888        # Establish that the underlying call was made with the expected
3889        # request object values.
3890        assert len(call.mock_calls) == 1
3891        _, args, _ = call.mock_calls[0]
3892        assert args[0].parent == "parent_value"
3893
3894
3895def test_list_exclusions_flattened_error():
3896    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
3897
3898    # Attempting to call a method with both a request object and flattened
3899    # fields is an error.
3900    with pytest.raises(ValueError):
3901        client.list_exclusions(
3902            logging_config.ListExclusionsRequest(), parent="parent_value",
3903        )
3904
3905
3906@pytest.mark.asyncio
3907async def test_list_exclusions_flattened_async():
3908    client = ConfigServiceV2AsyncClient(
3909        credentials=ga_credentials.AnonymousCredentials(),
3910    )
3911
3912    # Mock the actual call within the gRPC stub, and fake the request.
3913    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3914        # Designate an appropriate return value for the call.
3915        call.return_value = logging_config.ListExclusionsResponse()
3916
3917        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
3918            logging_config.ListExclusionsResponse()
3919        )
3920        # Call the method with a truthy value for each flattened field,
3921        # using the keyword arguments to the method.
3922        response = await client.list_exclusions(parent="parent_value",)
3923
3924        # Establish that the underlying call was made with the expected
3925        # request object values.
3926        assert len(call.mock_calls)
3927        _, args, _ = call.mock_calls[0]
3928        assert args[0].parent == "parent_value"
3929
3930
3931@pytest.mark.asyncio
3932async def test_list_exclusions_flattened_error_async():
3933    client = ConfigServiceV2AsyncClient(
3934        credentials=ga_credentials.AnonymousCredentials(),
3935    )
3936
3937    # Attempting to call a method with both a request object and flattened
3938    # fields is an error.
3939    with pytest.raises(ValueError):
3940        await client.list_exclusions(
3941            logging_config.ListExclusionsRequest(), parent="parent_value",
3942        )
3943
3944
3945def test_list_exclusions_pager():
3946    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
3947
3948    # Mock the actual call within the gRPC stub, and fake the request.
3949    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3950        # Set the response to a series of pages.
3951        call.side_effect = (
3952            logging_config.ListExclusionsResponse(
3953                exclusions=[
3954                    logging_config.LogExclusion(),
3955                    logging_config.LogExclusion(),
3956                    logging_config.LogExclusion(),
3957                ],
3958                next_page_token="abc",
3959            ),
3960            logging_config.ListExclusionsResponse(
3961                exclusions=[], next_page_token="def",
3962            ),
3963            logging_config.ListExclusionsResponse(
3964                exclusions=[logging_config.LogExclusion(),], next_page_token="ghi",
3965            ),
3966            logging_config.ListExclusionsResponse(
3967                exclusions=[
3968                    logging_config.LogExclusion(),
3969                    logging_config.LogExclusion(),
3970                ],
3971            ),
3972            RuntimeError,
3973        )
3974
3975        metadata = ()
3976        metadata = tuple(metadata) + (
3977            gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)),
3978        )
3979        pager = client.list_exclusions(request={})
3980
3981        assert pager._metadata == metadata
3982
3983        results = [i for i in pager]
3984        assert len(results) == 6
3985        assert all(isinstance(i, logging_config.LogExclusion) for i in results)
3986
3987
3988def test_list_exclusions_pages():
3989    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials,)
3990
3991    # Mock the actual call within the gRPC stub, and fake the request.
3992    with mock.patch.object(type(client.transport.list_exclusions), "__call__") as call:
3993        # Set the response to a series of pages.
3994        call.side_effect = (
3995            logging_config.ListExclusionsResponse(
3996                exclusions=[
3997                    logging_config.LogExclusion(),
3998                    logging_config.LogExclusion(),
3999                    logging_config.LogExclusion(),
4000                ],
4001                next_page_token="abc",
4002            ),
4003            logging_config.ListExclusionsResponse(
4004                exclusions=[], next_page_token="def",
4005            ),
4006            logging_config.ListExclusionsResponse(
4007                exclusions=[logging_config.LogExclusion(),], next_page_token="ghi",
4008            ),
4009            logging_config.ListExclusionsResponse(
4010                exclusions=[
4011                    logging_config.LogExclusion(),
4012                    logging_config.LogExclusion(),
4013                ],
4014            ),
4015            RuntimeError,
4016        )
4017        pages = list(client.list_exclusions(request={}).pages)
4018        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
4019            assert page_.raw_page.next_page_token == token
4020
4021
4022@pytest.mark.asyncio
4023async def test_list_exclusions_async_pager():
4024    client = ConfigServiceV2AsyncClient(
4025        credentials=ga_credentials.AnonymousCredentials,
4026    )
4027
4028    # Mock the actual call within the gRPC stub, and fake the request.
4029    with mock.patch.object(
4030        type(client.transport.list_exclusions), "__call__", new_callable=mock.AsyncMock
4031    ) as call:
4032        # Set the response to a series of pages.
4033        call.side_effect = (
4034            logging_config.ListExclusionsResponse(
4035                exclusions=[
4036                    logging_config.LogExclusion(),
4037                    logging_config.LogExclusion(),
4038                    logging_config.LogExclusion(),
4039                ],
4040                next_page_token="abc",
4041            ),
4042            logging_config.ListExclusionsResponse(
4043                exclusions=[], next_page_token="def",
4044            ),
4045            logging_config.ListExclusionsResponse(
4046                exclusions=[logging_config.LogExclusion(),], next_page_token="ghi",
4047            ),
4048            logging_config.ListExclusionsResponse(
4049                exclusions=[
4050                    logging_config.LogExclusion(),
4051                    logging_config.LogExclusion(),
4052                ],
4053            ),
4054            RuntimeError,
4055        )
4056        async_pager = await client.list_exclusions(request={},)
4057        assert async_pager.next_page_token == "abc"
4058        responses = []
4059        async for response in async_pager:
4060            responses.append(response)
4061
4062        assert len(responses) == 6
4063        assert all(isinstance(i, logging_config.LogExclusion) for i in responses)
4064
4065
4066@pytest.mark.asyncio
4067async def test_list_exclusions_async_pages():
4068    client = ConfigServiceV2AsyncClient(
4069        credentials=ga_credentials.AnonymousCredentials,
4070    )
4071
4072    # Mock the actual call within the gRPC stub, and fake the request.
4073    with mock.patch.object(
4074        type(client.transport.list_exclusions), "__call__", new_callable=mock.AsyncMock
4075    ) as call:
4076        # Set the response to a series of pages.
4077        call.side_effect = (
4078            logging_config.ListExclusionsResponse(
4079                exclusions=[
4080                    logging_config.LogExclusion(),
4081                    logging_config.LogExclusion(),
4082                    logging_config.LogExclusion(),
4083                ],
4084                next_page_token="abc",
4085            ),
4086            logging_config.ListExclusionsResponse(
4087                exclusions=[], next_page_token="def",
4088            ),
4089            logging_config.ListExclusionsResponse(
4090                exclusions=[logging_config.LogExclusion(),], next_page_token="ghi",
4091            ),
4092            logging_config.ListExclusionsResponse(
4093                exclusions=[
4094                    logging_config.LogExclusion(),
4095                    logging_config.LogExclusion(),
4096                ],
4097            ),
4098            RuntimeError,
4099        )
4100        pages = []
4101        async for page_ in (await client.list_exclusions(request={})).pages:
4102            pages.append(page_)
4103        for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
4104            assert page_.raw_page.next_page_token == token
4105
4106
4107def test_get_exclusion(
4108    transport: str = "grpc", request_type=logging_config.GetExclusionRequest
4109):
4110    client = ConfigServiceV2Client(
4111        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4112    )
4113
4114    # Everything is optional in proto3 as far as the runtime is concerned,
4115    # and we are mocking out the actual API, so just send an empty request.
4116    request = request_type()
4117
4118    # Mock the actual call within the gRPC stub, and fake the request.
4119    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4120        # Designate an appropriate return value for the call.
4121        call.return_value = logging_config.LogExclusion(
4122            name="name_value",
4123            description="description_value",
4124            filter="filter_value",
4125            disabled=True,
4126        )
4127        response = client.get_exclusion(request)
4128
4129        # Establish that the underlying gRPC stub method was called.
4130        assert len(call.mock_calls) == 1
4131        _, args, _ = call.mock_calls[0]
4132        assert args[0] == logging_config.GetExclusionRequest()
4133
4134    # Establish that the response is the type that we expect.
4135    assert isinstance(response, logging_config.LogExclusion)
4136    assert response.name == "name_value"
4137    assert response.description == "description_value"
4138    assert response.filter == "filter_value"
4139    assert response.disabled is True
4140
4141
4142def test_get_exclusion_from_dict():
4143    test_get_exclusion(request_type=dict)
4144
4145
4146def test_get_exclusion_empty_call():
4147    # This test is a coverage failsafe to make sure that totally empty calls,
4148    # i.e. request == None and no flattened fields passed, work.
4149    client = ConfigServiceV2Client(
4150        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
4151    )
4152
4153    # Mock the actual call within the gRPC stub, and fake the request.
4154    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4155        client.get_exclusion()
4156        call.assert_called()
4157        _, args, _ = call.mock_calls[0]
4158        assert args[0] == logging_config.GetExclusionRequest()
4159
4160
4161@pytest.mark.asyncio
4162async def test_get_exclusion_async(
4163    transport: str = "grpc_asyncio", request_type=logging_config.GetExclusionRequest
4164):
4165    client = ConfigServiceV2AsyncClient(
4166        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4167    )
4168
4169    # Everything is optional in proto3 as far as the runtime is concerned,
4170    # and we are mocking out the actual API, so just send an empty request.
4171    request = request_type()
4172
4173    # Mock the actual call within the gRPC stub, and fake the request.
4174    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4175        # Designate an appropriate return value for the call.
4176        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4177            logging_config.LogExclusion(
4178                name="name_value",
4179                description="description_value",
4180                filter="filter_value",
4181                disabled=True,
4182            )
4183        )
4184        response = await client.get_exclusion(request)
4185
4186        # Establish that the underlying gRPC stub method was called.
4187        assert len(call.mock_calls)
4188        _, args, _ = call.mock_calls[0]
4189        assert args[0] == logging_config.GetExclusionRequest()
4190
4191    # Establish that the response is the type that we expect.
4192    assert isinstance(response, logging_config.LogExclusion)
4193    assert response.name == "name_value"
4194    assert response.description == "description_value"
4195    assert response.filter == "filter_value"
4196    assert response.disabled is True
4197
4198
4199@pytest.mark.asyncio
4200async def test_get_exclusion_async_from_dict():
4201    await test_get_exclusion_async(request_type=dict)
4202
4203
4204def test_get_exclusion_field_headers():
4205    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4206
4207    # Any value that is part of the HTTP/1.1 URI should be sent as
4208    # a field header. Set these to a non-empty value.
4209    request = logging_config.GetExclusionRequest()
4210
4211    request.name = "name/value"
4212
4213    # Mock the actual call within the gRPC stub, and fake the request.
4214    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4215        call.return_value = logging_config.LogExclusion()
4216        client.get_exclusion(request)
4217
4218        # Establish that the underlying gRPC stub method was called.
4219        assert len(call.mock_calls) == 1
4220        _, args, _ = call.mock_calls[0]
4221        assert args[0] == request
4222
4223    # Establish that the field header was sent.
4224    _, _, kw = call.mock_calls[0]
4225    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
4226
4227
4228@pytest.mark.asyncio
4229async def test_get_exclusion_field_headers_async():
4230    client = ConfigServiceV2AsyncClient(
4231        credentials=ga_credentials.AnonymousCredentials(),
4232    )
4233
4234    # Any value that is part of the HTTP/1.1 URI should be sent as
4235    # a field header. Set these to a non-empty value.
4236    request = logging_config.GetExclusionRequest()
4237
4238    request.name = "name/value"
4239
4240    # Mock the actual call within the gRPC stub, and fake the request.
4241    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4242        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4243            logging_config.LogExclusion()
4244        )
4245        await client.get_exclusion(request)
4246
4247        # Establish that the underlying gRPC stub method was called.
4248        assert len(call.mock_calls)
4249        _, args, _ = call.mock_calls[0]
4250        assert args[0] == request
4251
4252    # Establish that the field header was sent.
4253    _, _, kw = call.mock_calls[0]
4254    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
4255
4256
4257def test_get_exclusion_flattened():
4258    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4259
4260    # Mock the actual call within the gRPC stub, and fake the request.
4261    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4262        # Designate an appropriate return value for the call.
4263        call.return_value = logging_config.LogExclusion()
4264        # Call the method with a truthy value for each flattened field,
4265        # using the keyword arguments to the method.
4266        client.get_exclusion(name="name_value",)
4267
4268        # Establish that the underlying call was made with the expected
4269        # request object values.
4270        assert len(call.mock_calls) == 1
4271        _, args, _ = call.mock_calls[0]
4272        assert args[0].name == "name_value"
4273
4274
4275def test_get_exclusion_flattened_error():
4276    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4277
4278    # Attempting to call a method with both a request object and flattened
4279    # fields is an error.
4280    with pytest.raises(ValueError):
4281        client.get_exclusion(
4282            logging_config.GetExclusionRequest(), name="name_value",
4283        )
4284
4285
4286@pytest.mark.asyncio
4287async def test_get_exclusion_flattened_async():
4288    client = ConfigServiceV2AsyncClient(
4289        credentials=ga_credentials.AnonymousCredentials(),
4290    )
4291
4292    # Mock the actual call within the gRPC stub, and fake the request.
4293    with mock.patch.object(type(client.transport.get_exclusion), "__call__") as call:
4294        # Designate an appropriate return value for the call.
4295        call.return_value = logging_config.LogExclusion()
4296
4297        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4298            logging_config.LogExclusion()
4299        )
4300        # Call the method with a truthy value for each flattened field,
4301        # using the keyword arguments to the method.
4302        response = await client.get_exclusion(name="name_value",)
4303
4304        # Establish that the underlying call was made with the expected
4305        # request object values.
4306        assert len(call.mock_calls)
4307        _, args, _ = call.mock_calls[0]
4308        assert args[0].name == "name_value"
4309
4310
4311@pytest.mark.asyncio
4312async def test_get_exclusion_flattened_error_async():
4313    client = ConfigServiceV2AsyncClient(
4314        credentials=ga_credentials.AnonymousCredentials(),
4315    )
4316
4317    # Attempting to call a method with both a request object and flattened
4318    # fields is an error.
4319    with pytest.raises(ValueError):
4320        await client.get_exclusion(
4321            logging_config.GetExclusionRequest(), name="name_value",
4322        )
4323
4324
4325def test_create_exclusion(
4326    transport: str = "grpc", request_type=logging_config.CreateExclusionRequest
4327):
4328    client = ConfigServiceV2Client(
4329        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4330    )
4331
4332    # Everything is optional in proto3 as far as the runtime is concerned,
4333    # and we are mocking out the actual API, so just send an empty request.
4334    request = request_type()
4335
4336    # Mock the actual call within the gRPC stub, and fake the request.
4337    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4338        # Designate an appropriate return value for the call.
4339        call.return_value = logging_config.LogExclusion(
4340            name="name_value",
4341            description="description_value",
4342            filter="filter_value",
4343            disabled=True,
4344        )
4345        response = client.create_exclusion(request)
4346
4347        # Establish that the underlying gRPC stub method was called.
4348        assert len(call.mock_calls) == 1
4349        _, args, _ = call.mock_calls[0]
4350        assert args[0] == logging_config.CreateExclusionRequest()
4351
4352    # Establish that the response is the type that we expect.
4353    assert isinstance(response, logging_config.LogExclusion)
4354    assert response.name == "name_value"
4355    assert response.description == "description_value"
4356    assert response.filter == "filter_value"
4357    assert response.disabled is True
4358
4359
4360def test_create_exclusion_from_dict():
4361    test_create_exclusion(request_type=dict)
4362
4363
4364def test_create_exclusion_empty_call():
4365    # This test is a coverage failsafe to make sure that totally empty calls,
4366    # i.e. request == None and no flattened fields passed, work.
4367    client = ConfigServiceV2Client(
4368        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
4369    )
4370
4371    # Mock the actual call within the gRPC stub, and fake the request.
4372    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4373        client.create_exclusion()
4374        call.assert_called()
4375        _, args, _ = call.mock_calls[0]
4376        assert args[0] == logging_config.CreateExclusionRequest()
4377
4378
4379@pytest.mark.asyncio
4380async def test_create_exclusion_async(
4381    transport: str = "grpc_asyncio", request_type=logging_config.CreateExclusionRequest
4382):
4383    client = ConfigServiceV2AsyncClient(
4384        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4385    )
4386
4387    # Everything is optional in proto3 as far as the runtime is concerned,
4388    # and we are mocking out the actual API, so just send an empty request.
4389    request = request_type()
4390
4391    # Mock the actual call within the gRPC stub, and fake the request.
4392    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4393        # Designate an appropriate return value for the call.
4394        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4395            logging_config.LogExclusion(
4396                name="name_value",
4397                description="description_value",
4398                filter="filter_value",
4399                disabled=True,
4400            )
4401        )
4402        response = await client.create_exclusion(request)
4403
4404        # Establish that the underlying gRPC stub method was called.
4405        assert len(call.mock_calls)
4406        _, args, _ = call.mock_calls[0]
4407        assert args[0] == logging_config.CreateExclusionRequest()
4408
4409    # Establish that the response is the type that we expect.
4410    assert isinstance(response, logging_config.LogExclusion)
4411    assert response.name == "name_value"
4412    assert response.description == "description_value"
4413    assert response.filter == "filter_value"
4414    assert response.disabled is True
4415
4416
4417@pytest.mark.asyncio
4418async def test_create_exclusion_async_from_dict():
4419    await test_create_exclusion_async(request_type=dict)
4420
4421
4422def test_create_exclusion_field_headers():
4423    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4424
4425    # Any value that is part of the HTTP/1.1 URI should be sent as
4426    # a field header. Set these to a non-empty value.
4427    request = logging_config.CreateExclusionRequest()
4428
4429    request.parent = "parent/value"
4430
4431    # Mock the actual call within the gRPC stub, and fake the request.
4432    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4433        call.return_value = logging_config.LogExclusion()
4434        client.create_exclusion(request)
4435
4436        # Establish that the underlying gRPC stub method was called.
4437        assert len(call.mock_calls) == 1
4438        _, args, _ = call.mock_calls[0]
4439        assert args[0] == request
4440
4441    # Establish that the field header was sent.
4442    _, _, kw = call.mock_calls[0]
4443    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
4444
4445
4446@pytest.mark.asyncio
4447async def test_create_exclusion_field_headers_async():
4448    client = ConfigServiceV2AsyncClient(
4449        credentials=ga_credentials.AnonymousCredentials(),
4450    )
4451
4452    # Any value that is part of the HTTP/1.1 URI should be sent as
4453    # a field header. Set these to a non-empty value.
4454    request = logging_config.CreateExclusionRequest()
4455
4456    request.parent = "parent/value"
4457
4458    # Mock the actual call within the gRPC stub, and fake the request.
4459    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4460        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4461            logging_config.LogExclusion()
4462        )
4463        await client.create_exclusion(request)
4464
4465        # Establish that the underlying gRPC stub method was called.
4466        assert len(call.mock_calls)
4467        _, args, _ = call.mock_calls[0]
4468        assert args[0] == request
4469
4470    # Establish that the field header was sent.
4471    _, _, kw = call.mock_calls[0]
4472    assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"]
4473
4474
4475def test_create_exclusion_flattened():
4476    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4477
4478    # Mock the actual call within the gRPC stub, and fake the request.
4479    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4480        # Designate an appropriate return value for the call.
4481        call.return_value = logging_config.LogExclusion()
4482        # Call the method with a truthy value for each flattened field,
4483        # using the keyword arguments to the method.
4484        client.create_exclusion(
4485            parent="parent_value",
4486            exclusion=logging_config.LogExclusion(name="name_value"),
4487        )
4488
4489        # Establish that the underlying call was made with the expected
4490        # request object values.
4491        assert len(call.mock_calls) == 1
4492        _, args, _ = call.mock_calls[0]
4493        assert args[0].parent == "parent_value"
4494        assert args[0].exclusion == logging_config.LogExclusion(name="name_value")
4495
4496
4497def test_create_exclusion_flattened_error():
4498    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4499
4500    # Attempting to call a method with both a request object and flattened
4501    # fields is an error.
4502    with pytest.raises(ValueError):
4503        client.create_exclusion(
4504            logging_config.CreateExclusionRequest(),
4505            parent="parent_value",
4506            exclusion=logging_config.LogExclusion(name="name_value"),
4507        )
4508
4509
4510@pytest.mark.asyncio
4511async def test_create_exclusion_flattened_async():
4512    client = ConfigServiceV2AsyncClient(
4513        credentials=ga_credentials.AnonymousCredentials(),
4514    )
4515
4516    # Mock the actual call within the gRPC stub, and fake the request.
4517    with mock.patch.object(type(client.transport.create_exclusion), "__call__") as call:
4518        # Designate an appropriate return value for the call.
4519        call.return_value = logging_config.LogExclusion()
4520
4521        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4522            logging_config.LogExclusion()
4523        )
4524        # Call the method with a truthy value for each flattened field,
4525        # using the keyword arguments to the method.
4526        response = await client.create_exclusion(
4527            parent="parent_value",
4528            exclusion=logging_config.LogExclusion(name="name_value"),
4529        )
4530
4531        # Establish that the underlying call was made with the expected
4532        # request object values.
4533        assert len(call.mock_calls)
4534        _, args, _ = call.mock_calls[0]
4535        assert args[0].parent == "parent_value"
4536        assert args[0].exclusion == logging_config.LogExclusion(name="name_value")
4537
4538
4539@pytest.mark.asyncio
4540async def test_create_exclusion_flattened_error_async():
4541    client = ConfigServiceV2AsyncClient(
4542        credentials=ga_credentials.AnonymousCredentials(),
4543    )
4544
4545    # Attempting to call a method with both a request object and flattened
4546    # fields is an error.
4547    with pytest.raises(ValueError):
4548        await client.create_exclusion(
4549            logging_config.CreateExclusionRequest(),
4550            parent="parent_value",
4551            exclusion=logging_config.LogExclusion(name="name_value"),
4552        )
4553
4554
4555def test_update_exclusion(
4556    transport: str = "grpc", request_type=logging_config.UpdateExclusionRequest
4557):
4558    client = ConfigServiceV2Client(
4559        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4560    )
4561
4562    # Everything is optional in proto3 as far as the runtime is concerned,
4563    # and we are mocking out the actual API, so just send an empty request.
4564    request = request_type()
4565
4566    # Mock the actual call within the gRPC stub, and fake the request.
4567    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4568        # Designate an appropriate return value for the call.
4569        call.return_value = logging_config.LogExclusion(
4570            name="name_value",
4571            description="description_value",
4572            filter="filter_value",
4573            disabled=True,
4574        )
4575        response = client.update_exclusion(request)
4576
4577        # Establish that the underlying gRPC stub method was called.
4578        assert len(call.mock_calls) == 1
4579        _, args, _ = call.mock_calls[0]
4580        assert args[0] == logging_config.UpdateExclusionRequest()
4581
4582    # Establish that the response is the type that we expect.
4583    assert isinstance(response, logging_config.LogExclusion)
4584    assert response.name == "name_value"
4585    assert response.description == "description_value"
4586    assert response.filter == "filter_value"
4587    assert response.disabled is True
4588
4589
4590def test_update_exclusion_from_dict():
4591    test_update_exclusion(request_type=dict)
4592
4593
4594def test_update_exclusion_empty_call():
4595    # This test is a coverage failsafe to make sure that totally empty calls,
4596    # i.e. request == None and no flattened fields passed, work.
4597    client = ConfigServiceV2Client(
4598        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
4599    )
4600
4601    # Mock the actual call within the gRPC stub, and fake the request.
4602    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4603        client.update_exclusion()
4604        call.assert_called()
4605        _, args, _ = call.mock_calls[0]
4606        assert args[0] == logging_config.UpdateExclusionRequest()
4607
4608
4609@pytest.mark.asyncio
4610async def test_update_exclusion_async(
4611    transport: str = "grpc_asyncio", request_type=logging_config.UpdateExclusionRequest
4612):
4613    client = ConfigServiceV2AsyncClient(
4614        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4615    )
4616
4617    # Everything is optional in proto3 as far as the runtime is concerned,
4618    # and we are mocking out the actual API, so just send an empty request.
4619    request = request_type()
4620
4621    # Mock the actual call within the gRPC stub, and fake the request.
4622    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4623        # Designate an appropriate return value for the call.
4624        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4625            logging_config.LogExclusion(
4626                name="name_value",
4627                description="description_value",
4628                filter="filter_value",
4629                disabled=True,
4630            )
4631        )
4632        response = await client.update_exclusion(request)
4633
4634        # Establish that the underlying gRPC stub method was called.
4635        assert len(call.mock_calls)
4636        _, args, _ = call.mock_calls[0]
4637        assert args[0] == logging_config.UpdateExclusionRequest()
4638
4639    # Establish that the response is the type that we expect.
4640    assert isinstance(response, logging_config.LogExclusion)
4641    assert response.name == "name_value"
4642    assert response.description == "description_value"
4643    assert response.filter == "filter_value"
4644    assert response.disabled is True
4645
4646
4647@pytest.mark.asyncio
4648async def test_update_exclusion_async_from_dict():
4649    await test_update_exclusion_async(request_type=dict)
4650
4651
4652def test_update_exclusion_field_headers():
4653    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4654
4655    # Any value that is part of the HTTP/1.1 URI should be sent as
4656    # a field header. Set these to a non-empty value.
4657    request = logging_config.UpdateExclusionRequest()
4658
4659    request.name = "name/value"
4660
4661    # Mock the actual call within the gRPC stub, and fake the request.
4662    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4663        call.return_value = logging_config.LogExclusion()
4664        client.update_exclusion(request)
4665
4666        # Establish that the underlying gRPC stub method was called.
4667        assert len(call.mock_calls) == 1
4668        _, args, _ = call.mock_calls[0]
4669        assert args[0] == request
4670
4671    # Establish that the field header was sent.
4672    _, _, kw = call.mock_calls[0]
4673    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
4674
4675
4676@pytest.mark.asyncio
4677async def test_update_exclusion_field_headers_async():
4678    client = ConfigServiceV2AsyncClient(
4679        credentials=ga_credentials.AnonymousCredentials(),
4680    )
4681
4682    # Any value that is part of the HTTP/1.1 URI should be sent as
4683    # a field header. Set these to a non-empty value.
4684    request = logging_config.UpdateExclusionRequest()
4685
4686    request.name = "name/value"
4687
4688    # Mock the actual call within the gRPC stub, and fake the request.
4689    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4690        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4691            logging_config.LogExclusion()
4692        )
4693        await client.update_exclusion(request)
4694
4695        # Establish that the underlying gRPC stub method was called.
4696        assert len(call.mock_calls)
4697        _, args, _ = call.mock_calls[0]
4698        assert args[0] == request
4699
4700    # Establish that the field header was sent.
4701    _, _, kw = call.mock_calls[0]
4702    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
4703
4704
4705def test_update_exclusion_flattened():
4706    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4707
4708    # Mock the actual call within the gRPC stub, and fake the request.
4709    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4710        # Designate an appropriate return value for the call.
4711        call.return_value = logging_config.LogExclusion()
4712        # Call the method with a truthy value for each flattened field,
4713        # using the keyword arguments to the method.
4714        client.update_exclusion(
4715            name="name_value",
4716            exclusion=logging_config.LogExclusion(name="name_value"),
4717            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
4718        )
4719
4720        # Establish that the underlying call was made with the expected
4721        # request object values.
4722        assert len(call.mock_calls) == 1
4723        _, args, _ = call.mock_calls[0]
4724        assert args[0].name == "name_value"
4725        assert args[0].exclusion == logging_config.LogExclusion(name="name_value")
4726        assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"])
4727
4728
4729def test_update_exclusion_flattened_error():
4730    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4731
4732    # Attempting to call a method with both a request object and flattened
4733    # fields is an error.
4734    with pytest.raises(ValueError):
4735        client.update_exclusion(
4736            logging_config.UpdateExclusionRequest(),
4737            name="name_value",
4738            exclusion=logging_config.LogExclusion(name="name_value"),
4739            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
4740        )
4741
4742
4743@pytest.mark.asyncio
4744async def test_update_exclusion_flattened_async():
4745    client = ConfigServiceV2AsyncClient(
4746        credentials=ga_credentials.AnonymousCredentials(),
4747    )
4748
4749    # Mock the actual call within the gRPC stub, and fake the request.
4750    with mock.patch.object(type(client.transport.update_exclusion), "__call__") as call:
4751        # Designate an appropriate return value for the call.
4752        call.return_value = logging_config.LogExclusion()
4753
4754        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
4755            logging_config.LogExclusion()
4756        )
4757        # Call the method with a truthy value for each flattened field,
4758        # using the keyword arguments to the method.
4759        response = await client.update_exclusion(
4760            name="name_value",
4761            exclusion=logging_config.LogExclusion(name="name_value"),
4762            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
4763        )
4764
4765        # Establish that the underlying call was made with the expected
4766        # request object values.
4767        assert len(call.mock_calls)
4768        _, args, _ = call.mock_calls[0]
4769        assert args[0].name == "name_value"
4770        assert args[0].exclusion == logging_config.LogExclusion(name="name_value")
4771        assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"])
4772
4773
4774@pytest.mark.asyncio
4775async def test_update_exclusion_flattened_error_async():
4776    client = ConfigServiceV2AsyncClient(
4777        credentials=ga_credentials.AnonymousCredentials(),
4778    )
4779
4780    # Attempting to call a method with both a request object and flattened
4781    # fields is an error.
4782    with pytest.raises(ValueError):
4783        await client.update_exclusion(
4784            logging_config.UpdateExclusionRequest(),
4785            name="name_value",
4786            exclusion=logging_config.LogExclusion(name="name_value"),
4787            update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]),
4788        )
4789
4790
4791def test_delete_exclusion(
4792    transport: str = "grpc", request_type=logging_config.DeleteExclusionRequest
4793):
4794    client = ConfigServiceV2Client(
4795        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4796    )
4797
4798    # Everything is optional in proto3 as far as the runtime is concerned,
4799    # and we are mocking out the actual API, so just send an empty request.
4800    request = request_type()
4801
4802    # Mock the actual call within the gRPC stub, and fake the request.
4803    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4804        # Designate an appropriate return value for the call.
4805        call.return_value = None
4806        response = client.delete_exclusion(request)
4807
4808        # Establish that the underlying gRPC stub method was called.
4809        assert len(call.mock_calls) == 1
4810        _, args, _ = call.mock_calls[0]
4811        assert args[0] == logging_config.DeleteExclusionRequest()
4812
4813    # Establish that the response is the type that we expect.
4814    assert response is None
4815
4816
4817def test_delete_exclusion_from_dict():
4818    test_delete_exclusion(request_type=dict)
4819
4820
4821def test_delete_exclusion_empty_call():
4822    # This test is a coverage failsafe to make sure that totally empty calls,
4823    # i.e. request == None and no flattened fields passed, work.
4824    client = ConfigServiceV2Client(
4825        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
4826    )
4827
4828    # Mock the actual call within the gRPC stub, and fake the request.
4829    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4830        client.delete_exclusion()
4831        call.assert_called()
4832        _, args, _ = call.mock_calls[0]
4833        assert args[0] == logging_config.DeleteExclusionRequest()
4834
4835
4836@pytest.mark.asyncio
4837async def test_delete_exclusion_async(
4838    transport: str = "grpc_asyncio", request_type=logging_config.DeleteExclusionRequest
4839):
4840    client = ConfigServiceV2AsyncClient(
4841        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4842    )
4843
4844    # Everything is optional in proto3 as far as the runtime is concerned,
4845    # and we are mocking out the actual API, so just send an empty request.
4846    request = request_type()
4847
4848    # Mock the actual call within the gRPC stub, and fake the request.
4849    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4850        # Designate an appropriate return value for the call.
4851        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
4852        response = await client.delete_exclusion(request)
4853
4854        # Establish that the underlying gRPC stub method was called.
4855        assert len(call.mock_calls)
4856        _, args, _ = call.mock_calls[0]
4857        assert args[0] == logging_config.DeleteExclusionRequest()
4858
4859    # Establish that the response is the type that we expect.
4860    assert response is None
4861
4862
4863@pytest.mark.asyncio
4864async def test_delete_exclusion_async_from_dict():
4865    await test_delete_exclusion_async(request_type=dict)
4866
4867
4868def test_delete_exclusion_field_headers():
4869    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4870
4871    # Any value that is part of the HTTP/1.1 URI should be sent as
4872    # a field header. Set these to a non-empty value.
4873    request = logging_config.DeleteExclusionRequest()
4874
4875    request.name = "name/value"
4876
4877    # Mock the actual call within the gRPC stub, and fake the request.
4878    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4879        call.return_value = None
4880        client.delete_exclusion(request)
4881
4882        # Establish that the underlying gRPC stub method was called.
4883        assert len(call.mock_calls) == 1
4884        _, args, _ = call.mock_calls[0]
4885        assert args[0] == request
4886
4887    # Establish that the field header was sent.
4888    _, _, kw = call.mock_calls[0]
4889    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
4890
4891
4892@pytest.mark.asyncio
4893async def test_delete_exclusion_field_headers_async():
4894    client = ConfigServiceV2AsyncClient(
4895        credentials=ga_credentials.AnonymousCredentials(),
4896    )
4897
4898    # Any value that is part of the HTTP/1.1 URI should be sent as
4899    # a field header. Set these to a non-empty value.
4900    request = logging_config.DeleteExclusionRequest()
4901
4902    request.name = "name/value"
4903
4904    # Mock the actual call within the gRPC stub, and fake the request.
4905    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4906        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
4907        await client.delete_exclusion(request)
4908
4909        # Establish that the underlying gRPC stub method was called.
4910        assert len(call.mock_calls)
4911        _, args, _ = call.mock_calls[0]
4912        assert args[0] == request
4913
4914    # Establish that the field header was sent.
4915    _, _, kw = call.mock_calls[0]
4916    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
4917
4918
4919def test_delete_exclusion_flattened():
4920    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4921
4922    # Mock the actual call within the gRPC stub, and fake the request.
4923    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4924        # Designate an appropriate return value for the call.
4925        call.return_value = None
4926        # Call the method with a truthy value for each flattened field,
4927        # using the keyword arguments to the method.
4928        client.delete_exclusion(name="name_value",)
4929
4930        # Establish that the underlying call was made with the expected
4931        # request object values.
4932        assert len(call.mock_calls) == 1
4933        _, args, _ = call.mock_calls[0]
4934        assert args[0].name == "name_value"
4935
4936
4937def test_delete_exclusion_flattened_error():
4938    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
4939
4940    # Attempting to call a method with both a request object and flattened
4941    # fields is an error.
4942    with pytest.raises(ValueError):
4943        client.delete_exclusion(
4944            logging_config.DeleteExclusionRequest(), name="name_value",
4945        )
4946
4947
4948@pytest.mark.asyncio
4949async def test_delete_exclusion_flattened_async():
4950    client = ConfigServiceV2AsyncClient(
4951        credentials=ga_credentials.AnonymousCredentials(),
4952    )
4953
4954    # Mock the actual call within the gRPC stub, and fake the request.
4955    with mock.patch.object(type(client.transport.delete_exclusion), "__call__") as call:
4956        # Designate an appropriate return value for the call.
4957        call.return_value = None
4958
4959        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)
4960        # Call the method with a truthy value for each flattened field,
4961        # using the keyword arguments to the method.
4962        response = await client.delete_exclusion(name="name_value",)
4963
4964        # Establish that the underlying call was made with the expected
4965        # request object values.
4966        assert len(call.mock_calls)
4967        _, args, _ = call.mock_calls[0]
4968        assert args[0].name == "name_value"
4969
4970
4971@pytest.mark.asyncio
4972async def test_delete_exclusion_flattened_error_async():
4973    client = ConfigServiceV2AsyncClient(
4974        credentials=ga_credentials.AnonymousCredentials(),
4975    )
4976
4977    # Attempting to call a method with both a request object and flattened
4978    # fields is an error.
4979    with pytest.raises(ValueError):
4980        await client.delete_exclusion(
4981            logging_config.DeleteExclusionRequest(), name="name_value",
4982        )
4983
4984
4985def test_get_cmek_settings(
4986    transport: str = "grpc", request_type=logging_config.GetCmekSettingsRequest
4987):
4988    client = ConfigServiceV2Client(
4989        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
4990    )
4991
4992    # Everything is optional in proto3 as far as the runtime is concerned,
4993    # and we are mocking out the actual API, so just send an empty request.
4994    request = request_type()
4995
4996    # Mock the actual call within the gRPC stub, and fake the request.
4997    with mock.patch.object(
4998        type(client.transport.get_cmek_settings), "__call__"
4999    ) as call:
5000        # Designate an appropriate return value for the call.
5001        call.return_value = logging_config.CmekSettings(
5002            name="name_value",
5003            kms_key_name="kms_key_name_value",
5004            service_account_id="service_account_id_value",
5005        )
5006        response = client.get_cmek_settings(request)
5007
5008        # Establish that the underlying gRPC stub method was called.
5009        assert len(call.mock_calls) == 1
5010        _, args, _ = call.mock_calls[0]
5011        assert args[0] == logging_config.GetCmekSettingsRequest()
5012
5013    # Establish that the response is the type that we expect.
5014    assert isinstance(response, logging_config.CmekSettings)
5015    assert response.name == "name_value"
5016    assert response.kms_key_name == "kms_key_name_value"
5017    assert response.service_account_id == "service_account_id_value"
5018
5019
5020def test_get_cmek_settings_from_dict():
5021    test_get_cmek_settings(request_type=dict)
5022
5023
5024def test_get_cmek_settings_empty_call():
5025    # This test is a coverage failsafe to make sure that totally empty calls,
5026    # i.e. request == None and no flattened fields passed, work.
5027    client = ConfigServiceV2Client(
5028        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
5029    )
5030
5031    # Mock the actual call within the gRPC stub, and fake the request.
5032    with mock.patch.object(
5033        type(client.transport.get_cmek_settings), "__call__"
5034    ) as call:
5035        client.get_cmek_settings()
5036        call.assert_called()
5037        _, args, _ = call.mock_calls[0]
5038        assert args[0] == logging_config.GetCmekSettingsRequest()
5039
5040
5041@pytest.mark.asyncio
5042async def test_get_cmek_settings_async(
5043    transport: str = "grpc_asyncio", request_type=logging_config.GetCmekSettingsRequest
5044):
5045    client = ConfigServiceV2AsyncClient(
5046        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
5047    )
5048
5049    # Everything is optional in proto3 as far as the runtime is concerned,
5050    # and we are mocking out the actual API, so just send an empty request.
5051    request = request_type()
5052
5053    # Mock the actual call within the gRPC stub, and fake the request.
5054    with mock.patch.object(
5055        type(client.transport.get_cmek_settings), "__call__"
5056    ) as call:
5057        # Designate an appropriate return value for the call.
5058        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
5059            logging_config.CmekSettings(
5060                name="name_value",
5061                kms_key_name="kms_key_name_value",
5062                service_account_id="service_account_id_value",
5063            )
5064        )
5065        response = await client.get_cmek_settings(request)
5066
5067        # Establish that the underlying gRPC stub method was called.
5068        assert len(call.mock_calls)
5069        _, args, _ = call.mock_calls[0]
5070        assert args[0] == logging_config.GetCmekSettingsRequest()
5071
5072    # Establish that the response is the type that we expect.
5073    assert isinstance(response, logging_config.CmekSettings)
5074    assert response.name == "name_value"
5075    assert response.kms_key_name == "kms_key_name_value"
5076    assert response.service_account_id == "service_account_id_value"
5077
5078
5079@pytest.mark.asyncio
5080async def test_get_cmek_settings_async_from_dict():
5081    await test_get_cmek_settings_async(request_type=dict)
5082
5083
5084def test_get_cmek_settings_field_headers():
5085    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
5086
5087    # Any value that is part of the HTTP/1.1 URI should be sent as
5088    # a field header. Set these to a non-empty value.
5089    request = logging_config.GetCmekSettingsRequest()
5090
5091    request.name = "name/value"
5092
5093    # Mock the actual call within the gRPC stub, and fake the request.
5094    with mock.patch.object(
5095        type(client.transport.get_cmek_settings), "__call__"
5096    ) as call:
5097        call.return_value = logging_config.CmekSettings()
5098        client.get_cmek_settings(request)
5099
5100        # Establish that the underlying gRPC stub method was called.
5101        assert len(call.mock_calls) == 1
5102        _, args, _ = call.mock_calls[0]
5103        assert args[0] == request
5104
5105    # Establish that the field header was sent.
5106    _, _, kw = call.mock_calls[0]
5107    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
5108
5109
5110@pytest.mark.asyncio
5111async def test_get_cmek_settings_field_headers_async():
5112    client = ConfigServiceV2AsyncClient(
5113        credentials=ga_credentials.AnonymousCredentials(),
5114    )
5115
5116    # Any value that is part of the HTTP/1.1 URI should be sent as
5117    # a field header. Set these to a non-empty value.
5118    request = logging_config.GetCmekSettingsRequest()
5119
5120    request.name = "name/value"
5121
5122    # Mock the actual call within the gRPC stub, and fake the request.
5123    with mock.patch.object(
5124        type(client.transport.get_cmek_settings), "__call__"
5125    ) as call:
5126        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
5127            logging_config.CmekSettings()
5128        )
5129        await client.get_cmek_settings(request)
5130
5131        # Establish that the underlying gRPC stub method was called.
5132        assert len(call.mock_calls)
5133        _, args, _ = call.mock_calls[0]
5134        assert args[0] == request
5135
5136    # Establish that the field header was sent.
5137    _, _, kw = call.mock_calls[0]
5138    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
5139
5140
5141def test_update_cmek_settings(
5142    transport: str = "grpc", request_type=logging_config.UpdateCmekSettingsRequest
5143):
5144    client = ConfigServiceV2Client(
5145        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
5146    )
5147
5148    # Everything is optional in proto3 as far as the runtime is concerned,
5149    # and we are mocking out the actual API, so just send an empty request.
5150    request = request_type()
5151
5152    # Mock the actual call within the gRPC stub, and fake the request.
5153    with mock.patch.object(
5154        type(client.transport.update_cmek_settings), "__call__"
5155    ) as call:
5156        # Designate an appropriate return value for the call.
5157        call.return_value = logging_config.CmekSettings(
5158            name="name_value",
5159            kms_key_name="kms_key_name_value",
5160            service_account_id="service_account_id_value",
5161        )
5162        response = client.update_cmek_settings(request)
5163
5164        # Establish that the underlying gRPC stub method was called.
5165        assert len(call.mock_calls) == 1
5166        _, args, _ = call.mock_calls[0]
5167        assert args[0] == logging_config.UpdateCmekSettingsRequest()
5168
5169    # Establish that the response is the type that we expect.
5170    assert isinstance(response, logging_config.CmekSettings)
5171    assert response.name == "name_value"
5172    assert response.kms_key_name == "kms_key_name_value"
5173    assert response.service_account_id == "service_account_id_value"
5174
5175
5176def test_update_cmek_settings_from_dict():
5177    test_update_cmek_settings(request_type=dict)
5178
5179
5180def test_update_cmek_settings_empty_call():
5181    # This test is a coverage failsafe to make sure that totally empty calls,
5182    # i.e. request == None and no flattened fields passed, work.
5183    client = ConfigServiceV2Client(
5184        credentials=ga_credentials.AnonymousCredentials(), transport="grpc",
5185    )
5186
5187    # Mock the actual call within the gRPC stub, and fake the request.
5188    with mock.patch.object(
5189        type(client.transport.update_cmek_settings), "__call__"
5190    ) as call:
5191        client.update_cmek_settings()
5192        call.assert_called()
5193        _, args, _ = call.mock_calls[0]
5194        assert args[0] == logging_config.UpdateCmekSettingsRequest()
5195
5196
5197@pytest.mark.asyncio
5198async def test_update_cmek_settings_async(
5199    transport: str = "grpc_asyncio",
5200    request_type=logging_config.UpdateCmekSettingsRequest,
5201):
5202    client = ConfigServiceV2AsyncClient(
5203        credentials=ga_credentials.AnonymousCredentials(), transport=transport,
5204    )
5205
5206    # Everything is optional in proto3 as far as the runtime is concerned,
5207    # and we are mocking out the actual API, so just send an empty request.
5208    request = request_type()
5209
5210    # Mock the actual call within the gRPC stub, and fake the request.
5211    with mock.patch.object(
5212        type(client.transport.update_cmek_settings), "__call__"
5213    ) as call:
5214        # Designate an appropriate return value for the call.
5215        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
5216            logging_config.CmekSettings(
5217                name="name_value",
5218                kms_key_name="kms_key_name_value",
5219                service_account_id="service_account_id_value",
5220            )
5221        )
5222        response = await client.update_cmek_settings(request)
5223
5224        # Establish that the underlying gRPC stub method was called.
5225        assert len(call.mock_calls)
5226        _, args, _ = call.mock_calls[0]
5227        assert args[0] == logging_config.UpdateCmekSettingsRequest()
5228
5229    # Establish that the response is the type that we expect.
5230    assert isinstance(response, logging_config.CmekSettings)
5231    assert response.name == "name_value"
5232    assert response.kms_key_name == "kms_key_name_value"
5233    assert response.service_account_id == "service_account_id_value"
5234
5235
5236@pytest.mark.asyncio
5237async def test_update_cmek_settings_async_from_dict():
5238    await test_update_cmek_settings_async(request_type=dict)
5239
5240
5241def test_update_cmek_settings_field_headers():
5242    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
5243
5244    # Any value that is part of the HTTP/1.1 URI should be sent as
5245    # a field header. Set these to a non-empty value.
5246    request = logging_config.UpdateCmekSettingsRequest()
5247
5248    request.name = "name/value"
5249
5250    # Mock the actual call within the gRPC stub, and fake the request.
5251    with mock.patch.object(
5252        type(client.transport.update_cmek_settings), "__call__"
5253    ) as call:
5254        call.return_value = logging_config.CmekSettings()
5255        client.update_cmek_settings(request)
5256
5257        # Establish that the underlying gRPC stub method was called.
5258        assert len(call.mock_calls) == 1
5259        _, args, _ = call.mock_calls[0]
5260        assert args[0] == request
5261
5262    # Establish that the field header was sent.
5263    _, _, kw = call.mock_calls[0]
5264    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
5265
5266
5267@pytest.mark.asyncio
5268async def test_update_cmek_settings_field_headers_async():
5269    client = ConfigServiceV2AsyncClient(
5270        credentials=ga_credentials.AnonymousCredentials(),
5271    )
5272
5273    # Any value that is part of the HTTP/1.1 URI should be sent as
5274    # a field header. Set these to a non-empty value.
5275    request = logging_config.UpdateCmekSettingsRequest()
5276
5277    request.name = "name/value"
5278
5279    # Mock the actual call within the gRPC stub, and fake the request.
5280    with mock.patch.object(
5281        type(client.transport.update_cmek_settings), "__call__"
5282    ) as call:
5283        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
5284            logging_config.CmekSettings()
5285        )
5286        await client.update_cmek_settings(request)
5287
5288        # Establish that the underlying gRPC stub method was called.
5289        assert len(call.mock_calls)
5290        _, args, _ = call.mock_calls[0]
5291        assert args[0] == request
5292
5293    # Establish that the field header was sent.
5294    _, _, kw = call.mock_calls[0]
5295    assert ("x-goog-request-params", "name=name/value",) in kw["metadata"]
5296
5297
5298def test_credentials_transport_error():
5299    # It is an error to provide credentials and a transport instance.
5300    transport = transports.ConfigServiceV2GrpcTransport(
5301        credentials=ga_credentials.AnonymousCredentials(),
5302    )
5303    with pytest.raises(ValueError):
5304        client = ConfigServiceV2Client(
5305            credentials=ga_credentials.AnonymousCredentials(), transport=transport,
5306        )
5307
5308    # It is an error to provide a credentials file and a transport instance.
5309    transport = transports.ConfigServiceV2GrpcTransport(
5310        credentials=ga_credentials.AnonymousCredentials(),
5311    )
5312    with pytest.raises(ValueError):
5313        client = ConfigServiceV2Client(
5314            client_options={"credentials_file": "credentials.json"},
5315            transport=transport,
5316        )
5317
5318    # It is an error to provide scopes and a transport instance.
5319    transport = transports.ConfigServiceV2GrpcTransport(
5320        credentials=ga_credentials.AnonymousCredentials(),
5321    )
5322    with pytest.raises(ValueError):
5323        client = ConfigServiceV2Client(
5324            client_options={"scopes": ["1", "2"]}, transport=transport,
5325        )
5326
5327
5328def test_transport_instance():
5329    # A client may be instantiated with a custom transport instance.
5330    transport = transports.ConfigServiceV2GrpcTransport(
5331        credentials=ga_credentials.AnonymousCredentials(),
5332    )
5333    client = ConfigServiceV2Client(transport=transport)
5334    assert client.transport is transport
5335
5336
5337def test_transport_get_channel():
5338    # A client may be instantiated with a custom transport instance.
5339    transport = transports.ConfigServiceV2GrpcTransport(
5340        credentials=ga_credentials.AnonymousCredentials(),
5341    )
5342    channel = transport.grpc_channel
5343    assert channel
5344
5345    transport = transports.ConfigServiceV2GrpcAsyncIOTransport(
5346        credentials=ga_credentials.AnonymousCredentials(),
5347    )
5348    channel = transport.grpc_channel
5349    assert channel
5350
5351
5352@pytest.mark.parametrize(
5353    "transport_class",
5354    [
5355        transports.ConfigServiceV2GrpcTransport,
5356        transports.ConfigServiceV2GrpcAsyncIOTransport,
5357    ],
5358)
5359def test_transport_adc(transport_class):
5360    # Test default credentials are used if not provided.
5361    with mock.patch.object(google.auth, "default") as adc:
5362        adc.return_value = (ga_credentials.AnonymousCredentials(), None)
5363        transport_class()
5364        adc.assert_called_once()
5365
5366
5367def test_transport_grpc_default():
5368    # A client should use the gRPC transport by default.
5369    client = ConfigServiceV2Client(credentials=ga_credentials.AnonymousCredentials(),)
5370    assert isinstance(client.transport, transports.ConfigServiceV2GrpcTransport,)
5371
5372
5373def test_config_service_v2_base_transport_error():
5374    # Passing both a credentials object and credentials_file should raise an error
5375    with pytest.raises(core_exceptions.DuplicateCredentialArgs):
5376        transport = transports.ConfigServiceV2Transport(
5377            credentials=ga_credentials.AnonymousCredentials(),
5378            credentials_file="credentials.json",
5379        )
5380
5381
5382def test_config_service_v2_base_transport():
5383    # Instantiate the base transport.
5384    with mock.patch(
5385        "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport.__init__"
5386    ) as Transport:
5387        Transport.return_value = None
5388        transport = transports.ConfigServiceV2Transport(
5389            credentials=ga_credentials.AnonymousCredentials(),
5390        )
5391
5392    # Every method on the transport should just blindly
5393    # raise NotImplementedError.
5394    methods = (
5395        "list_buckets",
5396        "get_bucket",
5397        "create_bucket",
5398        "update_bucket",
5399        "delete_bucket",
5400        "undelete_bucket",
5401        "list_views",
5402        "get_view",
5403        "create_view",
5404        "update_view",
5405        "delete_view",
5406        "list_sinks",
5407        "get_sink",
5408        "create_sink",
5409        "update_sink",
5410        "delete_sink",
5411        "list_exclusions",
5412        "get_exclusion",
5413        "create_exclusion",
5414        "update_exclusion",
5415        "delete_exclusion",
5416        "get_cmek_settings",
5417        "update_cmek_settings",
5418    )
5419    for method in methods:
5420        with pytest.raises(NotImplementedError):
5421            getattr(transport, method)(request=object())
5422
5423    with pytest.raises(NotImplementedError):
5424        transport.close()
5425
5426
5427def test_config_service_v2_base_transport_with_credentials_file():
5428    # Instantiate the base transport with a credentials file
5429    with mock.patch.object(
5430        google.auth, "load_credentials_from_file", autospec=True
5431    ) as load_creds, mock.patch(
5432        "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport._prep_wrapped_messages"
5433    ) as Transport:
5434        Transport.return_value = None
5435        load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
5436        transport = transports.ConfigServiceV2Transport(
5437            credentials_file="credentials.json", quota_project_id="octopus",
5438        )
5439        load_creds.assert_called_once_with(
5440            "credentials.json",
5441            scopes=None,
5442            default_scopes=(
5443                "https://www.googleapis.com/auth/cloud-platform",
5444                "https://www.googleapis.com/auth/cloud-platform.read-only",
5445                "https://www.googleapis.com/auth/logging.admin",
5446                "https://www.googleapis.com/auth/logging.read",
5447            ),
5448            quota_project_id="octopus",
5449        )
5450
5451
5452def test_config_service_v2_base_transport_with_adc():
5453    # Test the default credentials are used if credentials and credentials_file are None.
5454    with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch(
5455        "google.cloud.logging_v2.services.config_service_v2.transports.ConfigServiceV2Transport._prep_wrapped_messages"
5456    ) as Transport:
5457        Transport.return_value = None
5458        adc.return_value = (ga_credentials.AnonymousCredentials(), None)
5459        transport = transports.ConfigServiceV2Transport()
5460        adc.assert_called_once()
5461
5462
5463def test_config_service_v2_auth_adc():
5464    # If no credentials are provided, we should use ADC credentials.
5465    with mock.patch.object(google.auth, "default", autospec=True) as adc:
5466        adc.return_value = (ga_credentials.AnonymousCredentials(), None)
5467        ConfigServiceV2Client()
5468        adc.assert_called_once_with(
5469            scopes=None,
5470            default_scopes=(
5471                "https://www.googleapis.com/auth/cloud-platform",
5472                "https://www.googleapis.com/auth/cloud-platform.read-only",
5473                "https://www.googleapis.com/auth/logging.admin",
5474                "https://www.googleapis.com/auth/logging.read",
5475            ),
5476            quota_project_id=None,
5477        )
5478
5479
5480@pytest.mark.parametrize(
5481    "transport_class",
5482    [
5483        transports.ConfigServiceV2GrpcTransport,
5484        transports.ConfigServiceV2GrpcAsyncIOTransport,
5485    ],
5486)
5487def test_config_service_v2_transport_auth_adc(transport_class):
5488    # If credentials and host are not provided, the transport class should use
5489    # ADC credentials.
5490    with mock.patch.object(google.auth, "default", autospec=True) as adc:
5491        adc.return_value = (ga_credentials.AnonymousCredentials(), None)
5492        transport_class(quota_project_id="octopus", scopes=["1", "2"])
5493        adc.assert_called_once_with(
5494            scopes=["1", "2"],
5495            default_scopes=(
5496                "https://www.googleapis.com/auth/cloud-platform",
5497                "https://www.googleapis.com/auth/cloud-platform.read-only",
5498                "https://www.googleapis.com/auth/logging.admin",
5499                "https://www.googleapis.com/auth/logging.read",
5500            ),
5501            quota_project_id="octopus",
5502        )
5503
5504
5505@pytest.mark.parametrize(
5506    "transport_class,grpc_helpers",
5507    [
5508        (transports.ConfigServiceV2GrpcTransport, grpc_helpers),
5509        (transports.ConfigServiceV2GrpcAsyncIOTransport, grpc_helpers_async),
5510    ],
5511)
5512def test_config_service_v2_transport_create_channel(transport_class, grpc_helpers):
5513    # If credentials and host are not provided, the transport class should use
5514    # ADC credentials.
5515    with mock.patch.object(
5516        google.auth, "default", autospec=True
5517    ) as adc, mock.patch.object(
5518        grpc_helpers, "create_channel", autospec=True
5519    ) as create_channel:
5520        creds = ga_credentials.AnonymousCredentials()
5521        adc.return_value = (creds, None)
5522        transport_class(quota_project_id="octopus", scopes=["1", "2"])
5523
5524        create_channel.assert_called_with(
5525            "logging.googleapis.com:443",
5526            credentials=creds,
5527            credentials_file=None,
5528            quota_project_id="octopus",
5529            default_scopes=(
5530                "https://www.googleapis.com/auth/cloud-platform",
5531                "https://www.googleapis.com/auth/cloud-platform.read-only",
5532                "https://www.googleapis.com/auth/logging.admin",
5533                "https://www.googleapis.com/auth/logging.read",
5534            ),
5535            scopes=["1", "2"],
5536            default_host="logging.googleapis.com",
5537            ssl_credentials=None,
5538            options=[
5539                ("grpc.max_send_message_length", -1),
5540                ("grpc.max_receive_message_length", -1),
5541            ],
5542        )
5543
5544
5545@pytest.mark.parametrize(
5546    "transport_class",
5547    [
5548        transports.ConfigServiceV2GrpcTransport,
5549        transports.ConfigServiceV2GrpcAsyncIOTransport,
5550    ],
5551)
5552def test_config_service_v2_grpc_transport_client_cert_source_for_mtls(transport_class):
5553    cred = ga_credentials.AnonymousCredentials()
5554
5555    # Check ssl_channel_credentials is used if provided.
5556    with mock.patch.object(transport_class, "create_channel") as mock_create_channel:
5557        mock_ssl_channel_creds = mock.Mock()
5558        transport_class(
5559            host="squid.clam.whelk",
5560            credentials=cred,
5561            ssl_channel_credentials=mock_ssl_channel_creds,
5562        )
5563        mock_create_channel.assert_called_once_with(
5564            "squid.clam.whelk:443",
5565            credentials=cred,
5566            credentials_file=None,
5567            scopes=None,
5568            ssl_credentials=mock_ssl_channel_creds,
5569            quota_project_id=None,
5570            options=[
5571                ("grpc.max_send_message_length", -1),
5572                ("grpc.max_receive_message_length", -1),
5573            ],
5574        )
5575
5576    # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls
5577    # is used.
5578    with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()):
5579        with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred:
5580            transport_class(
5581                credentials=cred,
5582                client_cert_source_for_mtls=client_cert_source_callback,
5583            )
5584            expected_cert, expected_key = client_cert_source_callback()
5585            mock_ssl_cred.assert_called_once_with(
5586                certificate_chain=expected_cert, private_key=expected_key
5587            )
5588
5589
5590def test_config_service_v2_host_no_port():
5591    client = ConfigServiceV2Client(
5592        credentials=ga_credentials.AnonymousCredentials(),
5593        client_options=client_options.ClientOptions(
5594            api_endpoint="logging.googleapis.com"
5595        ),
5596    )
5597    assert client.transport._host == "logging.googleapis.com:443"
5598
5599
5600def test_config_service_v2_host_with_port():
5601    client = ConfigServiceV2Client(
5602        credentials=ga_credentials.AnonymousCredentials(),
5603        client_options=client_options.ClientOptions(
5604            api_endpoint="logging.googleapis.com:8000"
5605        ),
5606    )
5607    assert client.transport._host == "logging.googleapis.com:8000"
5608
5609
5610def test_config_service_v2_grpc_transport_channel():
5611    channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials())
5612
5613    # Check that channel is used if provided.
5614    transport = transports.ConfigServiceV2GrpcTransport(
5615        host="squid.clam.whelk", channel=channel,
5616    )
5617    assert transport.grpc_channel == channel
5618    assert transport._host == "squid.clam.whelk:443"
5619    assert transport._ssl_channel_credentials == None
5620
5621
5622def test_config_service_v2_grpc_asyncio_transport_channel():
5623    channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials())
5624
5625    # Check that channel is used if provided.
5626    transport = transports.ConfigServiceV2GrpcAsyncIOTransport(
5627        host="squid.clam.whelk", channel=channel,
5628    )
5629    assert transport.grpc_channel == channel
5630    assert transport._host == "squid.clam.whelk:443"
5631    assert transport._ssl_channel_credentials == None
5632
5633
5634# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are
5635# removed from grpc/grpc_asyncio transport constructor.
5636@pytest.mark.parametrize(
5637    "transport_class",
5638    [
5639        transports.ConfigServiceV2GrpcTransport,
5640        transports.ConfigServiceV2GrpcAsyncIOTransport,
5641    ],
5642)
5643def test_config_service_v2_transport_channel_mtls_with_client_cert_source(
5644    transport_class,
5645):
5646    with mock.patch(
5647        "grpc.ssl_channel_credentials", autospec=True
5648    ) as grpc_ssl_channel_cred:
5649        with mock.patch.object(
5650            transport_class, "create_channel"
5651        ) as grpc_create_channel:
5652            mock_ssl_cred = mock.Mock()
5653            grpc_ssl_channel_cred.return_value = mock_ssl_cred
5654
5655            mock_grpc_channel = mock.Mock()
5656            grpc_create_channel.return_value = mock_grpc_channel
5657
5658            cred = ga_credentials.AnonymousCredentials()
5659            with pytest.warns(DeprecationWarning):
5660                with mock.patch.object(google.auth, "default") as adc:
5661                    adc.return_value = (cred, None)
5662                    transport = transport_class(
5663                        host="squid.clam.whelk",
5664                        api_mtls_endpoint="mtls.squid.clam.whelk",
5665                        client_cert_source=client_cert_source_callback,
5666                    )
5667                    adc.assert_called_once()
5668
5669            grpc_ssl_channel_cred.assert_called_once_with(
5670                certificate_chain=b"cert bytes", private_key=b"key bytes"
5671            )
5672            grpc_create_channel.assert_called_once_with(
5673                "mtls.squid.clam.whelk:443",
5674                credentials=cred,
5675                credentials_file=None,
5676                scopes=None,
5677                ssl_credentials=mock_ssl_cred,
5678                quota_project_id=None,
5679                options=[
5680                    ("grpc.max_send_message_length", -1),
5681                    ("grpc.max_receive_message_length", -1),
5682                ],
5683            )
5684            assert transport.grpc_channel == mock_grpc_channel
5685            assert transport._ssl_channel_credentials == mock_ssl_cred
5686
5687
5688# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are
5689# removed from grpc/grpc_asyncio transport constructor.
5690@pytest.mark.parametrize(
5691    "transport_class",
5692    [
5693        transports.ConfigServiceV2GrpcTransport,
5694        transports.ConfigServiceV2GrpcAsyncIOTransport,
5695    ],
5696)
5697def test_config_service_v2_transport_channel_mtls_with_adc(transport_class):
5698    mock_ssl_cred = mock.Mock()
5699    with mock.patch.multiple(
5700        "google.auth.transport.grpc.SslCredentials",
5701        __init__=mock.Mock(return_value=None),
5702        ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred),
5703    ):
5704        with mock.patch.object(
5705            transport_class, "create_channel"
5706        ) as grpc_create_channel:
5707            mock_grpc_channel = mock.Mock()
5708            grpc_create_channel.return_value = mock_grpc_channel
5709            mock_cred = mock.Mock()
5710
5711            with pytest.warns(DeprecationWarning):
5712                transport = transport_class(
5713                    host="squid.clam.whelk",
5714                    credentials=mock_cred,
5715                    api_mtls_endpoint="mtls.squid.clam.whelk",
5716                    client_cert_source=None,
5717                )
5718
5719            grpc_create_channel.assert_called_once_with(
5720                "mtls.squid.clam.whelk:443",
5721                credentials=mock_cred,
5722                credentials_file=None,
5723                scopes=None,
5724                ssl_credentials=mock_ssl_cred,
5725                quota_project_id=None,
5726                options=[
5727                    ("grpc.max_send_message_length", -1),
5728                    ("grpc.max_receive_message_length", -1),
5729                ],
5730            )
5731            assert transport.grpc_channel == mock_grpc_channel
5732
5733
5734def test_cmek_settings_path():
5735    project = "squid"
5736    expected = "projects/{project}/cmekSettings".format(project=project,)
5737    actual = ConfigServiceV2Client.cmek_settings_path(project)
5738    assert expected == actual
5739
5740
5741def test_parse_cmek_settings_path():
5742    expected = {
5743        "project": "clam",
5744    }
5745    path = ConfigServiceV2Client.cmek_settings_path(**expected)
5746
5747    # Check that the path construction is reversible.
5748    actual = ConfigServiceV2Client.parse_cmek_settings_path(path)
5749    assert expected == actual
5750
5751
5752def test_log_bucket_path():
5753    project = "whelk"
5754    location = "octopus"
5755    bucket = "oyster"
5756    expected = "projects/{project}/locations/{location}/buckets/{bucket}".format(
5757        project=project, location=location, bucket=bucket,
5758    )
5759    actual = ConfigServiceV2Client.log_bucket_path(project, location, bucket)
5760    assert expected == actual
5761
5762
5763def test_parse_log_bucket_path():
5764    expected = {
5765        "project": "nudibranch",
5766        "location": "cuttlefish",
5767        "bucket": "mussel",
5768    }
5769    path = ConfigServiceV2Client.log_bucket_path(**expected)
5770
5771    # Check that the path construction is reversible.
5772    actual = ConfigServiceV2Client.parse_log_bucket_path(path)
5773    assert expected == actual
5774
5775
5776def test_log_exclusion_path():
5777    project = "winkle"
5778    exclusion = "nautilus"
5779    expected = "projects/{project}/exclusions/{exclusion}".format(
5780        project=project, exclusion=exclusion,
5781    )
5782    actual = ConfigServiceV2Client.log_exclusion_path(project, exclusion)
5783    assert expected == actual
5784
5785
5786def test_parse_log_exclusion_path():
5787    expected = {
5788        "project": "scallop",
5789        "exclusion": "abalone",
5790    }
5791    path = ConfigServiceV2Client.log_exclusion_path(**expected)
5792
5793    # Check that the path construction is reversible.
5794    actual = ConfigServiceV2Client.parse_log_exclusion_path(path)
5795    assert expected == actual
5796
5797
5798def test_log_sink_path():
5799    project = "squid"
5800    sink = "clam"
5801    expected = "projects/{project}/sinks/{sink}".format(project=project, sink=sink,)
5802    actual = ConfigServiceV2Client.log_sink_path(project, sink)
5803    assert expected == actual
5804
5805
5806def test_parse_log_sink_path():
5807    expected = {
5808        "project": "whelk",
5809        "sink": "octopus",
5810    }
5811    path = ConfigServiceV2Client.log_sink_path(**expected)
5812
5813    # Check that the path construction is reversible.
5814    actual = ConfigServiceV2Client.parse_log_sink_path(path)
5815    assert expected == actual
5816
5817
5818def test_log_view_path():
5819    project = "oyster"
5820    location = "nudibranch"
5821    bucket = "cuttlefish"
5822    view = "mussel"
5823    expected = "projects/{project}/locations/{location}/buckets/{bucket}/views/{view}".format(
5824        project=project, location=location, bucket=bucket, view=view,
5825    )
5826    actual = ConfigServiceV2Client.log_view_path(project, location, bucket, view)
5827    assert expected == actual
5828
5829
5830def test_parse_log_view_path():
5831    expected = {
5832        "project": "winkle",
5833        "location": "nautilus",
5834        "bucket": "scallop",
5835        "view": "abalone",
5836    }
5837    path = ConfigServiceV2Client.log_view_path(**expected)
5838
5839    # Check that the path construction is reversible.
5840    actual = ConfigServiceV2Client.parse_log_view_path(path)
5841    assert expected == actual
5842
5843
5844def test_common_billing_account_path():
5845    billing_account = "squid"
5846    expected = "billingAccounts/{billing_account}".format(
5847        billing_account=billing_account,
5848    )
5849    actual = ConfigServiceV2Client.common_billing_account_path(billing_account)
5850    assert expected == actual
5851
5852
5853def test_parse_common_billing_account_path():
5854    expected = {
5855        "billing_account": "clam",
5856    }
5857    path = ConfigServiceV2Client.common_billing_account_path(**expected)
5858
5859    # Check that the path construction is reversible.
5860    actual = ConfigServiceV2Client.parse_common_billing_account_path(path)
5861    assert expected == actual
5862
5863
5864def test_common_folder_path():
5865    folder = "whelk"
5866    expected = "folders/{folder}".format(folder=folder,)
5867    actual = ConfigServiceV2Client.common_folder_path(folder)
5868    assert expected == actual
5869
5870
5871def test_parse_common_folder_path():
5872    expected = {
5873        "folder": "octopus",
5874    }
5875    path = ConfigServiceV2Client.common_folder_path(**expected)
5876
5877    # Check that the path construction is reversible.
5878    actual = ConfigServiceV2Client.parse_common_folder_path(path)
5879    assert expected == actual
5880
5881
5882def test_common_organization_path():
5883    organization = "oyster"
5884    expected = "organizations/{organization}".format(organization=organization,)
5885    actual = ConfigServiceV2Client.common_organization_path(organization)
5886    assert expected == actual
5887
5888
5889def test_parse_common_organization_path():
5890    expected = {
5891        "organization": "nudibranch",
5892    }
5893    path = ConfigServiceV2Client.common_organization_path(**expected)
5894
5895    # Check that the path construction is reversible.
5896    actual = ConfigServiceV2Client.parse_common_organization_path(path)
5897    assert expected == actual
5898
5899
5900def test_common_project_path():
5901    project = "cuttlefish"
5902    expected = "projects/{project}".format(project=project,)
5903    actual = ConfigServiceV2Client.common_project_path(project)
5904    assert expected == actual
5905
5906
5907def test_parse_common_project_path():
5908    expected = {
5909        "project": "mussel",
5910    }
5911    path = ConfigServiceV2Client.common_project_path(**expected)
5912
5913    # Check that the path construction is reversible.
5914    actual = ConfigServiceV2Client.parse_common_project_path(path)
5915    assert expected == actual
5916
5917
5918def test_common_location_path():
5919    project = "winkle"
5920    location = "nautilus"
5921    expected = "projects/{project}/locations/{location}".format(
5922        project=project, location=location,
5923    )
5924    actual = ConfigServiceV2Client.common_location_path(project, location)
5925    assert expected == actual
5926
5927
5928def test_parse_common_location_path():
5929    expected = {
5930        "project": "scallop",
5931        "location": "abalone",
5932    }
5933    path = ConfigServiceV2Client.common_location_path(**expected)
5934
5935    # Check that the path construction is reversible.
5936    actual = ConfigServiceV2Client.parse_common_location_path(path)
5937    assert expected == actual
5938
5939
5940def test_client_withDEFAULT_CLIENT_INFO():
5941    client_info = gapic_v1.client_info.ClientInfo()
5942
5943    with mock.patch.object(
5944        transports.ConfigServiceV2Transport, "_prep_wrapped_messages"
5945    ) as prep:
5946        client = ConfigServiceV2Client(
5947            credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
5948        )
5949        prep.assert_called_once_with(client_info)
5950
5951    with mock.patch.object(
5952        transports.ConfigServiceV2Transport, "_prep_wrapped_messages"
5953    ) as prep:
5954        transport_class = ConfigServiceV2Client.get_transport_class()
5955        transport = transport_class(
5956            credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
5957        )
5958        prep.assert_called_once_with(client_info)
5959
5960
5961@pytest.mark.asyncio
5962async def test_transport_close_async():
5963    client = ConfigServiceV2AsyncClient(
5964        credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio",
5965    )
5966    with mock.patch.object(
5967        type(getattr(client.transport, "grpc_channel")), "close"
5968    ) as close:
5969        async with client:
5970            close.assert_not_called()
5971        close.assert_called_once()
5972
5973
5974def test_transport_close():
5975    transports = {
5976        "grpc": "_grpc_channel",
5977    }
5978
5979    for transport, close_name in transports.items():
5980        client = ConfigServiceV2Client(
5981            credentials=ga_credentials.AnonymousCredentials(), transport=transport
5982        )
5983        with mock.patch.object(
5984            type(getattr(client.transport, close_name)), "close"
5985        ) as close:
5986            with client:
5987                close.assert_not_called()
5988            close.assert_called_once()
5989
5990
5991def test_client_ctx():
5992    transports = [
5993        "grpc",
5994    ]
5995    for transport in transports:
5996        client = ConfigServiceV2Client(
5997            credentials=ga_credentials.AnonymousCredentials(), transport=transport
5998        )
5999        # Test client calls underlying transport.
6000        with mock.patch.object(type(client.transport), "close") as close:
6001            close.assert_not_called()
6002            with client:
6003                pass
6004            close.assert_called()
6005