-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage: Blob.exists() does not work within Batch context #8618
Changes from 1 commit
522ff0b
42ca944
10fbf74
8d43ebc
f1f01a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,45 @@ | |
import os | ||
import tempfile | ||
import unittest | ||
import requests | ||
|
||
import google.cloud.storage.blob | ||
import mock | ||
import six | ||
from six.moves import http_client | ||
|
||
|
||
def _make_response(status_code=http_client.OK, content=b"", headers={}): | ||
response = requests.Response() | ||
response.status_code = status_code | ||
response._content = content | ||
response.headers = headers | ||
response.request = requests.Request() | ||
return response | ||
|
||
|
||
def _make_connection(): | ||
from google.cloud.storage._http import Connection | ||
|
||
mock_conn = mock.create_autospec(Connection) | ||
mock_conn.user_agent = "testing 1.2.3" | ||
mock_conn._make_request.return_value = _make_response( | ||
status_code=200, | ||
headers={ | ||
"content-type": "multipart/mixed; boundary=batch_pK7JBAk73-E=_AA5eFwv4m2Q=", | ||
}, | ||
content=b""" | ||
--batch_pK7JBAk73-E=_AA5eFwv4m2Q= | ||
HTTP/1.1 404 NotFound | ||
|
||
--batch_pK7JBAk73-E=_AA5eFwv4m2Q= | ||
HTTP/1.1 200 OK | ||
|
||
--batch_pK7JBAk73-E=_AA5eFwv4m2Q=--""" | ||
) | ||
return mock_conn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are two different responses for two different |
||
|
||
|
||
def _make_credentials(): | ||
import google.auth.credentials | ||
|
||
|
@@ -582,6 +614,27 @@ def test_exists_miss(self): | |
}, | ||
) | ||
|
||
def test_exists_miss_within_batch(self): | ||
from google.cloud.storage.client import Client | ||
from google.cloud.exceptions import NotFound | ||
|
||
client = Client(credentials=_make_credentials()) | ||
client._base_connection = _make_connection() | ||
|
||
bucket = _Bucket(client) | ||
blob1 = self._make_one("nonesuch1", bucket=bucket) | ||
blob2 = self._make_one("nonesuch2", bucket=bucket) | ||
|
||
try: | ||
with client.batch(): | ||
bool1 = blob1.exists() | ||
bool2 = blob2.exists() | ||
except NotFound: | ||
pass | ||
|
||
self.assertFalse(bool1) | ||
self.assertTrue(bool2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking if both |
||
|
||
def test_exists_hit_w_user_project(self): | ||
BLOB_NAME = "blob-name" | ||
USER_PROJECT = "user-project-123" | ||
|
@@ -3311,6 +3364,7 @@ def delete_blob(self, blob_name, client=None, generation=None): | |
class _Client(object): | ||
def __init__(self, connection): | ||
self._base_connection = connection | ||
self.current_batch = None | ||
|
||
@property | ||
def _connection(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If exception have been raised, or request is not done yet, there will be
_FutureDict
obj