Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/google-cloud-storage/google/cloud/storage/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
See: https://cloud.google.com/storage/docs/storage-classes
"""

STANDARD_ENTERPRISE_STORAGE_CLASS = "STANDARD_ENTERPRISE"
"""Enterprise storage class for standard storage.

See: https://cloud.google.com/storage/docs/storage-classes
"""

STANDARD_FLEXBACKUP_ENTERPRISE_STORAGE_CLASS = "STANDARD_FLEXBACKUP_ENTERPRISE"
"""Enterprise storage class for standard flexbackup storage.

See: https://cloud.google.com/storage/docs/storage-classes
"""

NEARLINE_STORAGE_CLASS = "NEARLINE"
"""Storage class for objects accessed at most once per month.

Expand All @@ -45,6 +57,12 @@
See: https://cloud.google.com/storage/docs/storage-classes
"""

LR_STANDARD_ENTERPRISE_STORAGE_CLASS = "LR_STANDARD_ENTERPRISE"
"""Enterprise storage class for locally redundant standard storage.

See: https://cloud.google.com/storage/docs/storage-classes
"""

MULTI_REGIONAL_LEGACY_STORAGE_CLASS = "MULTI_REGIONAL"
"""Legacy storage class.

Expand Down
27 changes: 27 additions & 0 deletions packages/google-cloud-storage/tests/system/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,33 @@ def test_blob_update_storage_class_large_file(
assert blob.storage_class == constants.COLDLINE_STORAGE_CLASS


def test_blob_update_storage_class_enterprise(
storage_client, buckets_to_delete, blobs_to_delete, file_data
):
from google.cloud.storage import constants

bucket_name = _helpers.unique_name("blob-ent-sc")
bucket = storage_client.bucket(bucket_name)
bucket.storage_class = constants.STANDARD_ENTERPRISE_STORAGE_CLASS

_helpers.retry_429_503(bucket.create)(location="us-central1")
buckets_to_delete.append(bucket)

blob = bucket.blob("EnterpriseSmallFile")
info = file_data["simple"]
blob.upload_from_filename(info["path"])
blobs_to_delete.append(blob)
assert blob.storage_class == constants.STANDARD_ENTERPRISE_STORAGE_CLASS

blob.update_storage_class(constants.LR_STANDARD_ENTERPRISE_STORAGE_CLASS)
blob.reload()
assert blob.storage_class == constants.LR_STANDARD_ENTERPRISE_STORAGE_CLASS

blob.update_storage_class(constants.STANDARD_ENTERPRISE_STORAGE_CLASS)
blob.reload()
assert blob.storage_class == constants.STANDARD_ENTERPRISE_STORAGE_CLASS


def test_object_retention_lock(storage_client, buckets_to_delete, blobs_to_delete):
from google.cloud.storage._helpers import _NOW, _UTC

Expand Down
35 changes: 35 additions & 0 deletions packages/google-cloud-storage/tests/system/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,41 @@ def test_bucket_create_w_alt_storage_class(storage_client, buckets_to_delete):
assert created.storage_class == constants.ARCHIVE_STORAGE_CLASS


@pytest.mark.parametrize(
"storage_class,suffix,location",
[
("STANDARD_ENTERPRISE", "std-ent", "us-central1"),
("LR_STANDARD_ENTERPRISE", "lr-std-ent", "us-central1"),
("STANDARD_FLEXBACKUP_ENTERPRISE", "fb-ent", "us"),
],
)
def test_bucket_create_w_enterprise_storage_class(
storage_client, buckets_to_delete, storage_class, suffix, location
):
from google.cloud.storage import constants

enterprise_constants = (
constants.STANDARD_ENTERPRISE_STORAGE_CLASS,
constants.LR_STANDARD_ENTERPRISE_STORAGE_CLASS,
constants.STANDARD_FLEXBACKUP_ENTERPRISE_STORAGE_CLASS,
)
assert storage_class in enterprise_constants

bucket_name = _helpers.unique_name(f"bucket-w-{suffix}")

with pytest.raises(exceptions.NotFound):
storage_client.get_bucket(bucket_name)

bucket = storage_client.bucket(bucket_name)
bucket.storage_class = storage_class

_helpers.retry_429_503(bucket.create)(location=location)
buckets_to_delete.append(bucket)

created = storage_client.get_bucket(bucket_name)
assert created.storage_class == storage_class


def test_bucket_lifecycle_rules(storage_client, buckets_to_delete):
from google.cloud.storage import constants
from google.cloud.storage.bucket import (
Expand Down
24 changes: 24 additions & 0 deletions packages/google-cloud-storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -6788,6 +6788,30 @@ def test_w_existing_qs(self):
self.assertEqual(self._call_fut(BASE_URL, NV_LIST), f"{BASE_URL}&{expected}")


@pytest.mark.parametrize(
"constant_name,expected_value",
[
("STANDARD_ENTERPRISE_STORAGE_CLASS", "STANDARD_ENTERPRISE"),
(
"STANDARD_FLEXBACKUP_ENTERPRISE_STORAGE_CLASS",
"STANDARD_FLEXBACKUP_ENTERPRISE",
),
("LR_STANDARD_ENTERPRISE_STORAGE_CLASS", "LR_STANDARD_ENTERPRISE"),
],
)
def test_blob_storage_class_enterprise_constants(constant_name, expected_value):
from google.cloud.storage import constants
from google.cloud.storage.blob import Blob

storage_class = getattr(constants, constant_name)
assert storage_class == expected_value
bucket = _Bucket()
blob = Blob("blob-name", bucket=bucket)
blob.storage_class = storage_class
assert blob.storage_class == storage_class
assert blob._properties == {"storageClass": storage_class}


class _Connection(object):
API_BASE_URL = "http://example.com"
USER_AGENT = "testing 1.2.3"
Expand Down
31 changes: 31 additions & 0 deletions packages/google-cloud-storage/tests/unit/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3279,6 +3279,37 @@ def test_storage_class_setter_STANDARD(self):
self.assertEqual(bucket.storage_class, STANDARD_STORAGE_CLASS)
self.assertTrue("storageClass" in bucket._changes)

def test_storage_class_setter_STANDARD_ENTERPRISE(self):
from google.cloud.storage.constants import STANDARD_ENTERPRISE_STORAGE_CLASS

NAME = "name"
bucket = self._make_one(name=NAME)
bucket.storage_class = STANDARD_ENTERPRISE_STORAGE_CLASS
self.assertEqual(bucket.storage_class, STANDARD_ENTERPRISE_STORAGE_CLASS)
self.assertTrue("storageClass" in bucket._changes)

def test_storage_class_setter_STANDARD_FLEXBACKUP_ENTERPRISE(self):
from google.cloud.storage.constants import (
STANDARD_FLEXBACKUP_ENTERPRISE_STORAGE_CLASS,
)

NAME = "name"
bucket = self._make_one(name=NAME)
bucket.storage_class = STANDARD_FLEXBACKUP_ENTERPRISE_STORAGE_CLASS
self.assertEqual(
bucket.storage_class, STANDARD_FLEXBACKUP_ENTERPRISE_STORAGE_CLASS
)
self.assertTrue("storageClass" in bucket._changes)

def test_storage_class_setter_LR_STANDARD_ENTERPRISE(self):
from google.cloud.storage.constants import LR_STANDARD_ENTERPRISE_STORAGE_CLASS

NAME = "name"
bucket = self._make_one(name=NAME)
bucket.storage_class = LR_STANDARD_ENTERPRISE_STORAGE_CLASS
self.assertEqual(bucket.storage_class, LR_STANDARD_ENTERPRISE_STORAGE_CLASS)
self.assertTrue("storageClass" in bucket._changes)

def test_storage_class_setter_NEARLINE(self):
from google.cloud.storage.constants import NEARLINE_STORAGE_CLASS

Expand Down
Loading