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
refactor(storage): deprecate Bucket.create() and requester_pays #9893
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6873209
refactor(storage): deprecate Bucket.create() and requester_pays.
fe3642d
refactor(storage): deprecate Bucket.create() and requester_pays
cab1017
Merge branch 'deprecate_create_bucket' of https://github.com/q-logic/…
e44fad4
Fix requester_pays assertion.
e26c745
Add checks for deprecation warnings.
d28d1ec
Add more checks.
8f401f9
Fix coverage problem.
53e542e
Lint fix.
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,217 +607,6 @@ def api_request(cls, *args, **kwargs): | |
expected_cw = [((), expected_called_kwargs)] | ||
self.assertEqual(_FakeConnection._called_with, expected_cw) | ||
|
||
def test_create_w_user_project(self): | ||
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. Most part of these tests had already been moved into |
||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
USER_PROJECT = "user-project-123" | ||
|
||
client = Client(project=PROJECT) | ||
client._base_connection = _Connection() | ||
|
||
bucket = self._make_one(client, BUCKET_NAME, user_project=USER_PROJECT) | ||
|
||
with self.assertRaises(ValueError): | ||
bucket.create() | ||
|
||
def test_create_w_missing_client_project(self): | ||
from google.cloud.storage.client import Client | ||
|
||
BUCKET_NAME = "bucket-name" | ||
|
||
client = Client(project=None) | ||
bucket = self._make_one(client, BUCKET_NAME) | ||
|
||
with self.assertRaises(ValueError): | ||
bucket.create() | ||
|
||
def test_create_w_explicit_project(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
OTHER_PROJECT = "other-project-123" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _make_connection(DATA) | ||
|
||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
|
||
bucket = self._make_one(client, BUCKET_NAME) | ||
bucket.create(project=OTHER_PROJECT) | ||
connection.api_request.assert_called_once_with( | ||
method="POST", | ||
path="/b", | ||
query_params={"project": OTHER_PROJECT}, | ||
data=DATA, | ||
_target_object=bucket, | ||
) | ||
|
||
def test_create_w_explicit_location(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
LOCATION = "us-central1" | ||
DATA = {"location": LOCATION, "name": BUCKET_NAME} | ||
|
||
connection = _make_connection( | ||
DATA, "{'location': 'us-central1', 'name': 'bucket-name'}" | ||
) | ||
|
||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
|
||
bucket = self._make_one(client, BUCKET_NAME) | ||
bucket.create(location=LOCATION) | ||
|
||
connection.api_request.assert_called_once_with( | ||
method="POST", | ||
path="/b", | ||
data=DATA, | ||
_target_object=bucket, | ||
query_params={"project": "PROJECT"}, | ||
) | ||
self.assertEqual(bucket.location, LOCATION) | ||
|
||
def test_create_hit(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _make_connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
|
||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
bucket.create() | ||
|
||
connection.api_request.assert_called_once_with( | ||
method="POST", | ||
path="/b", | ||
query_params={"project": PROJECT}, | ||
data=DATA, | ||
_target_object=bucket, | ||
) | ||
|
||
def test_create_w_extra_properties(self): | ||
from google.cloud.storage.client import Client | ||
|
||
BUCKET_NAME = "bucket-name" | ||
PROJECT = "PROJECT" | ||
CORS = [ | ||
{ | ||
"maxAgeSeconds": 60, | ||
"methods": ["*"], | ||
"origin": ["https://example.com/frontend"], | ||
"responseHeader": ["X-Custom-Header"], | ||
} | ||
] | ||
LIFECYCLE_RULES = [{"action": {"type": "Delete"}, "condition": {"age": 365}}] | ||
LOCATION = "eu" | ||
LABELS = {"color": "red", "flavor": "cherry"} | ||
STORAGE_CLASS = "NEARLINE" | ||
DATA = { | ||
"name": BUCKET_NAME, | ||
"cors": CORS, | ||
"lifecycle": {"rule": LIFECYCLE_RULES}, | ||
"location": LOCATION, | ||
"storageClass": STORAGE_CLASS, | ||
"versioning": {"enabled": True}, | ||
"billing": {"requesterPays": True}, | ||
"labels": LABELS, | ||
} | ||
|
||
connection = _make_connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
|
||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
bucket.cors = CORS | ||
bucket.lifecycle_rules = LIFECYCLE_RULES | ||
bucket.storage_class = STORAGE_CLASS | ||
bucket.versioning_enabled = True | ||
bucket.requester_pays = True | ||
bucket.labels = LABELS | ||
bucket.create(location=LOCATION) | ||
|
||
connection.api_request.assert_called_once_with( | ||
method="POST", | ||
path="/b", | ||
query_params={"project": PROJECT}, | ||
data=DATA, | ||
_target_object=bucket, | ||
) | ||
|
||
def test_create_w_predefined_acl_invalid(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _Connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
|
||
with self.assertRaises(ValueError): | ||
bucket.create(predefined_acl="bogus") | ||
|
||
def test_create_w_predefined_acl_valid(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _Connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
bucket.create(predefined_acl="publicRead") | ||
|
||
kw, = connection._requested | ||
self.assertEqual(kw["method"], "POST") | ||
self.assertEqual(kw["path"], "/b") | ||
expected_qp = {"project": PROJECT, "predefinedAcl": "publicRead"} | ||
self.assertEqual(kw["query_params"], expected_qp) | ||
self.assertEqual(kw["data"], DATA) | ||
|
||
def test_create_w_predefined_default_object_acl_invalid(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _Connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
|
||
with self.assertRaises(ValueError): | ||
bucket.create(predefined_default_object_acl="bogus") | ||
|
||
def test_create_w_predefined_default_object_acl_valid(self): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _Connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
bucket.create(predefined_default_object_acl="publicRead") | ||
|
||
kw, = connection._requested | ||
self.assertEqual(kw["method"], "POST") | ||
self.assertEqual(kw["path"], "/b") | ||
expected_qp = {"project": PROJECT, "predefinedDefaultObjectAcl": "publicRead"} | ||
self.assertEqual(kw["query_params"], expected_qp) | ||
self.assertEqual(kw["data"], DATA) | ||
|
||
def test_acl_property(self): | ||
from google.cloud.storage.acl import BucketACL | ||
|
||
|
@@ -1964,6 +1753,35 @@ def test_versioning_enabled_setter(self): | |
bucket.versioning_enabled = True | ||
self.assertTrue(bucket.versioning_enabled) | ||
|
||
@mock.patch("warnings.warn") | ||
def test_create_deprecated(self, mock_warn): | ||
from google.cloud.storage.client import Client | ||
|
||
PROJECT = "PROJECT" | ||
BUCKET_NAME = "bucket-name" | ||
DATA = {"name": BUCKET_NAME} | ||
connection = _make_connection(DATA) | ||
client = Client(project=PROJECT) | ||
client._base_connection = connection | ||
|
||
bucket = self._make_one(client=client, name=BUCKET_NAME) | ||
bucket.create() | ||
|
||
connection.api_request.assert_called_once_with( | ||
method="POST", | ||
path="/b", | ||
query_params={"project": PROJECT}, | ||
data=DATA, | ||
_target_object=bucket, | ||
) | ||
|
||
mock_warn.assert_called_with( | ||
"Bucket.create() is deprecated and will be removed in future." | ||
"Use Client.create_bucket() instead.", | ||
PendingDeprecationWarning, | ||
stacklevel=1, | ||
) | ||
|
||
def test_requester_pays_getter_missing(self): | ||
NAME = "name" | ||
bucket = self._make_one(name=NAME) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Deleting old implementation and mirroring to
Client.create_bucket()