|
49 | 49 | SelectRequest)
|
50 | 50 | from minio.sse import SseCustomerKey
|
51 | 51 | from minio.time import to_http_header
|
52 |
| -from minio.versioningconfig import VersioningConfig |
| 52 | +from minio.versioningconfig import SUSPENDED, VersioningConfig |
53 | 53 |
|
54 | 54 | _CLIENT = None # initialized in main().
|
55 | 55 | _TEST_FILE = None # initialized in main().
|
@@ -1935,6 +1935,61 @@ def test_upload_snowball_objects_with_staging( # pylint: disable=invalid-name
|
1935 | 1935 | _test_upload_snowball_objects(log_entry, staging_filename)
|
1936 | 1936 |
|
1937 | 1937 |
|
| 1938 | +def test_set_get_bucket_versioning(log_entry): |
| 1939 | + """Test set/get bucket_versining""" |
| 1940 | + |
| 1941 | + # Get a unique bucket_name and object_name |
| 1942 | + bucket_name = _gen_bucket_name() |
| 1943 | + |
| 1944 | + log_entry["args"] = { |
| 1945 | + "bucket_name": bucket_name, |
| 1946 | + } |
| 1947 | + |
| 1948 | + excl_prefixes = ['prefix1', 'prefix2'] |
| 1949 | + |
| 1950 | + _CLIENT.make_bucket(bucket_name) |
| 1951 | + |
| 1952 | + try: |
| 1953 | + # Test all fields of versioning configuration |
| 1954 | + _CLIENT.set_bucket_versioning( |
| 1955 | + bucket_name, |
| 1956 | + VersioningConfig(status=ENABLED, |
| 1957 | + exclude_folders=True, |
| 1958 | + excluded_prefixes=excl_prefixes), |
| 1959 | + ) |
| 1960 | + |
| 1961 | + vcfg = _CLIENT.get_bucket_versioning(bucket_name) |
| 1962 | + if vcfg.status != ENABLED: |
| 1963 | + raise ValueError(f'(1) unexpected get_bucket_versioning result: ' |
| 1964 | + f'status: {vcfg.status}') |
| 1965 | + if not vcfg.exclude_folders: |
| 1966 | + raise ValueError(f'(1) unexpected get_bucket_versioning result: ' |
| 1967 | + f'exclude_folders: {vcfg.exclude_folders}') |
| 1968 | + if set(vcfg.excluded_prefixes) != set(excl_prefixes): |
| 1969 | + raise ValueError(f'(1) unexpected get_bucket_versioning result: ' |
| 1970 | + f'excluded_prefixes: {vcfg.excluded_prefixes}') |
| 1971 | + |
| 1972 | + # Disable all fields of versioning configuration |
| 1973 | + _CLIENT.set_bucket_versioning( |
| 1974 | + bucket_name, |
| 1975 | + VersioningConfig(status=SUSPENDED), |
| 1976 | + ) |
| 1977 | + |
| 1978 | + vcfg = _CLIENT.get_bucket_versioning(bucket_name) |
| 1979 | + if vcfg.status != SUSPENDED: |
| 1980 | + raise ValueError(f'(2) unexpected get_bucket_versioning result: ' |
| 1981 | + f'status: {vcfg.status}') |
| 1982 | + if vcfg.exclude_folders: |
| 1983 | + raise ValueError(f'(2) unexpected get_bucket_versioning result: ' |
| 1984 | + f'exclude_folders: {vcfg.exclude_folders}') |
| 1985 | + if len(vcfg.excluded_prefixes) != 0: |
| 1986 | + raise ValueError(f'(2) unexpected get_bucket_versioning result: ' |
| 1987 | + f'excluded_prefixes: {vcfg.excluded_prefixes}') |
| 1988 | + |
| 1989 | + finally: |
| 1990 | + _CLIENT.remove_bucket(bucket_name) |
| 1991 | + |
| 1992 | + |
1938 | 1993 | def main():
|
1939 | 1994 | """
|
1940 | 1995 | Functional testing of minio python library.
|
@@ -2026,6 +2081,7 @@ def main():
|
2026 | 2081 | test_presigned_put_object_expiry: None,
|
2027 | 2082 | test_presigned_post_policy: None,
|
2028 | 2083 | test_thread_safe: None,
|
| 2084 | + test_set_get_bucket_versioning: None, |
2029 | 2085 | test_get_bucket_policy: None,
|
2030 | 2086 | test_set_bucket_policy_readonly: None,
|
2031 | 2087 | test_set_bucket_policy_readwrite: None,
|
|
0 commit comments