1+ # -*- coding: utf-8 -*-
2+ #
13# Copyright 2018 Google LLC
24#
35# Licensed under the Apache License, Version 2.0 (the "License");
1315# limitations under the License.
1416"""Unit tests."""
1517
18+ import mock
1619import pytest
1720
1821from google .cloud import oslogin_v1
@@ -63,7 +66,10 @@ class CustomException(Exception):
6366class 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