@@ -125,6 +125,23 @@ def test_ctor_explicit(self):
125125 self .assertFalse (bucket ._default_object_acl .loaded )
126126 self .assertTrue (bucket ._default_object_acl .bucket is bucket )
127127
128+ def test__client_or_connection_implicit (self ):
129+ from gcloud ._testing import _Monkey
130+ from gcloud .storage import bucket as MUT
131+ bucket = self ._makeOne ()
132+ num_mock_require_calls = [0 ]
133+ cnxn = object ()
134+
135+ def mock_require ():
136+ num_mock_require_calls [0 ] += 1
137+ return cnxn
138+
139+ with _Monkey (MUT , _require_connection = mock_require ):
140+ result = bucket ._client_or_connection (None )
141+
142+ self .assertTrue (result is cnxn )
143+ self .assertEqual (num_mock_require_calls , [1 ])
144+
128145 def test_exists_miss (self ):
129146 from gcloud .exceptions import NotFound
130147
@@ -139,7 +156,8 @@ def api_request(cls, *args, **kwargs):
139156
140157 BUCKET_NAME = 'bucket-name'
141158 bucket = self ._makeOne (BUCKET_NAME )
142- self .assertFalse (bucket .exists (connection = _FakeConnection ))
159+ client = _Client (_FakeConnection )
160+ self .assertFalse (bucket .exists (client = client ))
143161 expected_called_kwargs = {
144162 'method' : 'GET' ,
145163 'path' : bucket .path ,
@@ -164,7 +182,8 @@ def api_request(cls, *args, **kwargs):
164182
165183 BUCKET_NAME = 'bucket-name'
166184 bucket = self ._makeOne (BUCKET_NAME )
167- self .assertTrue (bucket .exists (connection = _FakeConnection ))
185+ client = _Client (_FakeConnection )
186+ self .assertTrue (bucket .exists (client = client ))
168187 expected_called_kwargs = {
169188 'method' : 'GET' ,
170189 'path' : bucket .path ,
@@ -1049,3 +1068,9 @@ class MockFile(io.StringIO):
10491068 def __init__ (self , name , buffer_ = None ):
10501069 super (MockFile , self ).__init__ (buffer_ )
10511070 self .name = name
1071+
1072+
1073+ class _Client (object ):
1074+
1075+ def __init__ (self , connection ):
1076+ self .connection = connection
0 commit comments