From fad1da04120536818bc950f72bbc2a3c44bb3a3b Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 21 Nov 2018 11:37:02 -0500 Subject: [PATCH] Websecurityscanner: pick up fixes to GAPIC generator. (#6633) Includes fixes from these PRs: - googleapis/gapic-generator#2407 - googleapis/gapic-generator#2396 Includes changes to generated tests. Closes #6476. --- .../web_security_scanner_grpc_transport.py | 11 ++ .../gapic/web_security_scanner_client.py | 17 +- synth.py | 1 + ...est_web_security_scanner_client_v1alpha.py | 159 ++++++++++++------ 4 files changed, 131 insertions(+), 57 deletions(-) diff --git a/google/cloud/websecurityscanner_v1alpha/gapic/transports/web_security_scanner_grpc_transport.py b/google/cloud/websecurityscanner_v1alpha/gapic/transports/web_security_scanner_grpc_transport.py index fa648a2..1e6e1e4 100644 --- a/google/cloud/websecurityscanner_v1alpha/gapic/transports/web_security_scanner_grpc_transport.py +++ b/google/cloud/websecurityscanner_v1alpha/gapic/transports/web_security_scanner_grpc_transport.py @@ -62,6 +62,8 @@ def __init__(self, credentials=credentials, ) + self._channel = channel + # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. self._stubs = { @@ -92,6 +94,15 @@ def create_channel(cls, scopes=cls._OAUTH_SCOPES, ) + @property + def channel(self): + """The gRPC channel used by the transport. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return self._channel + @property def create_scan_config(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py b/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py index cdb8b92..ff6e8b3 100644 --- a/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py +++ b/google/cloud/websecurityscanner_v1alpha/gapic/web_security_scanner_client.py @@ -120,7 +120,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=web_security_scanner_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -153,13 +153,20 @@ def __init__(self, your own client library. """ # Raise deprecation warnings for things we want to go away. - if client_config: - warnings.warn('The `client_config` argument is deprecated.', - PendingDeprecationWarning) + if client_config is not None: + warnings.warn( + 'The `client_config` argument is deprecated.', + PendingDeprecationWarning, + stacklevel=2) + else: + client_config = web_security_scanner_client_config.config + if channel: warnings.warn( 'The `channel` argument is deprecated; use ' - '`transport` instead.', PendingDeprecationWarning) + '`transport` instead.', + PendingDeprecationWarning, + stacklevel=2) # Instantiate the transport. # The transport is responsible for handling serialization and diff --git a/synth.py b/synth.py index e395ec5..3154605 100644 --- a/synth.py +++ b/synth.py @@ -31,3 +31,4 @@ s.move(library / 'google/cloud/websecurityscanner_v1alpha/proto') s.move(library / 'google/cloud/websecurityscanner_v1alpha/gapic') +s.move(library / 'tests/unit/gapic/v1alpha') diff --git a/tests/unit/gapic/v1alpha/test_web_security_scanner_client_v1alpha.py b/tests/unit/gapic/v1alpha/test_web_security_scanner_client_v1alpha.py index f3d24fb..310509a 100644 --- a/tests/unit/gapic/v1alpha/test_web_security_scanner_client_v1alpha.py +++ b/tests/unit/gapic/v1alpha/test_web_security_scanner_client_v1alpha.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.cloud import websecurityscanner_v1alpha @@ -79,8 +82,10 @@ def test_create_scan_config(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request parent = client.project_path('[PROJECT]') @@ -98,8 +103,10 @@ def test_create_scan_config(self): def test_create_scan_config_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request parent = client.project_path('[PROJECT]') @@ -110,8 +117,10 @@ def test_create_scan_config_exception(self): def test_delete_scan_config(self): channel = ChannelStub() - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request name = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -127,8 +136,10 @@ def test_delete_scan_config(self): def test_delete_scan_config_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request name = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -150,8 +161,10 @@ def test_get_scan_config(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request name = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -168,8 +181,10 @@ def test_get_scan_config(self): def test_get_scan_config_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request name = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -191,8 +206,10 @@ def test_list_scan_configs(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request parent = client.project_path('[PROJECT]') @@ -211,8 +228,10 @@ def test_list_scan_configs(self): def test_list_scan_configs_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request parent = client.project_path('[PROJECT]') @@ -235,8 +254,10 @@ def test_update_scan_config(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request scan_config = {} @@ -254,8 +275,10 @@ def test_update_scan_config(self): def test_update_scan_config_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request scan_config = {} @@ -282,8 +305,10 @@ def test_start_scan_run(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request name = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -300,8 +325,10 @@ def test_start_scan_run(self): def test_start_scan_run_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request name = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -327,8 +354,10 @@ def test_get_scan_run(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request name = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', '[SCAN_RUN]') @@ -345,8 +374,10 @@ def test_get_scan_run(self): def test_get_scan_run_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request name = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', '[SCAN_RUN]') @@ -368,8 +399,10 @@ def test_list_scan_runs(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request parent = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -388,8 +421,10 @@ def test_list_scan_runs(self): def test_list_scan_runs_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request parent = client.scan_config_path('[PROJECT]', '[SCAN_CONFIG]') @@ -416,8 +451,10 @@ def test_stop_scan_run(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request name = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', '[SCAN_RUN]') @@ -434,8 +471,10 @@ def test_stop_scan_run(self): def test_stop_scan_run_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request name = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', '[SCAN_RUN]') @@ -457,8 +496,10 @@ def test_list_crawled_urls(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request parent = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', @@ -478,8 +519,10 @@ def test_list_crawled_urls(self): def test_list_crawled_urls_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request parent = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', @@ -515,8 +558,10 @@ def test_get_finding(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request name = client.finding_path('[PROJECT]', '[SCAN_CONFIG]', '[SCAN_RUN]', @@ -534,8 +579,10 @@ def test_get_finding(self): def test_get_finding_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request name = client.finding_path('[PROJECT]', '[SCAN_CONFIG]', '[SCAN_RUN]', @@ -558,8 +605,10 @@ def test_list_findings(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request parent = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', @@ -580,8 +629,10 @@ def test_list_findings(self): def test_list_findings_exception(self): channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request parent = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', @@ -600,8 +651,10 @@ def test_list_finding_type_stats(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup Request parent = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]', @@ -619,8 +672,10 @@ def test_list_finding_type_stats(self): def test_list_finding_type_stats_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = websecurityscanner_v1alpha.WebSecurityScannerClient( - channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = websecurityscanner_v1alpha.WebSecurityScannerClient() # Setup request parent = client.scan_run_path('[PROJECT]', '[SCAN_CONFIG]',