28
28
from google .auth .credentials import AnonymousCredentials
29
29
from google .oauth2 .service_account import Credentials
30
30
31
- from google .cloud .storage import _helpers
32
31
from google .cloud .storage ._helpers import STORAGE_EMULATOR_ENV_VAR
33
32
from google .cloud .storage ._helpers import _get_default_headers
34
- from google .cloud .storage . _http import Connection
33
+ from google .cloud .storage import _helpers
35
34
from google .cloud .storage .retry import DEFAULT_RETRY
36
35
from google .cloud .storage .retry import DEFAULT_RETRY_IF_GENERATION_SPECIFIED
37
36
from tests .unit .test__helpers import GCCL_INVOCATION_TEST_CONST
@@ -120,6 +119,7 @@ def _make_one(self, *args, **kw):
120
119
121
120
def test_ctor_connection_type (self ):
122
121
from google .cloud ._http import ClientInfo
122
+ from google .cloud .storage ._http import Connection
123
123
124
124
PROJECT = "PROJECT"
125
125
credentials = _make_credentials ()
@@ -179,6 +179,8 @@ def test_ctor_w_client_options_object(self):
179
179
)
180
180
181
181
def test_ctor_wo_project (self ):
182
+ from google .cloud .storage ._http import Connection
183
+
182
184
PROJECT = "PROJECT"
183
185
credentials = _make_credentials (project = PROJECT )
184
186
@@ -191,6 +193,8 @@ def test_ctor_wo_project(self):
191
193
self .assertEqual (list (client ._batch_stack ), [])
192
194
193
195
def test_ctor_w_project_explicit_none (self ):
196
+ from google .cloud .storage ._http import Connection
197
+
194
198
credentials = _make_credentials ()
195
199
196
200
client = self ._make_one (project = None , credentials = credentials )
@@ -203,6 +207,7 @@ def test_ctor_w_project_explicit_none(self):
203
207
204
208
def test_ctor_w_client_info (self ):
205
209
from google .cloud ._http import ClientInfo
210
+ from google .cloud .storage ._http import Connection
206
211
207
212
credentials = _make_credentials ()
208
213
client_info = ClientInfo ()
@@ -234,40 +239,8 @@ def test_ctor_mtls(self):
234
239
self .assertEqual (client ._connection .ALLOW_AUTO_SWITCH_TO_MTLS_URL , False )
235
240
self .assertEqual (client ._connection .API_BASE_URL , "http://foo" )
236
241
237
- def test_ctor_w_custom_endpoint_use_auth (self ):
238
- custom_endpoint = "storage-example.p.googleapis.com"
239
- client = self ._make_one (client_options = {"api_endpoint" : custom_endpoint })
240
- self .assertEqual (client ._connection .API_BASE_URL , custom_endpoint )
241
- self .assertIsNotNone (client .project )
242
- self .assertIsInstance (client ._connection , Connection )
243
- self .assertIsNotNone (client ._connection .credentials )
244
- self .assertNotIsInstance (client ._connection .credentials , AnonymousCredentials )
245
-
246
- def test_ctor_w_custom_endpoint_bypass_auth (self ):
247
- custom_endpoint = "storage-example.p.googleapis.com"
248
- client = self ._make_one (
249
- client_options = {"api_endpoint" : custom_endpoint },
250
- use_auth_w_custom_endpoint = False ,
251
- )
252
- self .assertEqual (client ._connection .API_BASE_URL , custom_endpoint )
253
- self .assertEqual (client .project , None )
254
- self .assertIsInstance (client ._connection , Connection )
255
- self .assertIsInstance (client ._connection .credentials , AnonymousCredentials )
256
-
257
- def test_ctor_w_custom_endpoint_w_credentials (self ):
258
- PROJECT = "PROJECT"
259
- custom_endpoint = "storage-example.p.googleapis.com"
260
- credentials = _make_credentials (project = PROJECT )
261
- client = self ._make_one (
262
- credentials = credentials , client_options = {"api_endpoint" : custom_endpoint }
263
- )
264
- self .assertEqual (client ._connection .API_BASE_URL , custom_endpoint )
265
- self .assertEqual (client .project , PROJECT )
266
- self .assertIsInstance (client ._connection , Connection )
267
- self .assertIs (client ._connection .credentials , credentials )
268
-
269
242
def test_ctor_w_emulator_wo_project (self ):
270
- # bypasses authentication if STORAGE_EMULATOR_ENV_VAR is set
243
+ # avoids authentication if STORAGE_EMULATOR_ENV_VAR is set
271
244
host = "http://localhost:8080"
272
245
environ = {STORAGE_EMULATOR_ENV_VAR : host }
273
246
with mock .patch ("os.environ" , environ ):
@@ -277,8 +250,16 @@ def test_ctor_w_emulator_wo_project(self):
277
250
self .assertEqual (client ._connection .API_BASE_URL , host )
278
251
self .assertIsInstance (client ._connection .credentials , AnonymousCredentials )
279
252
253
+ # avoids authentication if storage emulator is set through api_endpoint
254
+ client = self ._make_one (
255
+ client_options = {"api_endpoint" : "http://localhost:8080" }
256
+ )
257
+ self .assertIsNone (client .project )
258
+ self .assertEqual (client ._connection .API_BASE_URL , host )
259
+ self .assertIsInstance (client ._connection .credentials , AnonymousCredentials )
260
+
280
261
def test_ctor_w_emulator_w_environ_project (self ):
281
- # bypasses authentication and infers the project from the environment
262
+ # avoids authentication and infers the project from the environment
282
263
host = "http://localhost:8080"
283
264
environ_project = "environ-project"
284
265
environ = {
@@ -308,17 +289,9 @@ def test_ctor_w_emulator_w_project_arg(self):
308
289
self .assertEqual (client ._connection .API_BASE_URL , host )
309
290
self .assertIsInstance (client ._connection .credentials , AnonymousCredentials )
310
291
311
- def test_ctor_w_emulator_w_credentials (self ):
312
- host = "http://localhost:8080"
313
- environ = {STORAGE_EMULATOR_ENV_VAR : host }
314
- credentials = _make_credentials ()
315
- with mock .patch ("os.environ" , environ ):
316
- client = self ._make_one (credentials = credentials )
317
-
318
- self .assertEqual (client ._connection .API_BASE_URL , host )
319
- self .assertIs (client ._connection .credentials , credentials )
320
-
321
292
def test_create_anonymous_client (self ):
293
+ from google .cloud .storage ._http import Connection
294
+
322
295
klass = self ._get_target_class ()
323
296
client = klass .create_anonymous_client ()
324
297
0 commit comments