Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(storage): deprecate Bucket.create() and requester_pays#9893
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
6873209fe3642dcab1017e44fad4e26c745d28d1ec8f401f953e542eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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): | ||
| ||
| 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) | ||
Uh oh!
There was an error while loading. Please reload this page.
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()