Skip to content

Commit

Permalink
Pick up fixes to GAPIC generator. (googleapis#6575)
Browse files Browse the repository at this point in the history
Includes fixes from these PRs:

- googleapis/gapic-generator#2407 (closing googleapis/gapic-generator#2389)
- googleapis/gapic-generator#2396 (for googleapis#5523 and dupes).

Includes changes to generated tests.

Closes googleapis#6502.
  • Loading branch information
tseaver authored Nov 19, 2018
1 parent f0da536 commit 4523af4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
17 changes: 12 additions & 5 deletions oslogin/google/cloud/oslogin_v1/gapic/os_login_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=os_login_service_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -137,13 +137,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 = os_login_service_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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,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 = {
Expand Down Expand Up @@ -97,6 +99,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 delete_posix_account(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
1 change: 1 addition & 0 deletions oslogin/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
artman_output_name='os-login-v1')

s.move(library / 'google/cloud/oslogin_v1')
s.move(library / 'tests/unit/gapic/v1')

# Fix up imports
s.replace(
Expand Down
63 changes: 51 additions & 12 deletions oslogin/tests/unit/gapic/v1/test_os_login_service_client_v1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -13,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.cloud import oslogin_v1
Expand Down Expand Up @@ -63,7 +66,10 @@ class CustomException(Exception):
class TestOsLoginServiceClient(object):
def test_delete_posix_account(self):
channel = ChannelStub()
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

# Setup Request
name = client.project_path('[USER]', '[PROJECT]')
Expand All @@ -78,7 +84,10 @@ def test_delete_posix_account(self):
def test_delete_posix_account_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

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

def test_delete_ssh_public_key(self):
channel = ChannelStub()
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

# Setup Request
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
Expand All @@ -103,7 +115,10 @@ def test_delete_ssh_public_key(self):
def test_delete_ssh_public_key_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

# Setup Request
name = client.user_path('[USER]')
Expand All @@ -136,7 +154,10 @@ def test_get_login_profile(self):
def test_get_login_profile_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

# Setup Request
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
Expand All @@ -174,7 +198,10 @@ def test_get_ssh_public_key(self):
def test_get_ssh_public_key_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

# Setup Request
parent = client.user_path('[USER]')
Expand All @@ -208,7 +238,10 @@ def test_import_ssh_public_key(self):
def test_import_ssh_public_key_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

# Setup Request
name = client.fingerprint_path('[USER]', '[FINGERPRINT]')
Expand All @@ -249,7 +285,10 @@ def test_update_ssh_public_key(self):
def test_update_ssh_public_key_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = oslogin_v1.OsLoginServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = oslogin_v1.OsLoginServiceClient()

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

0 comments on commit 4523af4

Please sign in to comment.