@@ -136,7 +136,8 @@ def test__make_request_GET_normal(self):
136
136
url = "http://example.com/api"
137
137
http = _make_requests_session ([])
138
138
connection = _Connection (http = http )
139
- batch = self ._make_one (connection )
139
+ client = _Client (connection )
140
+ batch = self ._make_one (client )
140
141
target = _MockObject ()
141
142
142
143
response = batch ._make_request ("GET" , url , target_object = target )
@@ -164,7 +165,8 @@ def test__make_request_POST_normal(self):
164
165
url = "http://example.com/api"
165
166
http = _make_requests_session ([])
166
167
connection = _Connection (http = http )
167
- batch = self ._make_one (connection )
168
+ client = _Client (connection )
169
+ batch = self ._make_one (client )
168
170
data = {"foo" : 1 }
169
171
target = _MockObject ()
170
172
@@ -191,7 +193,8 @@ def test__make_request_PATCH_normal(self):
191
193
url = "http://example.com/api"
192
194
http = _make_requests_session ([])
193
195
connection = _Connection (http = http )
194
- batch = self ._make_one (connection )
196
+ client = _Client (connection )
197
+ batch = self ._make_one (client )
195
198
data = {"foo" : 1 }
196
199
target = _MockObject ()
197
200
@@ -218,7 +221,8 @@ def test__make_request_DELETE_normal(self):
218
221
url = "http://example.com/api"
219
222
http = _make_requests_session ([])
220
223
connection = _Connection (http = http )
221
- batch = self ._make_one (connection )
224
+ client = _Client (connection )
225
+ batch = self ._make_one (client )
222
226
target = _MockObject ()
223
227
224
228
response = batch ._make_request ("DELETE" , url , target_object = target )
@@ -243,7 +247,8 @@ def test__make_request_POST_too_many_requests(self):
243
247
url = "http://example.com/api"
244
248
http = _make_requests_session ([])
245
249
connection = _Connection (http = http )
246
- batch = self ._make_one (connection )
250
+ client = _Client (connection )
251
+ batch = self ._make_one (client )
247
252
248
253
batch ._MAX_BATCH_SIZE = 1
249
254
batch ._requests .append (("POST" , url , {}, {"bar" : 2 }))
@@ -254,7 +259,8 @@ def test__make_request_POST_too_many_requests(self):
254
259
def test_finish_empty (self ):
255
260
http = _make_requests_session ([])
256
261
connection = _Connection (http = http )
257
- batch = self ._make_one (connection )
262
+ client = _Client (connection )
263
+ batch = self ._make_one (client )
258
264
259
265
with self .assertRaises (ValueError ):
260
266
batch .finish ()
@@ -518,6 +524,25 @@ def test_as_context_mgr_w_error(self):
518
524
self .assertIsInstance (target2 ._properties , _FutureDict )
519
525
self .assertIsInstance (target3 ._properties , _FutureDict )
520
526
527
+ def test_respect_client_existing_connection (self ):
528
+ client_endpoint = "http://localhost:9023"
529
+ http = _make_requests_session ([])
530
+ connection = _Connection (http = http , api_endpoint = client_endpoint )
531
+ client = _Client (connection )
532
+ batch = self ._make_one (client )
533
+ self .assertEqual (batch .API_BASE_URL , client_endpoint )
534
+ self .assertEqual (batch ._client ._connection .API_BASE_URL , client_endpoint )
535
+
536
+ def test_use_default_api_without_existing_connection (self ):
537
+ default_api_endpoint = "https://storage.googleapis.com"
538
+ http = _make_requests_session ([])
539
+ connection = _Connection (http = http )
540
+ client = _Client (connection )
541
+ batch = self ._make_one (client )
542
+ self .assertEqual (batch .API_BASE_URL , default_api_endpoint )
543
+ self .assertIsNone (batch ._client ._connection .API_BASE_URL )
544
+ self .assertIsNone (batch ._client ._connection ._client_info )
545
+
521
546
522
547
class Test__unpack_batch_response (unittest .TestCase ):
523
548
def _call_fut (self , headers , content ):
@@ -633,6 +658,8 @@ class _Connection(object):
633
658
634
659
def __init__ (self , ** kw ):
635
660
self .__dict__ .update (kw )
661
+ self ._client_info = kw .get ("client_info" , None )
662
+ self .API_BASE_URL = kw .get ("api_endpoint" , None )
636
663
637
664
def _make_request (self , method , url , data = None , headers = None , timeout = None ):
638
665
return self .http .request (
@@ -647,3 +674,4 @@ class _MockObject(object):
647
674
class _Client (object ):
648
675
def __init__ (self , connection ):
649
676
self ._base_connection = connection
677
+ self ._connection = connection
0 commit comments