Skip to content

Commit 4523af4

Browse files
authored
Pick up fixes to GAPIC generator. (#6575)
Includes fixes from these PRs: - googleapis/gapic-generator#2407 (closing googleapis/gapic-generator#2389) - googleapis/gapic-generator#2396 (for #5523 and dupes). Includes changes to generated tests. Closes #6502.
1 parent f0da536 commit 4523af4

4 files changed

Lines changed: 75 additions & 17 deletions

File tree

oslogin/google/cloud/oslogin_v1/gapic/os_login_service_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def __init__(self,
104104
transport=None,
105105
channel=None,
106106
credentials=None,
107-
client_config=os_login_service_client_config.config,
107+
client_config=None,
108108
client_info=None):
109109
"""Constructor.
110110
@@ -137,13 +137,20 @@ def __init__(self,
137137
your own client library.
138138
"""
139139
# Raise deprecation warnings for things we want to go away.
140-
if client_config:
141-
warnings.warn('The `client_config` argument is deprecated.',
142-
PendingDeprecationWarning)
140+
if client_config is not None:
141+
warnings.warn(
142+
'The `client_config` argument is deprecated.',
143+
PendingDeprecationWarning,
144+
stacklevel=2)
145+
else:
146+
client_config = os_login_service_client_config.config
147+
143148
if channel:
144149
warnings.warn(
145150
'The `channel` argument is deprecated; use '
146-
'`transport` instead.', PendingDeprecationWarning)
151+
'`transport` instead.',
152+
PendingDeprecationWarning,
153+
stacklevel=2)
147154

148155
# Instantiate the transport.
149156
# The transport is responsible for handling serialization and

oslogin/google/cloud/oslogin_v1/gapic/transports/os_login_service_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def __init__(self,
6767
credentials=credentials,
6868
)
6969

70+
self._channel = channel
71+
7072
# gRPC uses objects called "stubs" that are bound to the
7173
# channel and provide a basic method for each RPC.
7274
self._stubs = {
@@ -97,6 +99,15 @@ def create_channel(cls,
9799
scopes=cls._OAUTH_SCOPES,
98100
)
99101

102+
@property
103+
def channel(self):
104+
"""The gRPC channel used by the transport.
105+
106+
Returns:
107+
grpc.Channel: A gRPC channel object.
108+
"""
109+
return self._channel
110+
100111
@property
101112
def delete_posix_account(self):
102113
"""Return the gRPC stub for {$apiMethod.name}.

oslogin/synth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
artman_output_name='os-login-v1')
3030

3131
s.move(library / 'google/cloud/oslogin_v1')
32+
s.move(library / 'tests/unit/gapic/v1')
3233

3334
# Fix up imports
3435
s.replace(

oslogin/tests/unit/gapic/v1/test_os_login_service_client_v1.py

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
#
13
# Copyright 2018 Google LLC
24
#
35
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +15,7 @@
1315
# limitations under the License.
1416
"""Unit tests."""
1517

18+
import mock
1619
import pytest
1720

1821
from google.cloud import oslogin_v1
@@ -63,7 +66,10 @@ class CustomException(Exception):
6366
class TestOsLoginServiceClient(object):
6467
def test_delete_posix_account(self):
6568
channel = ChannelStub()
66-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
69+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
70+
with patch as create_channel:
71+
create_channel.return_value = channel
72+
client = oslogin_v1.OsLoginServiceClient()
6773

6874
# Setup Request
6975
name = client.project_path('[USER]', '[PROJECT]')
@@ -78,7 +84,10 @@ def test_delete_posix_account(self):
7884
def test_delete_posix_account_exception(self):
7985
# Mock the API response
8086
channel = ChannelStub(responses=[CustomException()])
81-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
87+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
88+
with patch as create_channel:
89+
create_channel.return_value = channel
90+
client = oslogin_v1.OsLoginServiceClient()
8291

8392
# Setup request
8493
name = client.project_path('[USER]', '[PROJECT]')
@@ -88,7 +97,10 @@ def test_delete_posix_account_exception(self):
8897

8998
def test_delete_ssh_public_key(self):
9099
channel = ChannelStub()
91-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
100+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
101+
with patch as create_channel:
102+
create_channel.return_value = channel
103+
client = oslogin_v1.OsLoginServiceClient()
92104

93105
# Setup Request
94106
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
@@ -103,7 +115,10 @@ def test_delete_ssh_public_key(self):
103115
def test_delete_ssh_public_key_exception(self):
104116
# Mock the API response
105117
channel = ChannelStub(responses=[CustomException()])
106-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
118+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
119+
with patch as create_channel:
120+
create_channel.return_value = channel
121+
client = oslogin_v1.OsLoginServiceClient()
107122

108123
# Setup request
109124
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
@@ -120,7 +135,10 @@ def test_get_login_profile(self):
120135

121136
# Mock the API response
122137
channel = ChannelStub(responses=[expected_response])
123-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
138+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
139+
with patch as create_channel:
140+
create_channel.return_value = channel
141+
client = oslogin_v1.OsLoginServiceClient()
124142

125143
# Setup Request
126144
name = client.user_path('[USER]')
@@ -136,7 +154,10 @@ def test_get_login_profile(self):
136154
def test_get_login_profile_exception(self):
137155
# Mock the API response
138156
channel = ChannelStub(responses=[CustomException()])
139-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
157+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
158+
with patch as create_channel:
159+
create_channel.return_value = channel
160+
client = oslogin_v1.OsLoginServiceClient()
140161

141162
# Setup request
142163
name = client.user_path('[USER]')
@@ -158,7 +179,10 @@ def test_get_ssh_public_key(self):
158179

159180
# Mock the API response
160181
channel = ChannelStub(responses=[expected_response])
161-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
182+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
183+
with patch as create_channel:
184+
create_channel.return_value = channel
185+
client = oslogin_v1.OsLoginServiceClient()
162186

163187
# Setup Request
164188
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
@@ -174,7 +198,10 @@ def test_get_ssh_public_key(self):
174198
def test_get_ssh_public_key_exception(self):
175199
# Mock the API response
176200
channel = ChannelStub(responses=[CustomException()])
177-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
201+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
202+
with patch as create_channel:
203+
create_channel.return_value = channel
204+
client = oslogin_v1.OsLoginServiceClient()
178205

179206
# Setup request
180207
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
@@ -190,7 +217,10 @@ def test_import_ssh_public_key(self):
190217

191218
# Mock the API response
192219
channel = ChannelStub(responses=[expected_response])
193-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
220+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
221+
with patch as create_channel:
222+
create_channel.return_value = channel
223+
client = oslogin_v1.OsLoginServiceClient()
194224

195225
# Setup Request
196226
parent = client.user_path('[USER]')
@@ -208,7 +238,10 @@ def test_import_ssh_public_key(self):
208238
def test_import_ssh_public_key_exception(self):
209239
# Mock the API response
210240
channel = ChannelStub(responses=[CustomException()])
211-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
241+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
242+
with patch as create_channel:
243+
create_channel.return_value = channel
244+
client = oslogin_v1.OsLoginServiceClient()
212245

213246
# Setup request
214247
parent = client.user_path('[USER]')
@@ -231,7 +264,10 @@ def test_update_ssh_public_key(self):
231264

232265
# Mock the API response
233266
channel = ChannelStub(responses=[expected_response])
234-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
267+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
268+
with patch as create_channel:
269+
create_channel.return_value = channel
270+
client = oslogin_v1.OsLoginServiceClient()
235271

236272
# Setup Request
237273
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
@@ -249,7 +285,10 @@ def test_update_ssh_public_key(self):
249285
def test_update_ssh_public_key_exception(self):
250286
# Mock the API response
251287
channel = ChannelStub(responses=[CustomException()])
252-
client = oslogin_v1.OsLoginServiceClient(channel=channel)
288+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
289+
with patch as create_channel:
290+
create_channel.return_value = channel
291+
client = oslogin_v1.OsLoginServiceClient()
253292

254293
# Setup request
255294
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')

0 commit comments

Comments
 (0)