| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 132afa1 commit 8618ef5
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -467,7 +467,7 @@ async def get_metadata( | |||
| 467 | 467 | ||
| 468 | 468 | """ | |
| 469 | 469 | # Create or coerce a protobuf request object. | |
| 470 | - # Sanity check: If we got a request object, we should *not* have | ||
| 470 | + # Quick check: If we got a request object, we should *not* have | ||
| 471 | 471 | # gotten any keyword arguments that map to the request. | |
| 472 | 472 | has_flattened_params = any([name]) | |
| 473 | 473 | if request is not None and has_flattened_params: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -665,7 +665,7 @@ def get_metadata( | |||
| 665 | 665 | ||
| 666 | 666 | """ | |
| 667 | 667 | # Create or coerce a protobuf request object. | |
| 668 | - # Sanity check: If we got a request object, we should *not* have | ||
| 668 | + # Quick check: If we got a request object, we should *not* have | ||
| 669 | 669 | # gotten any keyword arguments that map to the request. | |
| 670 | 670 | has_flattened_params = any([name]) | |
| 671 | 671 | if request is not None and has_flattened_params: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,8 +158,11 @@ def __init__( | |||
| 158 | 158 | if not self._grpc_channel: | |
| 159 | 159 | self._grpc_channel = type(self).create_channel( | |
| 160 | 160 | self._host, | |
| 161 | + # use the credentials which are saved | ||
| 161 | 162 | credentials=self._credentials, | |
| 162 | - credentials_file=credentials_file, | ||
| 163 | + # Set ``credentials_file`` to ``None`` here as | ||
| 164 | + # the credentials that we saved earlier should be used. | ||
| 165 | + credentials_file=None, | ||
| 163 | 166 | scopes=self._scopes, | |
| 164 | 167 | ssl_credentials=self._ssl_channel_credentials, | |
| 165 | 168 | quota_project_id=quota_project_id, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -203,8 +203,11 @@ def __init__( | |||
| 203 | 203 | if not self._grpc_channel: | |
| 204 | 204 | self._grpc_channel = type(self).create_channel( | |
| 205 | 205 | self._host, | |
| 206 | + # use the credentials which are saved | ||
| 206 | 207 | credentials=self._credentials, | |
| 207 | - credentials_file=credentials_file, | ||
| 208 | + # Set ``credentials_file`` to ``None`` here as | ||
| 209 | + # the credentials that we saved earlier should be used. | ||
| 210 | + credentials_file=None, | ||
| 208 | 211 | scopes=self._scopes, | |
| 209 | 212 | ssl_credentials=self._ssl_channel_credentials, | |
| 210 | 213 | quota_project_id=quota_project_id, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -523,21 +523,28 @@ def test_beta_analytics_data_client_client_options_scopes( | |||
| 523 | 523 | ||
| 524 | 524 | ||
| 525 | 525 | @pytest.mark.parametrize( | |
| 526 | - "client_class,transport_class,transport_name", | ||
| 526 | + "client_class,transport_class,transport_name,grpc_helpers", | ||
| 527 | 527 | [ | |
| 528 | - (BetaAnalyticsDataClient, transports.BetaAnalyticsDataGrpcTransport, "grpc"), | ||
| 528 | + ( | ||
| 529 | + BetaAnalyticsDataClient, | ||
| 530 | + transports.BetaAnalyticsDataGrpcTransport, | ||
| 531 | + "grpc", | ||
| 532 | + grpc_helpers, | ||
| 533 | + ), | ||
| 529 | 534 | ( | |
| 530 | 535 | BetaAnalyticsDataAsyncClient, | |
| 531 | 536 | transports.BetaAnalyticsDataGrpcAsyncIOTransport, | |
| 532 | 537 | "grpc_asyncio", | |
| 538 | + grpc_helpers_async, | ||
| 533 | 539 | ), | |
| 534 | 540 | ], | |
| 535 | 541 | ) | |
| 536 | 542 | def test_beta_analytics_data_client_client_options_credentials_file( | |
| 537 | - client_class, transport_class, transport_name | ||
| 543 | + client_class, transport_class, transport_name, grpc_helpers | ||
| 538 | 544 | ): | |
| 539 | 545 | # Check the case credentials file is provided. | |
| 540 | 546 | options = client_options.ClientOptions(credentials_file="credentials.json") | |
| 547 | + | ||
| 541 | 548 | with mock.patch.object(transport_class, "__init__") as patched: | |
| 542 | 549 | patched.return_value = None | |
| 543 | 550 | client = client_class(client_options=options, transport=transport_name) | |
@@ -573,6 +580,75 @@ def test_beta_analytics_data_client_client_options_from_dict(): | |||
| 573 | 580 | ) | |
| 574 | 581 | ||
| 575 | 582 | ||
| 583 | + @pytest.mark.parametrize( | ||
| 584 | + "client_class,transport_class,transport_name,grpc_helpers", | ||
| 585 | + [ | ||
| 586 | + ( | ||
| 587 | + BetaAnalyticsDataClient, | ||
| 588 | + transports.BetaAnalyticsDataGrpcTransport, | ||
| 589 | + "grpc", | ||
| 590 | + grpc_helpers, | ||
| 591 | + ), | ||
| 592 | + ( | ||
| 593 | + BetaAnalyticsDataAsyncClient, | ||
| 594 | + transports.BetaAnalyticsDataGrpcAsyncIOTransport, | ||
| 595 | + "grpc_asyncio", | ||
| 596 | + grpc_helpers_async, | ||
| 597 | + ), | ||
| 598 | + ], | ||
| 599 | + ) | ||
| 600 | + def test_beta_analytics_data_client_create_channel_credentials_file( | ||
| 601 | + client_class, transport_class, transport_name, grpc_helpers | ||
| 602 | + ): | ||
| 603 | + # Check the case credentials file is provided. | ||
| 604 | + options = client_options.ClientOptions(credentials_file="credentials.json") | ||
| 605 | + | ||
| 606 | + with mock.patch.object(transport_class, "__init__") as patched: | ||
| 607 | + patched.return_value = None | ||
| 608 | + client = client_class(client_options=options, transport=transport_name) | ||
| 609 | + patched.assert_called_once_with( | ||
| 610 | + credentials=None, | ||
| 611 | + credentials_file="credentials.json", | ||
| 612 | + host=client.DEFAULT_ENDPOINT, | ||
| 613 | + scopes=None, | ||
| 614 | + client_cert_source_for_mtls=None, | ||
| 615 | + quota_project_id=None, | ||
| 616 | + client_info=transports.base.DEFAULT_CLIENT_INFO, | ||
| 617 | + always_use_jwt_access=True, | ||
| 618 | + ) | ||
| 619 | + | ||
| 620 | + # test that the credentials from file are saved and used as the credentials. | ||
| 621 | + with mock.patch.object( | ||
| 622 | + google.auth, "load_credentials_from_file", autospec=True | ||
| 623 | + ) as load_creds, mock.patch.object( | ||
| 624 | + google.auth, "default", autospec=True | ||
| 625 | + ) as adc, mock.patch.object( | ||
| 626 | + grpc_helpers, "create_channel" | ||
| 627 | + ) as create_channel: | ||
| 628 | + creds = ga_credentials.AnonymousCredentials() | ||
| 629 | + file_creds = ga_credentials.AnonymousCredentials() | ||
| 630 | + load_creds.return_value = (file_creds, None) | ||
| 631 | + adc.return_value = (creds, None) | ||
| 632 | + client = client_class(client_options=options, transport=transport_name) | ||
| 633 | + create_channel.assert_called_with( | ||
| 634 | + "analyticsdata.googleapis.com:443", | ||
| 635 | + credentials=file_creds, | ||
| 636 | + credentials_file=None, | ||
| 637 | + quota_project_id=None, | ||
| 638 | + default_scopes=( | ||
| 639 | + "https://www.googleapis.com/auth/analytics", | ||
| 640 | + "https://www.googleapis.com/auth/analytics.readonly", | ||
| 641 | + ), | ||
| 642 | + scopes=None, | ||
| 643 | + default_host="analyticsdata.googleapis.com", | ||
| 644 | + ssl_credentials=None, | ||
| 645 | + options=[ | ||
| 646 | + ("grpc.max_send_message_length", -1), | ||
| 647 | + ("grpc.max_receive_message_length", -1), | ||
| 648 | + ], | ||
| 649 | + ) | ||
| 650 | + | ||
| 651 | + | ||
| 576 | 652 | @pytest.mark.parametrize("request_type", [analytics_data_api.RunReportRequest, dict,]) | |
| 577 | 653 | def test_run_report(request_type, transport: str = "grpc"): | |
| 578 | 654 | client = BetaAnalyticsDataClient( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments