Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 821e77a

Browse files
committed
Add tests for abstracts
1 parent a784001 commit 821e77a

3 files changed

Lines changed: 159 additions & 0 deletions

File tree

tests/unit/abstracts/__init__.py

Whitespace-only changes.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
from unittest import mock
3+
4+
from google.cloud.storage.abstracts.base_blob import BaseBlob
5+
6+
7+
@pytest.fixture
8+
def base_blob():
9+
# Temporarily remove abstract methods restriction to allow direct instantiation
10+
with mock.patch.object(BaseBlob, "__abstractmethods__", set()):
11+
yield BaseBlob()
12+
13+
14+
# Properties that have both getters and setters
15+
READ_WRITE_PROPS = [
16+
"encryption_key",
17+
"chunk_size",
18+
"metadata",
19+
"kms_key_name",
20+
"custom_time",
21+
]
22+
23+
# Properties that only have getters
24+
READ_ONLY_PROPS = [
25+
"bucket",
26+
"acl",
27+
"path",
28+
"client",
29+
"user_project",
30+
"public_url",
31+
"component_count",
32+
"etag",
33+
"generation",
34+
"id",
35+
"media_link",
36+
"metageneration",
37+
"owner",
38+
"retention_expiration_time",
39+
"self_link",
40+
"size",
41+
"time_deleted",
42+
"time_created",
43+
"updated",
44+
"retention",
45+
"soft_delete_time",
46+
"hard_delete_time",
47+
]
48+
49+
50+
@pytest.mark.parametrize("prop", READ_WRITE_PROPS + READ_ONLY_PROPS)
51+
def test_property_getters(base_blob, prop):
52+
with pytest.raises(NotImplementedError, match="Not Yet Implemented"):
53+
getattr(base_blob, prop)
54+
55+
56+
@pytest.mark.parametrize("prop", READ_WRITE_PROPS)
57+
def test_property_setters(base_blob, prop):
58+
with pytest.raises(NotImplementedError, match="Not Yet Implemented"):
59+
setattr(base_blob, prop, "dummy_value")
60+
61+
62+
def test_reload(base_blob):
63+
with pytest.raises(NotImplementedError, match="Not Yet Implemented"):
64+
base_blob.reload()
65+
66+
67+
def test_open(base_blob):
68+
with pytest.raises(NotImplementedError, match="Not Yet Implemented"):
69+
base_blob.open()
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import pytest
2+
from unittest import mock
3+
4+
from google.cloud.storage.abstracts.base_bucket import BaseBucket
5+
6+
7+
@pytest.fixture
8+
def base_bucket():
9+
# Temporarily remove abstract methods restriction to allow direct instantiation
10+
with mock.patch.object(BaseBucket, "__abstractmethods__", set()):
11+
yield BaseBucket()
12+
13+
14+
# Properties that have both getters and setters
15+
READ_WRITE_PROPS = [
16+
"retention_period",
17+
"storage_class",
18+
"versioning_enabled",
19+
"requester_pays",
20+
"autoclass_enabled",
21+
"autoclass_terminal_storage_class",
22+
"hierarchical_namespace_enabled",
23+
"cors",
24+
"default_kms_key_name",
25+
"labels",
26+
"ip_filter",
27+
"lifecycle_rules",
28+
"location",
29+
]
30+
31+
# Properties that only have getters
32+
READ_ONLY_PROPS = [
33+
"rpo",
34+
"generation",
35+
"soft_delete_time",
36+
"hard_delete_time",
37+
"autoclass_terminal_storage_class_update_time",
38+
"object_retention_mode",
39+
"user_project",
40+
"autoclass_toggle_time",
41+
"time_created",
42+
"updated",
43+
"acl",
44+
"default_object_acl",
45+
"etag",
46+
"id",
47+
"iam_configuration",
48+
"soft_delete_policy",
49+
"data_locations",
50+
"location_type",
51+
"path",
52+
"metageneration",
53+
"owner",
54+
"project_number",
55+
"retention_policy_effective_time",
56+
"retention_policy_locked",
57+
"self_link",
58+
]
59+
60+
61+
@pytest.mark.parametrize("prop", READ_WRITE_PROPS + READ_ONLY_PROPS)
62+
def test_property_getters(base_bucket, prop):
63+
with pytest.raises(NotImplementedError):
64+
getattr(base_bucket, prop)
65+
66+
67+
@pytest.mark.parametrize("prop", READ_WRITE_PROPS)
68+
def test_property_setters(base_bucket, prop):
69+
with pytest.raises(NotImplementedError):
70+
setattr(base_bucket, prop, "dummy_value")
71+
72+
73+
def test_reload(base_bucket):
74+
with pytest.raises(NotImplementedError):
75+
base_bucket.reload()
76+
77+
78+
def test_patch(base_bucket):
79+
with pytest.raises(NotImplementedError):
80+
base_bucket.patch()
81+
82+
83+
def test_blob(base_bucket):
84+
with pytest.raises(NotImplementedError):
85+
base_bucket.blob("dummy_blob_name")
86+
87+
88+
def test_get_blob(base_bucket):
89+
with pytest.raises(NotImplementedError):
90+
base_bucket.get_blob("dummy_blob_name")

0 commit comments

Comments
 (0)