|
44 | 44 | import storage_define_bucket_website_configuration |
45 | 45 | import storage_delete_file |
46 | 46 | import storage_delete_file_archived_generation |
| 47 | +import storage_delete_object_contexts |
47 | 48 | import storage_disable_bucket_lifecycle_management |
48 | 49 | import storage_disable_soft_delete |
49 | 50 | import storage_disable_versioning |
|
62 | 63 | import storage_get_bucket_labels |
63 | 64 | import storage_get_bucket_metadata |
64 | 65 | import storage_get_metadata |
| 66 | +import storage_get_object_contexts |
65 | 67 | import storage_get_service_account |
66 | 68 | import storage_get_soft_delete_policy |
67 | 69 | import storage_get_soft_deleted_bucket |
68 | 70 | import storage_list_buckets |
69 | 71 | import storage_list_file_archived_generations |
70 | 72 | import storage_list_files |
71 | 73 | import storage_list_files_with_prefix |
| 74 | +import storage_list_object_contexts |
72 | 75 | import storage_list_soft_deleted_buckets |
73 | 76 | import storage_list_soft_deleted_object_versions |
74 | 77 | import storage_list_soft_deleted_objects |
|
85 | 88 | import storage_set_bucket_default_kms_key |
86 | 89 | import storage_set_client_endpoint |
87 | 90 | import storage_set_metadata |
| 91 | +import storage_set_object_contexts |
88 | 92 | import storage_set_object_retention_policy |
89 | 93 | import storage_set_soft_delete_policy |
90 | 94 | import storage_trace_quickstart |
@@ -248,6 +252,58 @@ def test_list_blobs(test_blob, capsys): |
248 | 252 | assert test_blob.name in out |
249 | 253 |
|
250 | 254 |
|
| 255 | +def test_set_object_contexts(test_blob, capsys): |
| 256 | + storage_set_object_contexts.set_object_contexts( |
| 257 | + test_blob.bucket.name, test_blob.name |
| 258 | + ) |
| 259 | + out, _ = capsys.readouterr() |
| 260 | + assert "key1 = newValue1" in out |
| 261 | + assert "key3 = value3" in out |
| 262 | + test_blob.reload() |
| 263 | + assert "key2" not in test_blob.contexts.custom |
| 264 | + |
| 265 | + |
| 266 | +def test_get_object_contexts(test_blob, capsys): |
| 267 | + storage_get_object_contexts.get_object_contexts( |
| 268 | + test_blob.bucket.name, test_blob.name |
| 269 | + ) |
| 270 | + out, _ = capsys.readouterr() |
| 271 | + assert f"No contexts found for {test_blob.name}" in out |
| 272 | + |
| 273 | + storage_set_object_contexts.set_object_contexts( |
| 274 | + test_blob.bucket.name, test_blob.name |
| 275 | + ) |
| 276 | + storage_get_object_contexts.get_object_contexts( |
| 277 | + test_blob.bucket.name, test_blob.name |
| 278 | + ) |
| 279 | + out, _ = capsys.readouterr() |
| 280 | + assert "key1 = newValue1" in out |
| 281 | + |
| 282 | + |
| 283 | +def test_list_object_contexts(test_blob, capsys): |
| 284 | + storage_set_object_contexts.set_object_contexts( |
| 285 | + test_blob.bucket.name, test_blob.name |
| 286 | + ) |
| 287 | + storage_list_object_contexts.list_object_contexts( |
| 288 | + test_blob.bucket.name, 'contexts."key1"="newValue1"' |
| 289 | + ) |
| 290 | + out, _ = capsys.readouterr() |
| 291 | + assert test_blob.name in out |
| 292 | + |
| 293 | + |
| 294 | +def test_delete_object_contexts(test_blob, capsys): |
| 295 | + storage_set_object_contexts.set_object_contexts( |
| 296 | + test_blob.bucket.name, test_blob.name |
| 297 | + ) |
| 298 | + storage_delete_object_contexts.delete_object_contexts( |
| 299 | + test_blob.bucket.name, test_blob.name |
| 300 | + ) |
| 301 | + out, _ = capsys.readouterr() |
| 302 | + assert f"Deleted all contexts for {test_blob.name}" in out |
| 303 | + test_blob.reload() |
| 304 | + assert not (test_blob.contexts and test_blob.contexts.custom) |
| 305 | + |
| 306 | + |
251 | 307 | def test_bucket_metadata(test_bucket, capsys): |
252 | 308 | storage_get_bucket_metadata.bucket_metadata(test_bucket.name) |
253 | 309 | out, _ = capsys.readouterr() |
|
0 commit comments