Skip to content

Commit

Permalink
Merge branch 'master' into fileio
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyn committed Mar 22, 2021
2 parents 3160173 + 4868be3 commit abceb1b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 8 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,22 @@

[1]: https://pypi.org/project/google-cloud-storage/#history

### [1.36.2](https://www.github.com/googleapis/python-storage/compare/v1.36.1...v1.36.2) (2021-03-09)


### Bug Fixes

* update batch connection to request api endpoint info from client ([#392](https://www.github.com/googleapis/python-storage/issues/392)) ([91fc6d9](https://www.github.com/googleapis/python-storage/commit/91fc6d9870a36308b15a827ed6a691e5b4669b62))

### [1.36.1](https://www.github.com/googleapis/python-storage/compare/v1.36.0...v1.36.1) (2021-02-19)


### Bug Fixes

* allow metadata keys to be cleared ([#383](https://www.github.com/googleapis/python-storage/issues/383)) ([79d27da](https://www.github.com/googleapis/python-storage/commit/79d27da9fe842e44a9091076ea0ef52c5ef5ff72)), closes [#381](https://www.github.com/googleapis/python-storage/issues/381)
* allow signed url version v4 without signed credentials ([#356](https://www.github.com/googleapis/python-storage/issues/356)) ([3e69bf9](https://www.github.com/googleapis/python-storage/commit/3e69bf92496616c5de28094dd42260b35c3bf982))
* correctly encode bytes for V2 signature ([#382](https://www.github.com/googleapis/python-storage/issues/382)) ([f44212b](https://www.github.com/googleapis/python-storage/commit/f44212b7b91a67ca661898400fe632f9fb3ec8f6))

## [1.36.0](https://www.github.com/googleapis/python-storage/compare/v1.35.1...v1.36.0) (2021-02-10)


Expand Down
6 changes: 5 additions & 1 deletion google/cloud/storage/batch.py
Expand Up @@ -147,7 +147,11 @@ class Batch(Connection):
_MAX_BATCH_SIZE = 1000

def __init__(self, client):
super(Batch, self).__init__(client)
api_endpoint = client._connection.API_BASE_URL
client_info = client._connection._client_info
super(Batch, self).__init__(
client, client_info=client_info, api_endpoint=api_endpoint
)
self._requests = []
self._target_objects = []

Expand Down
2 changes: 1 addition & 1 deletion google/cloud/storage/version.py
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.36.0"
__version__ = "1.36.2"
40 changes: 34 additions & 6 deletions tests/unit/test_batch.py
Expand Up @@ -136,7 +136,8 @@ def test__make_request_GET_normal(self):
url = "http://example.com/api"
http = _make_requests_session([])
connection = _Connection(http=http)
batch = self._make_one(connection)
client = _Client(connection)
batch = self._make_one(client)
target = _MockObject()

response = batch._make_request("GET", url, target_object=target)
Expand Down Expand Up @@ -164,7 +165,8 @@ def test__make_request_POST_normal(self):
url = "http://example.com/api"
http = _make_requests_session([])
connection = _Connection(http=http)
batch = self._make_one(connection)
client = _Client(connection)
batch = self._make_one(client)
data = {"foo": 1}
target = _MockObject()

Expand All @@ -191,7 +193,8 @@ def test__make_request_PATCH_normal(self):
url = "http://example.com/api"
http = _make_requests_session([])
connection = _Connection(http=http)
batch = self._make_one(connection)
client = _Client(connection)
batch = self._make_one(client)
data = {"foo": 1}
target = _MockObject()

Expand All @@ -218,7 +221,8 @@ def test__make_request_DELETE_normal(self):
url = "http://example.com/api"
http = _make_requests_session([])
connection = _Connection(http=http)
batch = self._make_one(connection)
client = _Client(connection)
batch = self._make_one(client)
target = _MockObject()

response = batch._make_request("DELETE", url, target_object=target)
Expand All @@ -243,7 +247,8 @@ def test__make_request_POST_too_many_requests(self):
url = "http://example.com/api"
http = _make_requests_session([])
connection = _Connection(http=http)
batch = self._make_one(connection)
client = _Client(connection)
batch = self._make_one(client)

batch._MAX_BATCH_SIZE = 1
batch._requests.append(("POST", url, {}, {"bar": 2}))
Expand All @@ -254,7 +259,8 @@ def test__make_request_POST_too_many_requests(self):
def test_finish_empty(self):
http = _make_requests_session([])
connection = _Connection(http=http)
batch = self._make_one(connection)
client = _Client(connection)
batch = self._make_one(client)

with self.assertRaises(ValueError):
batch.finish()
Expand Down Expand Up @@ -518,6 +524,25 @@ def test_as_context_mgr_w_error(self):
self.assertIsInstance(target2._properties, _FutureDict)
self.assertIsInstance(target3._properties, _FutureDict)

def test_respect_client_existing_connection(self):
client_endpoint = "http://localhost:9023"
http = _make_requests_session([])
connection = _Connection(http=http, api_endpoint=client_endpoint)
client = _Client(connection)
batch = self._make_one(client)
self.assertEqual(batch.API_BASE_URL, client_endpoint)
self.assertEqual(batch._client._connection.API_BASE_URL, client_endpoint)

def test_use_default_api_without_existing_connection(self):
default_api_endpoint = "https://storage.googleapis.com"
http = _make_requests_session([])
connection = _Connection(http=http)
client = _Client(connection)
batch = self._make_one(client)
self.assertEqual(batch.API_BASE_URL, default_api_endpoint)
self.assertIsNone(batch._client._connection.API_BASE_URL)
self.assertIsNone(batch._client._connection._client_info)


class Test__unpack_batch_response(unittest.TestCase):
def _call_fut(self, headers, content):
Expand Down Expand Up @@ -633,6 +658,8 @@ class _Connection(object):

def __init__(self, **kw):
self.__dict__.update(kw)
self._client_info = kw.get("client_info", None)
self.API_BASE_URL = kw.get("api_endpoint", None)

def _make_request(self, method, url, data=None, headers=None, timeout=None):
return self.http.request(
Expand All @@ -647,3 +674,4 @@ class _MockObject(object):
class _Client(object):
def __init__(self, connection):
self._base_connection = connection
self._connection = connection

0 comments on commit abceb1b

Please sign in to comment.