|
| 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", "generation", "soft_delete_time", "hard_delete_time", |
| 34 | + "autoclass_terminal_storage_class_update_time", "object_retention_mode", |
| 35 | + "user_project", "autoclass_toggle_time", "time_created", "updated", |
| 36 | + "acl", "default_object_acl", "etag", "id", "iam_configuration", |
| 37 | + "soft_delete_policy", "data_locations", "location_type", "path", |
| 38 | + "metageneration", "owner", "project_number", "retention_policy_effective_time", |
| 39 | + "retention_policy_locked", "self_link", |
| 40 | +] |
| 41 | + |
| 42 | + |
| 43 | +@pytest.mark.parametrize("prop", READ_WRITE_PROPS + READ_ONLY_PROPS) |
| 44 | +def test_property_getters(base_bucket, prop): |
| 45 | + with pytest.raises(NotImplementedError): |
| 46 | + getattr(base_bucket, prop) |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.parametrize("prop", READ_WRITE_PROPS) |
| 50 | +def test_property_setters(base_bucket, prop): |
| 51 | + with pytest.raises(NotImplementedError): |
| 52 | + setattr(base_bucket, prop, "dummy_value") |
| 53 | + |
| 54 | + |
| 55 | +def test_reload(base_bucket): |
| 56 | + with pytest.raises(NotImplementedError): |
| 57 | + base_bucket.reload() |
| 58 | + |
| 59 | + |
| 60 | +def test_patch(base_bucket): |
| 61 | + with pytest.raises(NotImplementedError): |
| 62 | + base_bucket.patch() |
| 63 | + |
| 64 | + |
| 65 | +def test_blob(base_bucket): |
| 66 | + with pytest.raises(NotImplementedError): |
| 67 | + base_bucket.blob("dummy_blob_name") |
| 68 | + |
| 69 | + |
| 70 | +def test_get_blob(base_bucket): |
| 71 | + with pytest.raises(NotImplementedError): |
| 72 | + base_bucket.get_blob("dummy_blob_name") |
0 commit comments