@@ -1818,6 +1818,7 @@ def _mock_transport(self, status_code, headers, content=b""):
1818
1818
def _do_multipart_success (
1819
1819
self ,
1820
1820
mock_get_boundary ,
1821
+ client = None ,
1821
1822
size = None ,
1822
1823
num_retries = None ,
1823
1824
user_project = None ,
@@ -1840,12 +1841,13 @@ def _do_multipart_success(
1840
1841
blob ._properties ["metadata" ] = metadata
1841
1842
self .assertEqual (len (blob ._changes ), 0 )
1842
1843
1843
- # Create mocks to be checked for doing transport.
1844
- transport = self ._mock_transport (http_client .OK , {})
1845
-
1846
1844
# Create some mock arguments.
1847
- client = mock .Mock (_http = transport , _connection = _Connection , spec = ["_http" ])
1848
- client ._connection .API_BASE_URL = "https://storage.googleapis.com"
1845
+ if not client :
1846
+ # Create mocks to be checked for doing transport.
1847
+ transport = self ._mock_transport (http_client .OK , {})
1848
+
1849
+ client = mock .Mock (_http = transport , _connection = _Connection , spec = ["_http" ])
1850
+ client ._connection .API_BASE_URL = "https://storage.googleapis.com"
1849
1851
data = b"data here hear hier"
1850
1852
stream = io .BytesIO (data )
1851
1853
content_type = u"application/xml"
@@ -1872,7 +1874,7 @@ def _do_multipart_success(
1872
1874
)
1873
1875
1874
1876
# Check the mocks and the returned value.
1875
- self .assertIs (response , transport .request .return_value )
1877
+ self .assertIs (response , client . _http .request .return_value )
1876
1878
if size is None :
1877
1879
data_read = data
1878
1880
self .assertEqual (stream .tell (), len (data ))
@@ -1929,7 +1931,7 @@ def _do_multipart_success(
1929
1931
+ b"\r \n --==0==--"
1930
1932
)
1931
1933
headers = {"content-type" : b'multipart/related; boundary="==0=="' }
1932
- transport .request .assert_called_once_with (
1934
+ client . _http .request .assert_called_once_with (
1933
1935
"POST" , upload_url , data = payload , headers = headers , timeout = expected_timeout
1934
1936
)
1935
1937
@@ -1987,6 +1989,13 @@ def test__do_multipart_upload_with_generation_not_match(self, mock_get_boundary)
1987
1989
mock_get_boundary , if_generation_not_match = 4 , if_metageneration_not_match = 4
1988
1990
)
1989
1991
1992
+ @mock .patch (u"google.resumable_media._upload.get_boundary" , return_value = b"==0==" )
1993
+ def test__do_multipart_upload_with_client (self , mock_get_boundary ):
1994
+ transport = self ._mock_transport (http_client .OK , {})
1995
+ client = mock .Mock (_http = transport , _connection = _Connection , spec = ["_http" ])
1996
+ client ._connection .API_BASE_URL = "https://storage.googleapis.com"
1997
+ self ._do_multipart_success (mock_get_boundary , client = client )
1998
+
1990
1999
@mock .patch (u"google.resumable_media._upload.get_boundary" , return_value = b"==0==" )
1991
2000
def test__do_multipart_upload_with_metadata (self , mock_get_boundary ):
1992
2001
self ._do_multipart_success (mock_get_boundary , metadata = {"test" : "test" })
@@ -2010,6 +2019,7 @@ def test__do_multipart_upload_bad_size(self):
2010
2019
2011
2020
def _initiate_resumable_helper (
2012
2021
self ,
2022
+ client = None ,
2013
2023
size = None ,
2014
2024
extra_headers = None ,
2015
2025
chunk_size = None ,
@@ -2051,14 +2061,17 @@ def _initiate_resumable_helper(
2051
2061
return_value = object_metadata , spec = []
2052
2062
)
2053
2063
2054
- # Create mocks to be checked for doing transport.
2055
2064
resumable_url = "http://test.invalid?upload_id=hey-you"
2056
- response_headers = {"location" : resumable_url }
2057
- transport = self ._mock_transport (http_client .OK , response_headers )
2058
-
2059
- # Create some mock arguments and call the method under test.
2060
- client = mock .Mock (_http = transport , _connection = _Connection , spec = [u"_http" ])
2061
- client ._connection .API_BASE_URL = "https://storage.googleapis.com"
2065
+ if not client :
2066
+ # Create mocks to be checked for doing transport.
2067
+ response_headers = {"location" : resumable_url }
2068
+ transport = self ._mock_transport (http_client .OK , response_headers )
2069
+
2070
+ # Create some mock arguments and call the method under test.
2071
+ client = mock .Mock (
2072
+ _http = transport , _connection = _Connection , spec = [u"_http" ]
2073
+ )
2074
+ client ._connection .API_BASE_URL = "https://storage.googleapis.com"
2062
2075
data = b"hello hallo halo hi-low"
2063
2076
stream = io .BytesIO (data )
2064
2077
content_type = u"text/plain"
@@ -2149,7 +2162,7 @@ def _initiate_resumable_helper(
2149
2162
else :
2150
2163
self .assertIsNone (retry_strategy .max_cumulative_retry )
2151
2164
self .assertEqual (retry_strategy .max_retries , num_retries )
2152
- self .assertIs (transport , transport )
2165
+ self .assertIs (client . _http , transport )
2153
2166
# Make sure we never read from the stream.
2154
2167
self .assertEqual (stream .tell (), 0 )
2155
2168
@@ -2237,6 +2250,15 @@ def test__initiate_resumable_upload_with_generation_not_match(self):
2237
2250
def test__initiate_resumable_upload_with_predefined_acl (self ):
2238
2251
self ._initiate_resumable_helper (predefined_acl = "private" )
2239
2252
2253
+ def test__initiate_resumable_upload_with_client (self ):
2254
+ resumable_url = "http://test.invalid?upload_id=hey-you"
2255
+ response_headers = {"location" : resumable_url }
2256
+ transport = self ._mock_transport (http_client .OK , response_headers )
2257
+
2258
+ client = mock .Mock (_http = transport , _connection = _Connection , spec = [u"_http" ])
2259
+ client ._connection .API_BASE_URL = "https://storage.googleapis.com"
2260
+ self ._initiate_resumable_helper (client = client )
2261
+
2240
2262
def _make_resumable_transport (
2241
2263
self , headers1 , headers2 , headers3 , total_bytes , data_corruption = False
2242
2264
):
0 commit comments