2828from google .auth .credentials import AnonymousCredentials
2929from google .oauth2 .service_account import Credentials
3030
31- from google .cloud .storage import _helpers
3231from google .cloud .storage ._helpers import STORAGE_EMULATOR_ENV_VAR
3332from google .cloud .storage ._helpers import _get_default_headers
34- from google .cloud .storage . _http import Connection
33+ from google .cloud .storage import _helpers
3534from google .cloud .storage .retry import DEFAULT_RETRY
3635from google .cloud .storage .retry import DEFAULT_RETRY_IF_GENERATION_SPECIFIED
3736from tests .unit .test__helpers import GCCL_INVOCATION_TEST_CONST
@@ -120,6 +119,7 @@ def _make_one(self, *args, **kw):
120119
121120 def test_ctor_connection_type (self ):
122121 from google .cloud ._http import ClientInfo
122+ from google .cloud .storage ._http import Connection
123123
124124 PROJECT = "PROJECT"
125125 credentials = _make_credentials ()
@@ -179,6 +179,8 @@ def test_ctor_w_client_options_object(self):
179179 )
180180
181181 def test_ctor_wo_project (self ):
182+ from google .cloud .storage ._http import Connection
183+
182184 PROJECT = "PROJECT"
183185 credentials = _make_credentials (project = PROJECT )
184186
@@ -191,6 +193,8 @@ def test_ctor_wo_project(self):
191193 self .assertEqual (list (client ._batch_stack ), [])
192194
193195 def test_ctor_w_project_explicit_none (self ):
196+ from google .cloud .storage ._http import Connection
197+
194198 credentials = _make_credentials ()
195199
196200 client = self ._make_one (project = None , credentials = credentials )
@@ -203,6 +207,7 @@ def test_ctor_w_project_explicit_none(self):
203207
204208 def test_ctor_w_client_info (self ):
205209 from google .cloud ._http import ClientInfo
210+ from google .cloud .storage ._http import Connection
206211
207212 credentials = _make_credentials ()
208213 client_info = ClientInfo ()
@@ -234,40 +239,8 @@ def test_ctor_mtls(self):
234239 self .assertEqual (client ._connection .ALLOW_AUTO_SWITCH_TO_MTLS_URL , False )
235240 self .assertEqual (client ._connection .API_BASE_URL , "http://foo" )
236241
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-
269242 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
271244 host = "http://localhost:8080"
272245 environ = {STORAGE_EMULATOR_ENV_VAR : host }
273246 with mock .patch ("os.environ" , environ ):
@@ -277,8 +250,16 @@ def test_ctor_w_emulator_wo_project(self):
277250 self .assertEqual (client ._connection .API_BASE_URL , host )
278251 self .assertIsInstance (client ._connection .credentials , AnonymousCredentials )
279252
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+
280261 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
282263 host = "http://localhost:8080"
283264 environ_project = "environ-project"
284265 environ = {
@@ -308,17 +289,9 @@ def test_ctor_w_emulator_w_project_arg(self):
308289 self .assertEqual (client ._connection .API_BASE_URL , host )
309290 self .assertIsInstance (client ._connection .credentials , AnonymousCredentials )
310291
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-
321292 def test_create_anonymous_client (self ):
293+ from google .cloud .storage ._http import Connection
294+
322295 klass = self ._get_target_class ()
323296 client = klass .create_anonymous_client ()
324297
0 commit comments